mirror of
https://github.com/BotChain-Robots/firmware.git
synced 2026-07-08 17:47:21 +02:00
Servo control
This commit is contained in:
21
main/include/LoopManager.h
Normal file
21
main/include/LoopManager.h
Normal file
@@ -0,0 +1,21 @@
|
||||
//
|
||||
// Created by Johnathon Slightham on 2025-07-05.
|
||||
//
|
||||
|
||||
#ifndef LOOPMANAGER_H
|
||||
#define LOOPMANAGER_H
|
||||
|
||||
#include "control/IActuator.h"
|
||||
#include "control/ActuatorFactory.h"
|
||||
|
||||
class LoopManager {
|
||||
public:
|
||||
[[noreturn]] static void control_loop();
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif //LOOPMANAGER_H
|
||||
18
main/include/control/ActuatorFactory.h
Normal file
18
main/include/control/ActuatorFactory.h
Normal file
@@ -0,0 +1,18 @@
|
||||
//
|
||||
// Created by Johnathon Slightham on 2025-07-15.
|
||||
//
|
||||
|
||||
#ifndef ACTUATORFACTORY_H
|
||||
#define ACTUATORFACTORY_H
|
||||
|
||||
#include "IActuator.h"
|
||||
#include "flatbuffers_generated/RobotModule_generated.h"
|
||||
|
||||
class ActuatorFactory {
|
||||
public:
|
||||
static std::unique_ptr<IActuator> create_actuator(ModuleType type);
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif //ACTUATORFACTORY_H
|
||||
15
main/include/control/IActuator.h
Normal file
15
main/include/control/IActuator.h
Normal file
@@ -0,0 +1,15 @@
|
||||
//
|
||||
// Created by Johnathon Slightham on 2025-07-15.
|
||||
//
|
||||
|
||||
#ifndef IACTUATOR_H
|
||||
#define IACTUATOR_H
|
||||
#include <cstdint>
|
||||
|
||||
class IActuator {
|
||||
public:
|
||||
virtual ~IActuator() {}
|
||||
virtual void actuate(uint8_t *cmd) = 0;
|
||||
};
|
||||
|
||||
#endif //IACTUATOR_H
|
||||
18
main/include/control/Servo1Actuator.h
Normal file
18
main/include/control/Servo1Actuator.h
Normal file
@@ -0,0 +1,18 @@
|
||||
//
|
||||
// Created by Johnathon Slightham on 2025-07-15.
|
||||
//
|
||||
|
||||
// 180 deg servo
|
||||
|
||||
#ifndef SERVO1ACTUATOR_H
|
||||
#define SERVO1ACTUATOR_H
|
||||
|
||||
#include "IActuator.h"
|
||||
|
||||
class Servo1Actuator final : public IActuator {
|
||||
public:
|
||||
Servo1Actuator();
|
||||
void actuate(uint8_t *cmd) override;
|
||||
};
|
||||
|
||||
#endif //SERVO1ACTUATOR_H
|
||||
24
main/include/util/number_utils.h
Normal file
24
main/include/util/number_utils.h
Normal file
@@ -0,0 +1,24 @@
|
||||
//
|
||||
// Created by Johnathon Slightham on 2025-07-15.
|
||||
//
|
||||
|
||||
#ifndef INT_UTILS_H
|
||||
#define INT_UTILS_H
|
||||
|
||||
#include <iostream>
|
||||
#include <type_traits>
|
||||
|
||||
namespace util {
|
||||
template<typename T>
|
||||
T mapRange(T value, T inMin, T inMax, T outMin, T outMax) {
|
||||
static_assert(std::is_arithmetic<T>::value, "Template parameter must be a numeric type");
|
||||
|
||||
if (inMin == inMax) {
|
||||
return value;
|
||||
}
|
||||
|
||||
return (value - inMin) * (outMax - outMin) / (inMax - inMin) + outMin;
|
||||
}
|
||||
}
|
||||
|
||||
#endif //INT_UTILS_H
|
||||
Reference in New Issue
Block a user