High-level wrapper for Arduino Servo control (RC servo motors).
More...
#include <ServoMotor.h>
|
|
::Servo | servo |
| |
|
int | pin = -1 |
| |
|
int | minAngle = -90 |
| |
|
int | maxAngle = 90 |
| |
|
bool | is_pin_asssigned = false |
| |
|
T | lastValuePercent = 0.0f |
| |
|
uint8_t | id = 0 |
| |
template<typename T = float>
class tinyrobotics::ServoMotor< T >
High-level wrapper for Arduino Servo control (RC servo motors).
This class provides an easy interface for controlling standard RC servo motors using the Arduino Servo library. It allows you to:
- Attach/detach a servo to a digital pin
- Set the servo angle in degrees (using ROS right-handed convention: 0 is forward, +left, -right)
- Set the servo position by pulse width (microseconds)
- Read back the last set angle (in degrees)
- Constrain the allowed angle range for safety or mechanical limits
Usage Example:
servo.attach(9);
servo.detach();
High-level wrapper for Arduino Servo control (RC servo motors).
Definition: ServoMotor.h:40
int8_t getAngle()
Definition: ServoMotor.h:63
void setConstraints(int minAngle, int maxAngle)
Definition: ServoMotor.h:86
void setAngle(int8_t rosAngleDegrees)
Definition: ServoMotor.h:54
- Note
- Requires the Arduino Servo library.
◆ begin()
◆ end()
◆ getAngle()
Get the last written angle (degrees)
◆ getValuePercent()
| T getValuePercent |
( |
| ) |
const |
|
inlineoverridevirtual |
◆ isPinsSet()
◆ setAngle()
| void setAngle |
( |
int8_t |
rosAngleDegrees | ) |
|
|
inline |
Set servo angle (degrees, 90 .. -90): 0 is forward
◆ setConstraints()
| void setConstraints |
( |
int |
minAngle, |
|
|
int |
maxAngle |
|
) |
| |
|
inline |
Set constraints on the allowed angle range (degrees). This can be used to prevent the servo from moving beyond physical limits or to limit the range of motion for safety: by default, the full range of -90 to 90 degrees is allowed.
◆ setPin()
Attach the servo to a pin
◆ setValuePercent()
| bool setValuePercent |
( |
T |
percent | ) |
|
|
inlineoverridevirtual |
Set servo position as a percentage (-100 to 100). -100 = minAngle, 0 = center, 100 = maxAngle
Implements IMotor< T >.
The documentation for this class was generated from the following file: