![]() |
Smart Car Controller
1.0
LIbrary to manage a Smart Car Robot
|
#include <MD_DCMotor.h>
Public Types | |
Enumerated values and Typedefs. | |
enum | runCmd_t { DIR_FWD , DIR_REV , DIR_STOP } |
Public Member Functions | |
Methods for core object control. | |
virtual void | begin (void)=0 |
virtual void | run (runCmd_t cmd, uint8_t speed)=0 |
virtual void | setSpeed (uint16_t s)=0 |
uint16_t | getSpeed () |
Protected Attributes | |
runCmd_t | _mode |
The current mode for the motor. | |
uint16_t | _speed |
The current speed setting for the motor. | |
Core object for the MD_DCMotor class
This class is a simple abstraction for PWM motor controllers that use 2 digital pins for direction control and PWM for speed control.
enum MD_DCMotor::runCmd_t |
Define the different motor commands/states
These commands are used to direct the different modes of running the DC motors allowed by the controller.
Enumerator | |
---|---|
DIR_FWD | Rotate in forward direction. |
DIR_REV | Rotate in reverse direction (opposite of DIR_FWD). |
DIR_STOP | Stop the motor. This should brake if possible. |
|
pure virtual |
Initialize the object.
Initialize the object data. This needs to be called during setup() to initialize new data for the class that cannot be done during the object creation.
Implemented in MD_DCMotor_M1508, and MD_DCMotor_L298.
uint16_t MD_DCMotor::getSpeed | ( | ) |
Get the currently set speed for the motor.
Returns the current speed setting
|
pure virtual |
Run/Stop the motor with speed.
This controls how the motor runs/stops. This is a convenience wrapper for the run() and setSpeed() methods. The command specified is one of the runCmd_t values and the speed must be suitable for the setSpeed() method.
cmd | the run/stop mode. |
speed | the speed to run at. |
Implemented in MD_DCMotor_M1508, and MD_DCMotor_L298.
|
pure virtual |
Set the speed for the motor.
This controls the speed setting for the motor. This is replaced with a method to implement the specifics for the derived class.
s | the speed setting appropriate for the controller type. |
Implemented in MD_DCMotor_M1508, and MD_DCMotor_L298.