Tripple Controller for the TLE5206 H Bridge motor controller

Committer:
AjK
Date:
Tue Jul 05 14:27:56 2011 +0000
Revision:
3:b7d951c6f551
Child:
4:d69f22061c03
0.5 Beta See ChangeLog.h

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AjK 3:b7d951c6f551 1
AjK 3:b7d951c6f551 2 #include "mbed.h"
AjK 3:b7d951c6f551 3 #include "SimpleTLE5206Profiler.h"
AjK 3:b7d951c6f551 4
AjK 3:b7d951c6f551 5 Serial pc(USBTX, USBRX);
AjK 3:b7d951c6f551 6
AjK 3:b7d951c6f551 7 /* See example1.h for basic notes.
AjK 3:b7d951c6f551 8 *
AjK 3:b7d951c6f551 9 * This example shows how to use the acceleration and deceleration
AjK 3:b7d951c6f551 10 * profiler to manage changing speed in a simple linear fashion.
AjK 3:b7d951c6f551 11 *
AjK 3:b7d951c6f551 12 * The default accel and decel rates are 0.01/10ms. So when a speed
AjK 3:b7d951c6f551 13 * of say +1.0 is demanded, it actually takes 1seond to reach that
AjK 3:b7d951c6f551 14 * target desired speed due to the acceleration profiler. Likewise
AjK 3:b7d951c6f551 15 * for deceleration.
AjK 3:b7d951c6f551 16 *
AjK 3:b7d951c6f551 17 * You can adjust the rates by altering the "poll interval" and the
AjK 3:b7d951c6f551 18 * step change size.
AjK 3:b7d951c6f551 19 */
AjK 3:b7d951c6f551 20
AjK 3:b7d951c6f551 21 #define DUTY_CYCLE_IN_HERTZ 50
AjK 3:b7d951c6f551 22
AjK 3:b7d951c6f551 23 // Create a motor "A", driven by a TLE5206 on pins 21 and 22 (attach scope first, not a motor!)
AjK 3:b7d951c6f551 24 SimpleTLE5206Output Ain1(p21); // TLE5206 In1 is connected to p21
AjK 3:b7d951c6f551 25 SimpleTLE5206Output Ain2(p22); // TLE5206 In2 is connected to p22
AjK 3:b7d951c6f551 26 SimpleTLE5206Profiler motorA(&Ain1, &Ain2, DUTY_CYCLE_IN_HERTZ); // Create the TLE5206 controller.
AjK 3:b7d951c6f551 27
AjK 3:b7d951c6f551 28 int main() {
AjK 3:b7d951c6f551 29
AjK 3:b7d951c6f551 30 pc.baud(115200);
AjK 3:b7d951c6f551 31
AjK 3:b7d951c6f551 32 while(1) {
AjK 3:b7d951c6f551 33 // Start from stationary.
AjK 3:b7d951c6f551 34 motorA.setSpeed(0);
AjK 3:b7d951c6f551 35 wait(1);
AjK 3:b7d951c6f551 36
AjK 3:b7d951c6f551 37 // Command full desired speed CW
AjK 3:b7d951c6f551 38 motorA.setSpeed(1.0);
AjK 3:b7d951c6f551 39
AjK 3:b7d951c6f551 40 // Wait for it to reach that speed.
AjK 3:b7d951c6f551 41 while( motorA.getSpeed() != 1.0) ;
AjK 3:b7d951c6f551 42
AjK 3:b7d951c6f551 43 // Wait for 3seconds
AjK 3:b7d951c6f551 44 wait(3);
AjK 3:b7d951c6f551 45
AjK 3:b7d951c6f551 46 // Stop the motor
AjK 3:b7d951c6f551 47 motorA.setSpeed(0.0);
AjK 3:b7d951c6f551 48 while( motorA.getSpeed() != 0.0) ;
AjK 3:b7d951c6f551 49
AjK 3:b7d951c6f551 50 // Wait for 3seconds
AjK 3:b7d951c6f551 51 wait(3);
AjK 3:b7d951c6f551 52
AjK 3:b7d951c6f551 53 // Command full desired speed CCW
AjK 3:b7d951c6f551 54 motorA.setSpeed(-1.0);
AjK 3:b7d951c6f551 55
AjK 3:b7d951c6f551 56 // Wait for it to reach that speed.
AjK 3:b7d951c6f551 57 while( motorA.getSpeed() != -1.0) ;
AjK 3:b7d951c6f551 58
AjK 3:b7d951c6f551 59 // Wait for 3seconds
AjK 3:b7d951c6f551 60 wait(3);
AjK 3:b7d951c6f551 61
AjK 3:b7d951c6f551 62 // Stop the motor
AjK 3:b7d951c6f551 63 motorA.setSpeed(0.0);
AjK 3:b7d951c6f551 64 while( motorA.getSpeed() != 0.0) ;
AjK 3:b7d951c6f551 65
AjK 3:b7d951c6f551 66 // Wait for 3seconds
AjK 3:b7d951c6f551 67 wait(3);
AjK 3:b7d951c6f551 68
AjK 3:b7d951c6f551 69 // repeat the cycle.
AjK 3:b7d951c6f551 70 }
AjK 3:b7d951c6f551 71 }
AjK 3:b7d951c6f551 72
AjK 3:b7d951c6f551 73