|
|
| BrushedMotor (uint8_t id=0) |
| | Empty constructor for late pin assignment.
|
| |
|
void | setPins (int pin1, int pin2, int pwmFreq=20000) |
| | Set the pins for the HBridge after construction.
|
| |
| bool | begin () |
| |
| void | setConstraints (T minSpeed, T maxSpeed) |
| |
|
void | setReverse (bool reverse) |
| | Invert the direction logic.
|
| |
| bool | setValuePercent (T percent) override |
| |
| T | getValuePercent () const override |
| |
| void | end () override |
| |
| bool | isPinsSet () const |
| | Check if the control pins have been set (i.e., not -1).
|
| |
| 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::BrushedMotor< T >
High-level H-Bridge motor driver class for bidirectional DC motor control.
This class provides an easy interface for controlling a DC motor using a standard H-Bridge driver (e.g., L298N, L293D, TB6612FNG). It supports:
- Forward, reverse, and stop (brake) control
- PWM speed control (signed, -255 to 255 or limited by setConstraints)
- Speed setting in percent (-100 to 100)
- Optional PWM frequency configuration (if supported by platform)
- Speed limiting for safety or motor tuning
Usage Example:
HBridge motor(5, 6);
motor.setConstraints(-200, 200);
motor.setSpeed(50);
motor.setSpeed(-50);
motor.stop();
- Note
- If your platform does not support analogWriteFreq, the default PWM frequency will be used.