ECE3872 HW/SW Project Code
Dependencies: mbed Servo mbed-rtos 4DGL-uLCD-SE PinDetect X_NUCLEO_53L0A1
motor_ctl.h@26:2063ee8419cc, 2020-04-14 (annotated)
- Committer:
- trmontgomery
- Date:
- Tue Apr 14 01:40:26 2020 +0000
- Revision:
- 26:2063ee8419cc
- Parent:
- 25:7764baddb7bc
map of distinct movements is playable. can record and play music at the same time.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
trmontgomery | 16:62976c3c029e | 1 | #include "mbed.h" |
trmontgomery | 16:62976c3c029e | 2 | #include "Servo.h" |
trmontgomery | 18:0e0edd4f9e4d | 3 | #include "rtos.h" |
trmontgomery | 26:2063ee8419cc | 4 | #include <string> |
trmontgomery | 16:62976c3c029e | 5 | |
trmontgomery | 16:62976c3c029e | 6 | Servo r_arm(p24); |
trmontgomery | 16:62976c3c029e | 7 | Servo l_arm(p23); |
trmontgomery | 16:62976c3c029e | 8 | Servo r_leg(p22); |
trmontgomery | 16:62976c3c029e | 9 | Servo l_leg(p21); |
trmontgomery | 16:62976c3c029e | 10 | |
trmontgomery | 16:62976c3c029e | 11 | Thread t_r_arm; |
trmontgomery | 16:62976c3c029e | 12 | Thread t_l_arm; |
trmontgomery | 16:62976c3c029e | 13 | Thread t_r_leg; |
trmontgomery | 16:62976c3c029e | 14 | Thread t_l_leg; |
trmontgomery | 16:62976c3c029e | 15 | |
trmontgomery | 26:2063ee8419cc | 16 | #define DUR 200 |
trmontgomery | 26:2063ee8419cc | 17 | |
trmontgomery | 26:2063ee8419cc | 18 | vector<string> move_map; //initialized in main |
trmontgomery | 26:2063ee8419cc | 19 | string note; |
trmontgomery | 16:62976c3c029e | 20 | |
trmontgomery | 26:2063ee8419cc | 21 | void la_dance() { |
trmontgomery | 26:2063ee8419cc | 22 | switch(note[0]){ |
trmontgomery | 26:2063ee8419cc | 23 | case 0: l_arm.write(1.0); break; |
trmontgomery | 26:2063ee8419cc | 24 | case 1: l_arm.write(0.0); break; |
trmontgomery | 26:2063ee8419cc | 25 | } |
trmontgomery | 26:2063ee8419cc | 26 | Thread::wait(DUR); |
trmontgomery | 26:2063ee8419cc | 27 | } |
trmontgomery | 16:62976c3c029e | 28 | |
trmontgomery | 25:7764baddb7bc | 29 | void ra_dance() { |
trmontgomery | 26:2063ee8419cc | 30 | switch(note[1]){ |
trmontgomery | 26:2063ee8419cc | 31 | case '0': r_arm.write(1.0); break; |
trmontgomery | 26:2063ee8419cc | 32 | case '1': r_arm.write(0.0); break; |
trmontgomery | 16:62976c3c029e | 33 | } |
trmontgomery | 26:2063ee8419cc | 34 | Thread::wait(DUR); |
trmontgomery | 16:62976c3c029e | 35 | } |
trmontgomery | 16:62976c3c029e | 36 | |
trmontgomery | 26:2063ee8419cc | 37 | void ll_dance() { |
trmontgomery | 26:2063ee8419cc | 38 | switch(note[2]){ |
trmontgomery | 26:2063ee8419cc | 39 | case 1: r_leg.write(1.0); break; |
trmontgomery | 26:2063ee8419cc | 40 | case 2: r_leg.write(0.6); break; |
trmontgomery | 26:2063ee8419cc | 41 | case 3: r_leg.write(0.1); break; |
trmontgomery | 16:62976c3c029e | 42 | } |
trmontgomery | 26:2063ee8419cc | 43 | Thread::wait(DUR); |
trmontgomery | 16:62976c3c029e | 44 | } |
trmontgomery | 16:62976c3c029e | 45 | |
trmontgomery | 25:7764baddb7bc | 46 | void rl_dance() { |
trmontgomery | 26:2063ee8419cc | 47 | switch(note[3]){ |
trmontgomery | 26:2063ee8419cc | 48 | case 1: l_leg.write(1.0); break; |
trmontgomery | 26:2063ee8419cc | 49 | case 2: l_leg.write(0.6); break; |
trmontgomery | 26:2063ee8419cc | 50 | case 3: l_leg.write(0.1); break; |
trmontgomery | 16:62976c3c029e | 51 | } |
trmontgomery | 26:2063ee8419cc | 52 | Thread::wait(DUR); |
trmontgomery | 16:62976c3c029e | 53 | } |
trmontgomery | 16:62976c3c029e | 54 | |
trmontgomery | 26:2063ee8419cc | 55 | void puppet_move(){ |
trmontgomery | 26:2063ee8419cc | 56 | t_r_arm.start(ra_dance); |
trmontgomery | 26:2063ee8419cc | 57 | t_l_arm.start(la_dance); |
trmontgomery | 26:2063ee8419cc | 58 | t_r_leg.start(rl_dance); |
trmontgomery | 26:2063ee8419cc | 59 | t_l_leg.start(ll_dance); |
trmontgomery | 16:62976c3c029e | 60 | } |
trmontgomery | 16:62976c3c029e | 61 |