Tripple Controller for the TLE5206 H Bridge motor controller
inc/example2.h@4:d69f22061c03, 2011-07-05 (annotated)
- Committer:
- AjK
- Date:
- Tue Jul 05 14:55:29 2011 +0000
- Revision:
- 4:d69f22061c03
- Parent:
- 3:b7d951c6f551
0.6 Beta See ChangLog.h
Who changed what in which revision?
User | Revision | Line number | New 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 | /* See example1.h for basic notes. |
AjK | 3:b7d951c6f551 | 6 | * |
AjK | 3:b7d951c6f551 | 7 | * This example shows how to use the acceleration and deceleration |
AjK | 3:b7d951c6f551 | 8 | * profiler to manage changing speed in a simple linear fashion. |
AjK | 3:b7d951c6f551 | 9 | * |
AjK | 3:b7d951c6f551 | 10 | * The default accel and decel rates are 0.01/10ms. So when a speed |
AjK | 4:d69f22061c03 | 11 | * of say +1.0 is demanded, it actually takes 1second to reach that |
AjK | 3:b7d951c6f551 | 12 | * target desired speed due to the acceleration profiler. Likewise |
AjK | 3:b7d951c6f551 | 13 | * for deceleration. |
AjK | 3:b7d951c6f551 | 14 | * |
AjK | 3:b7d951c6f551 | 15 | * You can adjust the rates by altering the "poll interval" and the |
AjK | 4:d69f22061c03 | 16 | * accel/decel rates with the API functions. |
AjK | 3:b7d951c6f551 | 17 | */ |
AjK | 3:b7d951c6f551 | 18 | |
AjK | 3:b7d951c6f551 | 19 | #define DUTY_CYCLE_IN_HERTZ 50 |
AjK | 3:b7d951c6f551 | 20 | |
AjK | 3:b7d951c6f551 | 21 | // Create a motor "A", driven by a TLE5206 on pins 21 and 22 (attach scope first, not a motor!) |
AjK | 3:b7d951c6f551 | 22 | SimpleTLE5206Output Ain1(p21); // TLE5206 In1 is connected to p21 |
AjK | 3:b7d951c6f551 | 23 | SimpleTLE5206Output Ain2(p22); // TLE5206 In2 is connected to p22 |
AjK | 3:b7d951c6f551 | 24 | SimpleTLE5206Profiler motorA(&Ain1, &Ain2, DUTY_CYCLE_IN_HERTZ); // Create the TLE5206 controller. |
AjK | 3:b7d951c6f551 | 25 | |
AjK | 3:b7d951c6f551 | 26 | int main() { |
AjK | 3:b7d951c6f551 | 27 | |
AjK | 3:b7d951c6f551 | 28 | while(1) { |
AjK | 3:b7d951c6f551 | 29 | // Start from stationary. |
AjK | 3:b7d951c6f551 | 30 | motorA.setSpeed(0); |
AjK | 3:b7d951c6f551 | 31 | wait(1); |
AjK | 3:b7d951c6f551 | 32 | |
AjK | 3:b7d951c6f551 | 33 | // Command full desired speed CW |
AjK | 3:b7d951c6f551 | 34 | motorA.setSpeed(1.0); |
AjK | 3:b7d951c6f551 | 35 | |
AjK | 3:b7d951c6f551 | 36 | // Wait for it to reach that speed. |
AjK | 3:b7d951c6f551 | 37 | while( motorA.getSpeed() != 1.0) ; |
AjK | 3:b7d951c6f551 | 38 | |
AjK | 3:b7d951c6f551 | 39 | // Wait for 3seconds |
AjK | 3:b7d951c6f551 | 40 | wait(3); |
AjK | 3:b7d951c6f551 | 41 | |
AjK | 3:b7d951c6f551 | 42 | // Stop the motor |
AjK | 3:b7d951c6f551 | 43 | motorA.setSpeed(0.0); |
AjK | 3:b7d951c6f551 | 44 | while( motorA.getSpeed() != 0.0) ; |
AjK | 3:b7d951c6f551 | 45 | |
AjK | 3:b7d951c6f551 | 46 | // Wait for 3seconds |
AjK | 3:b7d951c6f551 | 47 | wait(3); |
AjK | 3:b7d951c6f551 | 48 | |
AjK | 3:b7d951c6f551 | 49 | // Command full desired speed CCW |
AjK | 3:b7d951c6f551 | 50 | motorA.setSpeed(-1.0); |
AjK | 3:b7d951c6f551 | 51 | |
AjK | 3:b7d951c6f551 | 52 | // Wait for it to reach that speed. |
AjK | 3:b7d951c6f551 | 53 | while( motorA.getSpeed() != -1.0) ; |
AjK | 3:b7d951c6f551 | 54 | |
AjK | 3:b7d951c6f551 | 55 | // Wait for 3seconds |
AjK | 3:b7d951c6f551 | 56 | wait(3); |
AjK | 3:b7d951c6f551 | 57 | |
AjK | 3:b7d951c6f551 | 58 | // Stop the motor |
AjK | 3:b7d951c6f551 | 59 | motorA.setSpeed(0.0); |
AjK | 3:b7d951c6f551 | 60 | while( motorA.getSpeed() != 0.0) ; |
AjK | 3:b7d951c6f551 | 61 | |
AjK | 3:b7d951c6f551 | 62 | // Wait for 3seconds |
AjK | 3:b7d951c6f551 | 63 | wait(3); |
AjK | 3:b7d951c6f551 | 64 | |
AjK | 3:b7d951c6f551 | 65 | // repeat the cycle. |
AjK | 3:b7d951c6f551 | 66 | } |
AjK | 3:b7d951c6f551 | 67 | } |
AjK | 3:b7d951c6f551 | 68 | |
AjK | 3:b7d951c6f551 | 69 |