Control a DC motor via a standard H-bridge using a PwmOut pin to control speed and two DigitalOut pins to control direction. Can change pwm period on the PwmOut pin, and also brake high or low.

Dependents:   SimpleRover PIDRover IMURover incrementalencoder-pid-robot ... more

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 <Motor.h>

Public Member Functions

 Motor (PinName pwm, PinName fwd, PinName rev)
 Create a motor control interface.
void speed (float speed)
 Set the speed of the motor.
void period (float period)
 Set the period of the pwm duty cycle.
void brake (int highLow=BRAKE_HIGH)
 Brake the H-bridge to GND or VCC.

Detailed Description

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

Definition at line 34 of file Motor.h.


Constructor & Destructor Documentation

Motor ( PinName  pwm,
PinName  fwd,
PinName  rev 
)

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

Definition at line 25 of file Motor.cpp.


Member Function Documentation

void brake ( int  highLow = BRAKE_HIGH )

Brake the H-bridge to GND or VCC.

Defaults to breaking to VCC.

Brake to GND => inA = inB = 0 Brake to VCC => inA = inB = 1

Definition at line 49 of file Motor.cpp.

void period ( float  period )

Set the period of the pwm duty cycle.

Wrapper for PwmOut::period()

Parameters:
seconds- Pwm duty cycle in seconds.

Definition at line 43 of file Motor.cpp.

void 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

Definition at line 37 of file Motor.cpp.