Motor abstraction for integrating external/custom motor drivers using callbacks.
More...
|
|
| GenericMotor (uint8_t id, void *driver=nullptr) |
| |
| bool | begin () override |
| | Start the motor using the optional begin callback.
|
| |
| bool | setValuePercent (T percent) override |
| | Set value as percentage (-100 to 100)
|
| |
| T | getValuePercent () const override |
| | Get current value percentage.
|
| |
|
void | setAngle (T angle) |
| | For Servo: Set angle in degrees (-90 to 90) by mapping it to percentage.
|
| |
|
T | getAngle () |
| | For Servo: Get angle in degrees by mapping percentage back to angle.
|
| |
| void | end () override |
| | Stop the motor using the optional end callback.
|
| |
|
void | setValueCallback (void(*valueCB)(T value, GenericMotor &motor)) |
| | Mandatory callback to define speed/angle control behavior.
|
| |
|
void | setBeginCallback (bool(*beginCB)(GenericMotor &motor)) |
| | Optional callback to define begin behavior.
|
| |
|
void | setEndCallback (void(*endCB)(GenericMotor &motor)) |
| | Optional callback to define end behavior.
|
| |
|
template<typename DriverT > |
| DriverT & | getDriver () |
| | Provides the user motor object.
|
| |
| bool | isPinsSet () const override |
| | Not supported.
|
| |
|
void | setPin (int pin) |
| | Not supported.
|
| |
|
void | setPins (int, int, int na=-1) |
| | Not supported.
|
| |
| 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 |
| |
template<typename T = float>
class tinyrobotics::GenericMotor< T >
Motor abstraction for integrating external/custom motor drivers using callbacks.
This class provides a flexible interface for controlling motors that do not fit the standard interface. The user supplies an external motor object (as a void pointer) and callback functions for starting/stopping the motor and for setting the speed or angle. This allows integration of custom motor drivers or hardware with the TinyRobotics framework.
- The
valueCB callback is mandatory and is called with the desired speed or angle value.
- The
beginCB and endCB callbacks are optional and can be used to define custom start/stop logic.
- The user motor object can be accessed via
getMotor<T>().
Example usage:
MyMotorDriver driver;
MyMotorDriver* drv = m.getMotor<MyMotorDriver>();
drv->setPWM(value);
});
return true;
});
motor.setEndCallback([](GenericMotor& m) {
});
Motor abstraction for integrating external/custom motor drivers using callbacks.
Definition: GenericMotor.h:45