Control an H-Bridge using a PwmOut (enable) and two DigitalOuts (direction select)
Fork of Motor by
Revision 13:d67ecfc6cd7f, committed 2015-05-18
- Comitter:
- miczyg
- Date:
- Mon May 18 12:49:42 2015 +0000
- Parent:
- 12:8d67376b521d
- Child:
- 14:9fa93c83285e
- Commit message:
- hjg
Changed in this revision
--- a/Motor.h Mon May 18 11:05:31 2015 +0000 +++ b/Motor.h Mon May 18 12:49:42 2015 +0000 @@ -5,13 +5,13 @@ #include "PID.h" #include "QEI.h" -/*nastawy regulatora PID*/ +/*nastawy regulatora PID const float K = 1; const float Ti = 0; const float Td = 0; const float itv = 0.001; #define AUTO 1 - +*/ /*QEI pins*/ /* #define CH_A PTA2
--- a/MotorL.cpp Mon May 18 11:05:31 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,43 +0,0 @@ -#include "MotorL.h" -#include "mbed.h" - -MotorL::MotorL(PinName pwm, PinName fwd, PinName rev, PinName stby) : -_pwm(pwm), _fwd(fwd), _rev(rev), _stdby(stby)//, speedControl(K, Ti, Td, itv)//, encoder(CH_A, CH_B, NC, pPerRev) -{ - - // Set initial condition of PWM - _pwm.period(0.001); - _pwm = 0; - _stdby = 1; - // Initial condition of output enables - _fwd = 0; - _rev = 0; - - //PID config - //speedControl.setInputLimits(0, 1); - //speedControl.setOutputLimits(0, 1); - //speedControl.setMode(AUTO); - -} - -void MotorL::speed(float speed) { - -/*PID do enkoderow i utrzymywania stalej predkosci*/ -/* - if (speed != set_speed){ - speedControl.setSetPoint(speed); - set_speed = speed; - } - - pulses = encoder.getPulses(); - curr_speed = (pulses-prev_pulses) / max_pulse_rate; - prev_pulses = pulses; - - speedControl.setProcessValue(curr_speed); - speed = speedControl.compute(); -*/ - - _fwd = (speed > 0.0); - _rev = (speed < 0.0); - _pwm = abs(speed); -}
--- a/MotorL.h Mon May 18 11:05:31 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,57 +0,0 @@ -#ifndef MBED_MOTORL_H -#define MBED_MOTORL_H - -#include "mbed.h" -//#include "PID.h" - -/*nastawy regulatora PID*/ -/* -const float K = 1; -const float Ti = 0; -const float Td = 0; -const float itv = 0.001; -#define AUTO 1 -*/ -/** Interface to control a standard DC motor -* -* with an H-bridge using a PwmOut and 2 DigitalOuts -*/ -class MotorL { -public: - - /** Create a motor control interface - * - * @param pwm A PwmOut pin, driving the H-bridge enable line to control the speed - * @param fwd A DigitalOut, set high when the motor should go forward - * @param rev A DigitalOut, set high when the motor should go backwards - */ - MotorL(PinName pwm, PinName fwd, PinName rev, PinName stby); - - /** Set the speed of the motor - * - * @param speed The speed of the motor as a normalised value between -1.0 and 1.0 - */ - void speed(float speed); - - /**Change the stand by status of H-bridge - * - * @param status 0 - bridge disabled, 1 - bridge enabled - */ - void setStandby(bool status) - { - _stdby = status; - } - -protected: - PwmOut _pwm; - DigitalOut _fwd; - DigitalOut _rev; - DigitalOut _stdby; -private: - //PID speedControl; - //QEI encoder; - float set_speed; - -}; - -#endif
--- a/MotorR.cpp Mon May 18 11:05:31 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,43 +0,0 @@ -#include "MotorR.h" -#include "mbed.h" - -MotorR::MotorR(PinName pwm, PinName fwd, PinName rev, PinName stby) : -_pwm(pwm), _fwd(fwd), _rev(rev), _stdby(stby)//, speedControl(K, Ti, Td, itv)//, encoder(CH_A, CH_B, NC, pPerRev) -{ - - // Set initial condition of PWM - _pwm.period(0.001); - _pwm = 0; - _stdby = 1; - // Initial condition of output enables - _fwd = 0; - _rev = 0; - - //PID config - //speedControl.setInputLimits(0, 1); - //speedControl.setOutputLimits(0, 1); - //speedControl.setMode(AUTO); - -} - -void MotorR::speed(float speed) { - -/*PID do enkoderow i utrzymywania stalej predkosci*/ -/* - if (speed != set_speed){ - speedControl.setSetPoint(speed); - set_speed = speed; - } - - pulses = encoder.getPulses(); - curr_speed = (pulses-prev_pulses) / max_pulse_rate; - prev_pulses = pulses; - - speedControl.setProcessValue(curr_speed); - speed = speedControl.compute(); -*/ - - _fwd = (speed > 0.0); - _rev = (speed < 0.0); - _pwm = abs(speed); -}
--- a/MotorR.h Mon May 18 11:05:31 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,57 +0,0 @@ -#ifndef MBED_MOTORR_H -#define MBED_MOTORR_H - -#include "mbed.h" -//#include "PID.h" - -/*nastawy regulatora PID*/ -/* -const float K = 1; -const float Ti = 0; -const float Td = 0; -const float itv = 0.001; -#define AUTO 1 -*/ -/** Interface to control a standard DC motor -* -* with an H-bridge using a PwmOut and 2 DigitalOuts -*/ -class MotorR { -public: - - /** Create a motor control interface - * - * @param pwm A PwmOut pin, driving the H-bridge enable line to control the speed - * @param fwd A DigitalOut, set high when the motor should go forward - * @param rev A DigitalOut, set high when the motor should go backwards - */ - MotorR(PinName pwm, PinName fwd, PinName rev, PinName stby); - - /** Set the speed of the motor - * - * @param speed The speed of the motor as a normalised value between -1.0 and 1.0 - */ - void speed(float speed); - - /**Change the stand by status of H-bridge - * - * @param status 0 - bridge disabled, 1 - bridge enabled - */ - void setStandby(bool status) - { - _stdby = status; - } - -protected: - PwmOut _pwm; - DigitalOut _fwd; - DigitalOut _rev; - DigitalOut _stdby; -private: - //PID speedControl; - //QEI encoder; - float set_speed; - -}; - -#endif