Skyward boardcore
Loading...
Searching...
No Matches
Boardcore::Servo Class Reference

Driver to operate a PWM controlled servo motor. More...

#include <Servo.h>

Public Member Functions

 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 enable ()
 Starts producing the PWM signal.
 
void disable ()
 Stops producing the PWM signal.
 
void setPosition (float position, bool limited=true)
 Set the position of the servomotor.
 
void setPosition90Deg (float degrees)
 
void setPosition120Deg (float degrees)
 
void setPosition180Deg (float degrees)
 
void setPosition360Deg (float degrees)
 
float getPosition ()
 Returns the current position of the servomotor.
 
float getPosition90Deg ()
 
float getPosition180Deg ()
 
float getPosition360Deg ()
 
ServoData getState ()
 Returns the current position and the current timestamp.
 

Detailed Description

Driver to operate a PWM controlled servo motor.

Servo motors often are controlled via a PWM signal. A PWM signal is a simple rectangular wave with a set frequency and duty cycle. Usually servo motor listen for a pulse with a specific duration between two limits you can set to this driver. The position is then proportional to the size of the pulse relative to the range. A PWM signal is then used to periodically tell the servo the position where it should be.

Also Servo motors comes in a variety of motion range configurations. This driver is prepared for non continuous rotation servo motor, which usually have a range of 90, 180 or 360 degrees. The driver accepts the position relative to the range (a percentage basically) but provides tree function to convert to and from degrees.

The PWM signal is disabled automatically when the Servo object is destructed and the output of the signal pin will be low.

Note that the peripheral clock of the undelying timer used to generate the PWM signal, is enabled when the object is created and disabled when destructed. When using the same timer for two or more sensors keep in mind that you could encounter issues.

Definition at line 58 of file Servo.h.

Constructor & Destructor Documentation

◆ Servo()

Boardcore::Servo::Servo ( TIM_TypeDef *const timer,
TimerUtils::Channel pwmChannel,
unsigned int minPulse = 1000,
unsigned int maxPulse = 2000,
unsigned int frequency = 50 )
explicit

Prepare the timer and sets the PWM output to the minimum.

More specifically, the PWM output is prepared to be equal to minPulse but it is not enabled! After creating the object the PWM signal is not active. This is to ensure the servo motor doesn't move unexpectedly.

Note that the timer peripheral's clock is enabled automatically when the PWM object is created.

Parameters
timerTimer peripheral used for the PWM signal.
pwmChannelTimer's channel used for the PWM signal.
frequencyFrequency of the PWM driving the H-bridge.
minPulseMinimum signal pulse in microseconds.
maxPulseMaximum signal pulse in microseconds.

Definition at line 34 of file Servo.cpp.

Member Function Documentation

◆ disable()

void Boardcore::Servo::disable ( )

Stops producing the PWM signal.

Definition at line 45 of file Servo.cpp.

◆ enable()

void Boardcore::Servo::enable ( )

Starts producing the PWM signal.

Definition at line 43 of file Servo.cpp.

◆ getPosition()

float Boardcore::Servo::getPosition ( )

Returns the current position of the servomotor.

Note that this position isn't necessarily the real servo position because no feedback exists. It is merely the value of the signal generated.

Returns
Position in range [0, 1].

Definition at line 91 of file Servo.cpp.

◆ getPosition180Deg()

float Boardcore::Servo::getPosition180Deg ( )

Definition at line 106 of file Servo.cpp.

◆ getPosition360Deg()

float Boardcore::Servo::getPosition360Deg ( )

Definition at line 108 of file Servo.cpp.

◆ getPosition90Deg()

float Boardcore::Servo::getPosition90Deg ( )

Definition at line 104 of file Servo.cpp.

◆ getState()

ServoData Boardcore::Servo::getState ( )

Returns the current position and the current timestamp.

Definition at line 110 of file Servo.cpp.

◆ setPosition()

void Boardcore::Servo::setPosition ( float position,
bool limited = true )

Set the position of the servomotor.

Parameters
positionPosition in range [0, 1].

Definition at line 62 of file Servo.cpp.

◆ setPosition120Deg()

void Boardcore::Servo::setPosition120Deg ( float degrees)

Definition at line 85 of file Servo.cpp.

◆ setPosition180Deg()

void Boardcore::Servo::setPosition180Deg ( float degrees)

Definition at line 87 of file Servo.cpp.

◆ setPosition360Deg()

void Boardcore::Servo::setPosition360Deg ( float degrees)

Definition at line 89 of file Servo.cpp.

◆ setPosition90Deg()

void Boardcore::Servo::setPosition90Deg ( float degrees)

Definition at line 83 of file Servo.cpp.


The documentation for this class was generated from the following files: