32#ifndef COMPILE_FOR_HOST
35 unsigned int minPulse,
unsigned int maxPulse,
36 unsigned int frequency)
37 : pwm(timer, frequency), pwmChannel(pwmChannel), minPulse(minPulse),
38 maxPulse(maxPulse), frequency(frequency)
49Servo::Servo(
unsigned int minPulse,
unsigned int maxPulse,
50 unsigned int frequency)
51 : minPulse(minPulse), maxPulse(maxPulse), frequency(frequency)
68 else if (position > 1)
72 float pulse = minPulse + (maxPulse - minPulse) * position;
74 float dutyCycle = pulse * frequency / 1000000.0f;
76#ifndef COMPILE_FOR_HOST
79 this->dutyCycle = dutyCycle;
93#ifndef COMPILE_FOR_HOST
96 float dutyCycle = this->dutyCycle;
99 float pulse = dutyCycle * 1000000.0f / frequency;
101 return (pulse - minPulse) / (maxPulse - minPulse);
114#ifndef COMPILE_FOR_HOST
void disableChannel(TimerUtils::Channel channel)
void setDutyCycle(TimerUtils::Channel channel, float dutyCycle)
Sets the duty cycle for the specified channel.
float getDutyCycle(TimerUtils::Channel channel)
Return the channel's duty cycle in the range [0,1].
void enableChannel(TimerUtils::Channel channel, Polarity polarity=Polarity::NORMAL)
GP16bitTimer & getTimer()
Returns the timer used to generate the pwm signal.
ServoData getState()
Returns the current position and the current timestamp.
void setPosition360Deg(float degrees)
void setPosition90Deg(float degrees)
void enable()
Starts producing the PWM signal.
void setPosition180Deg(float degrees)
float getPosition180Deg()
void disable()
Stops producing the PWM signal.
Servo(TIM_TypeDef *const timer, TimerUtils::Channel pwmChannel, unsigned int minPulse=1000, unsigned int maxPulse=2000, unsigned int frequency=50)
Prepare the timer and sets the PWM output to the minimum.
void setPosition(float position, bool limited=true)
Set the position of the servomotor.
float getPosition()
Returns the current position of the servomotor.
void setPosition120Deg(float degrees)
float getPosition360Deg()
uint64_t getTimestamp()
Returns the current timer value in microseconds.
This file includes all the types the logdecoder script will decode.