diff --git a/src/shared/actuators/Servo/Servo.cpp b/src/shared/actuators/Servo/Servo.cpp index 0c4460cd2aa5ee009750a42ded9052488abce8bd..b4d9b8e647261844027f406fcf268e04bae68611 100644 --- a/src/shared/actuators/Servo/Servo.cpp +++ b/src/shared/actuators/Servo/Servo.cpp @@ -31,22 +31,32 @@ namespace Boardcore Servo::Servo(TIM_TypeDef* const timer, TimerUtils::Channel pwmChannel, unsigned int minPulse, unsigned int maxPulse, - unsigned int frequency) + unsigned int frequency, unsigned int resetPulse) : pwm(timer, frequency), pwmChannel(pwmChannel), minPulse(minPulse), - maxPulse(maxPulse), frequency(frequency) + maxPulse(maxPulse), resetPulse(resetPulse), frequency(frequency) +{ + setPosition(resetPulse); +} + +Servo::Servo(TIM_TypeDef* const timer, TimerUtils::Channel pwmChannel, + unsigned int minPulse, unsigned int maxPulse, + unsigned int frequency) + : Servo(timer, pwmChannel, minPulse, maxPulse, frequency, minPulse) { - setPosition(0); } void Servo::enable() { pwm.enableChannel(pwmChannel); } void Servo::disable() { pwm.disableChannel(pwmChannel); } +void Servo::reset() { setPosition(resetPulse); } + #else Servo::Servo(unsigned int minPulse, unsigned int maxPulse, unsigned int frequency) - : minPulse(minPulse), maxPulse(maxPulse), frequency(frequency) + : minPulse(minPulse), maxPulse(maxPulse), frequency(frequency), + resetPulse(minPulse) { setPosition(0); } diff --git a/src/shared/actuators/Servo/Servo.h b/src/shared/actuators/Servo/Servo.h index b76baba37e0cae8f9479da48886272cb637a7710..43c1ca54a708a0171dab661297ce97a1944dc6a1 100644 --- a/src/shared/actuators/Servo/Servo.h +++ b/src/shared/actuators/Servo/Servo.h @@ -76,6 +76,21 @@ public: explicit Servo(TIM_TypeDef* const timer, TimerUtils::Channel pwmChannel, unsigned int minPulse = 1000, unsigned int maxPulse = 2000, unsigned int frequency = 50); + /** + * @brief Prepare the timer and sets the PWM output to the minimum. + * + * @see Servo::Servo + * + * @param timer Timer peripheral used for the PWM signal. + * @param pwmChannel Timer's channel used for the PWM signal. + * @param frequency Frequency of the PWM driving the H-bridge. + * @param minPulse Minimum signal pulse in microseconds. + * @param maxPulse Maximum signal pulse in microseconds. + * @param resetPulse Reset signal pulse in microseconds. + */ + explicit Servo(TIM_TypeDef* const timer, TimerUtils::Channel pwmChannel, + unsigned int minPulse, unsigned int maxPulse, + unsigned int frequency, unsigned int resetPulse); #else explicit Servo(unsigned int minPulse = 1000, unsigned int maxPulse = 2000, unsigned int frequency = 50); @@ -91,6 +106,11 @@ public: */ void disable(); + /** + * @brief Moves the servo to the reset position. + */ + void reset(); + /** * @brief Set the position of the servomotor. * @@ -136,6 +156,7 @@ private: float minPulse; float maxPulse; + float resetPulse; float frequency; };