test script for motordriver. correct results are in the comments.
Dependencies: mbed Motordriver
main.cpp@0:751b3c43eaf5, 2010-11-25 (annotated)
- Committer:
- littlexc
- Date:
- Thu Nov 25 14:53:28 2010 +0000
- Revision:
- 0:751b3c43eaf5
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
littlexc | 0:751b3c43eaf5 | 1 | #include <mbed.h> |
littlexc | 0:751b3c43eaf5 | 2 | #include <motordriver.h> |
littlexc | 0:751b3c43eaf5 | 3 | //pc interface |
littlexc | 0:751b3c43eaf5 | 4 | Serial pc(USBTX, USBRX); // tx, rx |
littlexc | 0:751b3c43eaf5 | 5 | //declare motors |
littlexc | 0:751b3c43eaf5 | 6 | Motor A(p22, p6, p5, 1); // pwm, fwd, rev, can break |
littlexc | 0:751b3c43eaf5 | 7 | Motor B(p21, p7, p8, 1); // pwm, fwd, rev, can break |
littlexc | 0:751b3c43eaf5 | 8 | //debugging stuff, switches a new led on after each sqeuence. |
littlexc | 0:751b3c43eaf5 | 9 | DigitalOut led1 (LED1); |
littlexc | 0:751b3c43eaf5 | 10 | DigitalOut led2 (LED2); |
littlexc | 0:751b3c43eaf5 | 11 | DigitalOut led3 (LED3); |
littlexc | 0:751b3c43eaf5 | 12 | DigitalOut led4 (LED4); |
littlexc | 0:751b3c43eaf5 | 13 | |
littlexc | 0:751b3c43eaf5 | 14 | int main() { |
littlexc | 0:751b3c43eaf5 | 15 | pc.printf("motor A, reverse to foward \n"); |
littlexc | 0:751b3c43eaf5 | 16 | pc.printf("motor B, reverse to foward \n\n"); |
littlexc | 0:751b3c43eaf5 | 17 | |
littlexc | 0:751b3c43eaf5 | 18 | pc.printf("state motor A, %f, state motor B, %f \n\n", A.state(), B.state()); |
littlexc | 0:751b3c43eaf5 | 19 | //should be 2. |
littlexc | 0:751b3c43eaf5 | 20 | led1=1; |
littlexc | 0:751b3c43eaf5 | 21 | |
littlexc | 0:751b3c43eaf5 | 22 | for (float s=-1.0; s < 1.0 ; s += 0.01) {//sweep from reverse to foward |
littlexc | 0:751b3c43eaf5 | 23 | pc.printf("A %f %f \n",A.speed(s), s); |
littlexc | 0:751b3c43eaf5 | 24 | pc.printf("B %f %f \n\n",B.speed(s), s); |
littlexc | 0:751b3c43eaf5 | 25 | //should follow the output of the for loop |
littlexc | 0:751b3c43eaf5 | 26 | wait(0.02); |
littlexc | 0:751b3c43eaf5 | 27 | } |
littlexc | 0:751b3c43eaf5 | 28 | pc.printf("state motor A, %f, state motor B, %f \n\n", A.state(), B.state()); |
littlexc | 0:751b3c43eaf5 | 29 | //should be 0.99 0.99. |
littlexc | 0:751b3c43eaf5 | 30 | |
littlexc | 0:751b3c43eaf5 | 31 | led2=1; |
littlexc | 0:751b3c43eaf5 | 32 | |
littlexc | 0:751b3c43eaf5 | 33 | pc.printf("\nmotor A, braking \n"); |
littlexc | 0:751b3c43eaf5 | 34 | pc.printf("motor B, braking \n\n"); |
littlexc | 0:751b3c43eaf5 | 35 | |
littlexc | 0:751b3c43eaf5 | 36 | pc.printf("A %f 0.5 \n",A.stop(0.5)); |
littlexc | 0:751b3c43eaf5 | 37 | pc.printf("B %f 0.5 \n",B.stop(0.5)); |
littlexc | 0:751b3c43eaf5 | 38 | |
littlexc | 0:751b3c43eaf5 | 39 | pc.printf("\nstate motor A, %f, state motor B, %f \n\n", A.state(), B.state()); |
littlexc | 0:751b3c43eaf5 | 40 | //should be -2 -2. |
littlexc | 0:751b3c43eaf5 | 41 | |
littlexc | 0:751b3c43eaf5 | 42 | for (float s=-1.0; s < 1.0 ; s += 0.01) {//sweep motors in opposite directions |
littlexc | 0:751b3c43eaf5 | 43 | pc.printf("A %f %f \n",A.speed(-s), s); |
littlexc | 0:751b3c43eaf5 | 44 | pc.printf("B %f %f \n\n",B.speed(s), s); |
littlexc | 0:751b3c43eaf5 | 45 | //should follow the output of the for loop |
littlexc | 0:751b3c43eaf5 | 46 | wait(0.02); |
littlexc | 0:751b3c43eaf5 | 47 | } |
littlexc | 0:751b3c43eaf5 | 48 | pc.printf("state motor A, %f, state motor B, %f \n\n", A.state(), B.state()); |
littlexc | 0:751b3c43eaf5 | 49 | //should be -1 0.99. |
littlexc | 0:751b3c43eaf5 | 50 | |
littlexc | 0:751b3c43eaf5 | 51 | led3=1; |
littlexc | 0:751b3c43eaf5 | 52 | wait(1); |
littlexc | 0:751b3c43eaf5 | 53 | |
littlexc | 0:751b3c43eaf5 | 54 | pc.printf("motor A, coasting \n"); |
littlexc | 0:751b3c43eaf5 | 55 | pc.printf("motor B, coasting \n\n"); |
littlexc | 0:751b3c43eaf5 | 56 | |
littlexc | 0:751b3c43eaf5 | 57 | A.coast(); |
littlexc | 0:751b3c43eaf5 | 58 | B.coast(); |
littlexc | 0:751b3c43eaf5 | 59 | pc.printf("state motor A, %f, state motor B, %f \n end\n end\n", A.state(), B.state()); |
littlexc | 0:751b3c43eaf5 | 60 | //should be 2 2. |
littlexc | 0:751b3c43eaf5 | 61 | led4=1; |
littlexc | 0:751b3c43eaf5 | 62 | } |