motor drive libary to use speed control, coasting and dynamic braking. NOTE, dynamic braking my result in large currents. this may or may not set the motor driver on fire/break it/other undesired effects. so read the data sheet folks.

Dependents:   Test

Fork of Motordriver by Christopher Hasler

Embed: (wiki syntax)

« Back to documentation index

Motor Class Reference

Motor Class Reference

Interface to control a standard DC motor with an H-bridge using a PwmOut and 2 DigitalOuts. More...

#include <motordriver.h>

Public Member Functions

 Motor (PinName pwm, PinName fwd, PinName rev, int brakeable)
 Create a motor control interface.
float speed (float speed)
 Set the speed of the motor.
void coast (void)
 Set the the motor to coast.
float stop (float duty)
 Set the motor to dynamicaly brake.
float state (void)
 return the current state of the motor

Detailed Description

Interface to control a standard DC motor with an H-bridge using a PwmOut and 2 DigitalOuts.

Definition at line 37 of file motordriver.h.


Constructor & Destructor Documentation

Motor ( PinName  pwm,
PinName  fwd,
PinName  rev,
int  brakeable 
)

Create a motor control interface.

Parameters:
pwmA PwmOut pin, driving the H-bridge enable line to control the speed
fwdA DigitalOut, set high when the motor should go forward
revA DigitalOut, set high when the motor should go backwards
setif the motor driver is able to do braking 0 false 1 true.

Definition at line 33 of file motordriver.cpp.


Member Function Documentation

void coast ( void   )

Set the the motor to coast.

Parameters:
void
Returns:
motor coasts until another instruction is recived.

Definition at line 90 of file motordriver.cpp.

float speed ( float  speed )

Set the speed of the motor.

Parameters:
speedThe speed of the motor as a normalised value between -1.0 and 1.0.
Returns:
the applied speed to the motor after checking to ensure motor doesn't switch from forward to reverse without stopping.

Definition at line 48 of file motordriver.cpp.

float state ( void   )

return the current state of the motor

Parameters:
void
Returns:
state of motor, -1 to 1 is speed, -2 is braking, 2 is coasting. -3 is error.

Definition at line 109 of file motordriver.cpp.

float stop ( float  duty )

Set the motor to dynamicaly brake.

Parameters:
float0 - 1.0 provides some control over how hard the motor brakes.
Returns:
duty applied to motor driver. -1 is error, motor driver can't brake.

Definition at line 97 of file motordriver.cpp.