Tripple Controller for the TLE5206 H Bridge motor controller

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers example2.h Source File

example2.h

00001 
00002 #include "mbed.h"
00003 #include "SimpleTLE5206Profiler.h"
00004 
00005 /* See example1.h for basic notes.
00006  *
00007  * This example shows how to use the acceleration and deceleration
00008  * profiler to manage changing speed in a simple linear fashion.
00009  *
00010  * The default accel and decel rates are 0.01/10ms. So when a speed
00011  * of say +1.0 is demanded, it actually takes 1second to reach that
00012  * target desired speed due to the acceleration profiler. Likewise
00013  * for deceleration.
00014  *
00015  * You can adjust the rates by altering the "poll interval" and the
00016  * accel/decel rates with the API functions.
00017  */
00018 
00019 #define DUTY_CYCLE_IN_HERTZ 50
00020 
00021 // Create a motor "A", driven by a TLE5206 on pins 21 and 22 (attach scope first, not a motor!)
00022 SimpleTLE5206Output Ain1(p21);    // TLE5206 In1 is connected to p21
00023 SimpleTLE5206Output Ain2(p22);    // TLE5206 In2 is connected to p22
00024 SimpleTLE5206Profiler motorA(&Ain1, &Ain2, DUTY_CYCLE_IN_HERTZ); // Create the TLE5206 controller.
00025 
00026 int main() {
00027 
00028     while(1) {    
00029         // Start from stationary.
00030         motorA.setSpeed(0);
00031         wait(1);
00032         
00033         // Command full desired speed CW
00034         motorA.setSpeed(1.0);
00035         
00036         // Wait for it to reach that speed.
00037         while( motorA.getSpeed() != 1.0) ;
00038         
00039         // Wait for 3seconds
00040         wait(3);
00041         
00042         // Stop the motor
00043         motorA.setSpeed(0.0);
00044         while( motorA.getSpeed() != 0.0) ;   
00045         
00046         // Wait for 3seconds
00047         wait(3);
00048         
00049         // Command full desired speed CCW
00050         motorA.setSpeed(-1.0);
00051         
00052         // Wait for it to reach that speed.
00053         while( motorA.getSpeed() != -1.0) ;
00054         
00055         // Wait for 3seconds
00056         wait(3);
00057         
00058         // Stop the motor
00059         motorA.setSpeed(0.0);
00060         while( motorA.getSpeed() != 0.0) ;   
00061         
00062         // Wait for 3seconds
00063         wait(3);
00064 
00065         // repeat the cycle.        
00066     }
00067 }
00068 
00069