TinyRobotics
Loading...
Searching...
No Matches
Public Member Functions | Protected Attributes | List of all members
ServoMotor< T > Class Template Reference

High-level wrapper for Arduino Servo control (RC servo motors). More...

#include <ServoMotor.h>

Inheritance diagram for ServoMotor< T >:
Inheritance graph
[legend]
Collaboration diagram for ServoMotor< T >:
Collaboration graph
[legend]

Public Member Functions

 ServoMotor (uint8_t id=0)
 
void setPin (int pin)
 
bool begin ()
 
void setAngle (int8_t rosAngleDegrees)
 
int8_t getAngle ()
 
bool setValuePercent (T percent) override
 
getValuePercent () const override
 
void setConstraints (int minAngle, int maxAngle)
 
void end () override
 
bool isPinsSet () const
 
- Public Member Functions inherited from IMotor< T >
virtual bool begin ()=0
 
virtual void end ()=0
 
virtual bool isPinsSet () const =0
 
virtual bool setValuePercent (T percent)=0
 
virtual T getValuePercent () const =0
 
void setID (uint8_t id)
 
uint8_t getID () const
 

Protected Attributes

::Servo servo
 
int pin = -1
 
int minAngle = -90
 
int maxAngle = 90
 
bool is_pin_asssigned = false
 
lastValuePercent = 0.0f
 
- Protected Attributes inherited from IMotor< T >
uint8_t id = 0
 

Detailed Description

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:

Usage Example:

ServoMotor servo;
servo.attach(9); // Attach to pin 9
servo.setConstraints(-45, 45); // Limit range to -45..45 degrees
servo.setAngle(45); // Set to 45 degrees left
int angle = servo.getAngle(); // Read last angle
servo.detach(); // Detach when done
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.

Member Function Documentation

◆ begin()

bool begin ( )
inlinevirtual

Implements IMotor< T >.

◆ end()

void end ( )
inlineoverridevirtual

Implements IMotor< T >.

◆ getAngle()

int8_t getAngle ( )
inline

Get the last written angle (degrees)

◆ getValuePercent()

T getValuePercent ( ) const
inlineoverridevirtual

Implements IMotor< T >.

◆ isPinsSet()

bool isPinsSet ( ) const
inlinevirtual

Implements IMotor< T >.

◆ 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()

void setPin ( int  pin)
inline

Attach the servo to a pin

◆ setValuePercent()

bool setValuePercent ( 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: