Skip to content
Snippets Groups Projects
Commit c18571bf authored by Alberto Nidasio's avatar Alberto Nidasio
Browse files

[Servo] Implemented reset position

parent 3df306e8
No related branches found
No related tags found
No related merge requests found
......@@ -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);
}
......
......@@ -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;
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment