j
Fork of Motordriver by
Embed:
(wiki syntax)
Show/hide line numbers
motordriver.h
00001 #ifndef MBED_MOTOR_H 00002 #define MBED_MOTOR_H 00003 00004 #include "mbed.h" 00005 00006 /** Interface to control a standard DC motor 00007 * with an H-bridge using a PwmOut and 2 DigitalOuts 00008 */ 00009 class Motor { 00010 public: 00011 00012 /** Create a motor control interface 00013 * 00014 * @param pwm A PwmOut pin, driving the H-bridge enable line to control the speed 00015 * @param fwd A DigitalOut, set high when the motor should go forward 00016 * @param rev A DigitalOut, set high when the motor should go backwards 00017 * @param set if the motor driver is able to do braking 0 false 1 true. 00018 */ 00019 Motor(PinName pwm, PinName fwd, PinName rev, int brakeable); 00020 00021 /** Set the speed of the motor 00022 * 00023 * @param speed The speed of the motor as a normalised value between -1.0 and 1.0. 00024 * @return the applied speed to the motor after checking to ensure motor doesn't switch from forward to reverse without stopping. 00025 */ 00026 float speed(float speed); 00027 00028 /** Set the the motor to coast 00029 * 00030 * @param void 00031 * @return motor coasts until another instruction is recived. 00032 */ 00033 00034 void coast(void); 00035 00036 /** Set the motor to dynamicaly brake 00037 * 00038 * @param float 0 - 1.0 provides some control over how hard the motor brakes. 00039 * @return duty applied to motor driver. -1 is error, motor driver can't brake. 00040 */ 00041 00042 float stop(float duty); 00043 /** return the current state of the motor 00044 * 00045 * @param void 00046 * @return state of motor, -1 to 1 is speed, -2 is braking, 2 is coasting. -3 is error. 00047 */ 00048 float state(void); 00049 00050 protected: 00051 PwmOut _pwm; 00052 DigitalOut _fwd; 00053 DigitalOut _rev; 00054 int Brakeable; // cna the motor driver break 00055 int sign; //prevents throwing the motor from full foward to full reverse and stuff melting. 00056 00057 }; 00058 00059 00060 00061 00062 00063 #endif
Generated on Mon Aug 1 2022 07:25:02 by
