Program for testing motion boards (double motor controller)
Program to test motion boards (double motor controller).
The mbed board reads from a joystick and then sends the commands to the motor board (l293d), which lets the small caterpillar go ahead, go back and turn.
main.cpp@0:5307ae36f268, 2014-06-14 (annotated)
- Committer:
- mariob
- Date:
- Sat Jun 14 21:56:12 2014 +0000
- Revision:
- 0:5307ae36f268
example to test motion boards
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| mariob | 0:5307ae36f268 | 1 | #include "mbed.h" |
| mariob | 0:5307ae36f268 | 2 | #include "dc_motor.hpp" |
| mariob | 0:5307ae36f268 | 3 | |
| mariob | 0:5307ae36f268 | 4 | int main () |
| mariob | 0:5307ae36f268 | 5 | { |
| mariob | 0:5307ae36f268 | 6 | AnalogIn vert(p20); |
| mariob | 0:5307ae36f268 | 7 | AnalogIn horz(p19); |
| mariob | 0:5307ae36f268 | 8 | DC_motor m_sx(p21, p22); |
| mariob | 0:5307ae36f268 | 9 | DC_motor m_dx(p23, p24); |
| mariob | 0:5307ae36f268 | 10 | |
| mariob | 0:5307ae36f268 | 11 | while(1) { |
| mariob | 0:5307ae36f268 | 12 | wait(0.2); |
| mariob | 0:5307ae36f268 | 13 | float v = vert.read(); |
| mariob | 0:5307ae36f268 | 14 | float h = horz.read(); |
| mariob | 0:5307ae36f268 | 15 | float speed_sx = (v-0.5)*2.0; |
| mariob | 0:5307ae36f268 | 16 | if (h>0.5) |
| mariob | 0:5307ae36f268 | 17 | speed_sx *= (1.0-(h-0.5)*2.0); |
| mariob | 0:5307ae36f268 | 18 | float speed_dx = (v-0.5)*2.0; |
| mariob | 0:5307ae36f268 | 19 | if (h<0.5) |
| mariob | 0:5307ae36f268 | 20 | speed_dx *= ((h+0.5)*2.0-1.0); |
| mariob | 0:5307ae36f268 | 21 | m_sx.speed(speed_sx); |
| mariob | 0:5307ae36f268 | 22 | m_dx.speed(speed_dx); |
| mariob | 0:5307ae36f268 | 23 | // printf("VERT(%f), HORZ(%f), sx(%f), dx(%f)\n\r", |
| mariob | 0:5307ae36f268 | 24 | // vert.read(), horz.read(), speed_sx, speed_dx); |
| mariob | 0:5307ae36f268 | 25 | } |
| mariob | 0:5307ae36f268 | 26 | } |
Mario Bambagini