Clownface / MotorDriver

Fork of MotorDriver by Matt Rogers

Embed: (wiki syntax)

« Back to documentation index

MotorDriver Class Reference

MotorDriver Class Reference

MotorDriver class. More...

#include <MotorDriver.h>

Public Member Functions

 MotorDriver (DigitalOut in1, DigitalOut in2, PwmOut pwm, float pwmFreq, bool isBrakeable=false)
 Constructor of MotorDriver Objects.
State_t setSpeed (float speed)
 Sets speed of motor normalized between -1.0 to 1.0.
State_t forceSetSpeed (float speed)
 Same as setSpeed(float speed), however does not impose the safety disallowing instantaneous reversal of motor direction.
State_t brake (float intensity)
 Put motor into braked config.
State_t coast ()
 Put motor into stop/coast config.
State_t getState ()
 Get state of the motor.

Detailed Description

MotorDriver class.

Used for DIY project "RC-AutoBot" by Clownface.space

Example:

 #include "mbed.h"
 #include "MotorDriver.h"

 MotorDriver m1(in1, in2, pwm);

 void dist(int distance)
 {
  //put code here to happen when the distance is changed
  printf("\r\n** Distance changed to %dmm\r\n", distance);
  sensorDistance = distance;
 }

 int main() {
     m1.setSpeed(1);
 }

Definition at line 70 of file MotorDriver.h.


Constructor & Destructor Documentation

MotorDriver ( DigitalOut  in1,
DigitalOut  in2,
PwmOut  pwm,
float  pwmFreq,
bool  isBrakeable = false 
)

Constructor of MotorDriver Objects.

Parameters:
in_1Direction Input 1
in_2Direction Input 2
pwmPWM speed control input
pwmFreqPWM frequency, some motors may whine at lower freqs
isBrakableBoolean value indicating whether or not the motor driver is brakeable(see your datasheet)

Definition at line 6 of file MotorDriver.cpp.


Member Function Documentation

State_t brake ( float  intensity )

Put motor into braked config.

Parameters:
intensityHow hard to brake (0.0 to 1.0)
Returns:
state of the motors

Definition at line 76 of file MotorDriver.cpp.

State_t coast (  )

Put motor into stop/coast config.

Definition at line 88 of file MotorDriver.cpp.

State_t forceSetSpeed ( float  speed )

Same as setSpeed(float speed), however does not impose the safety disallowing instantaneous reversal of motor direction.

It is up to the user to ensure they do not blow up their motor.

Parameters:
speedHow fast to run the motor

Definition at line 63 of file MotorDriver.cpp.

State_t getState (  )

Get state of the motor.

Returns:
state of the motor

Definition at line 97 of file MotorDriver.cpp.

State_t setSpeed ( float  speed )

Sets speed of motor normalized between -1.0 to 1.0.

Parameters:
speedValue -1.0 to 1.0 (>0 CW at speed as percentage) (<0 CCW at speed as percentage) (=0 speed is zero)
Returns:
state of the motor NOTE: This method will NOT allow user to instantaneously swithch from CW to CCW or vise versa. Doing so will cause the motor to be put in to a BRAKE condition, while the motor_state.code will be updated to MOTOR_ERROR. User should avoid trying to do this, call first setSpeed(0) or brake().

Definition at line 38 of file MotorDriver.cpp.