test script for motordriver. correct results are in the comments.

Dependencies:   mbed Motordriver

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include <mbed.h>
00002 #include <motordriver.h>
00003 //pc interface
00004 Serial pc(USBTX, USBRX); // tx, rx
00005 //declare motors
00006 Motor A(p22, p6, p5, 1); // pwm, fwd, rev, can break
00007 Motor B(p21, p7, p8, 1); // pwm, fwd, rev, can break
00008 //debugging stuff, switches a new led on after each sqeuence.
00009 DigitalOut led1 (LED1);
00010 DigitalOut led2 (LED2);
00011 DigitalOut led3 (LED3);
00012 DigitalOut led4 (LED4);
00013 
00014 int main() {
00015     pc.printf("motor A, reverse to foward \n");
00016     pc.printf("motor B, reverse to foward \n\n");
00017 
00018     pc.printf("state motor A, %f, state motor B, %f \n\n", A.state(), B.state());
00019     //should be 2.
00020     led1=1;
00021 
00022     for (float s=-1.0; s < 1.0 ; s += 0.01) {//sweep from reverse to foward
00023         pc.printf("A %f %f \n",A.speed(s), s);
00024         pc.printf("B %f %f \n\n",B.speed(s), s);
00025         //should follow the output of the for loop
00026         wait(0.02);
00027     }
00028     pc.printf("state motor A, %f, state motor B, %f \n\n", A.state(), B.state());
00029     //should be 0.99 0.99.
00030     
00031     led2=1;
00032 
00033     pc.printf("\nmotor A, braking \n");
00034     pc.printf("motor B, braking \n\n");
00035 
00036     pc.printf("A %f 0.5 \n",A.stop(0.5));
00037     pc.printf("B %f 0.5 \n",B.stop(0.5));
00038 
00039     pc.printf("\nstate motor A, %f, state motor B, %f \n\n", A.state(), B.state());
00040     //should be -2 -2.
00041     
00042         for (float s=-1.0; s < 1.0 ; s += 0.01) {//sweep motors in opposite directions
00043         pc.printf("A %f %f \n",A.speed(-s), s);
00044         pc.printf("B %f %f \n\n",B.speed(s), s);
00045         //should follow the output of the for loop
00046         wait(0.02);
00047     }
00048     pc.printf("state motor A, %f, state motor B, %f \n\n", A.state(), B.state());
00049     //should be -1 0.99.
00050     
00051     led3=1;
00052     wait(1);
00053 
00054     pc.printf("motor A, coasting \n");
00055     pc.printf("motor B, coasting \n\n");
00056 
00057     A.coast();
00058     B.coast();
00059     pc.printf("state motor A, %f, state motor B, %f \n end\n end\n", A.state(), B.state());
00060     //should be 2 2.
00061     led4=1;
00062 }