ECE3872 HW/SW Project Code

Dependencies:   mbed Servo mbed-rtos 4DGL-uLCD-SE PinDetect X_NUCLEO_53L0A1

Committer:
trmontgomery
Date:
Mon Apr 13 21:32:00 2020 +0000
Revision:
25:7764baddb7bc
Parent:
18:0e0edd4f9e4d
Child:
26:2063ee8419cc
trying to make a servo move back and forth. tried to use SongPlayer class to control servos.

Who changed what in which revision?

UserRevisionLine numberNew 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 16:62976c3c029e 4
trmontgomery 16:62976c3c029e 5 Servo r_arm(p24);
trmontgomery 16:62976c3c029e 6 Servo l_arm(p23);
trmontgomery 16:62976c3c029e 7 Servo r_leg(p22);
trmontgomery 16:62976c3c029e 8 Servo l_leg(p21);
trmontgomery 16:62976c3c029e 9
trmontgomery 16:62976c3c029e 10 Thread t_r_arm;
trmontgomery 16:62976c3c029e 11 Thread t_l_arm;
trmontgomery 16:62976c3c029e 12 Thread t_r_leg;
trmontgomery 16:62976c3c029e 13 Thread t_l_leg;
trmontgomery 16:62976c3c029e 14
trmontgomery 25:7764baddb7bc 15 DigitalOut led(LED4);
trmontgomery 16:62976c3c029e 16
trmontgomery 25:7764baddb7bc 17 unsigned short move_map1[] = {0x149, 0x14A, 0x14C, 0x151, 0x152, 0x154, 0x291, 0x292, 0x294, 0x2A1, 0x2A2, 0x2A4};
trmontgomery 18:0e0edd4f9e4d 18 unsigned short ra_mask = 0x0C0;
trmontgomery 18:0e0edd4f9e4d 19 unsigned short la_mask = 0x300;
trmontgomery 18:0e0edd4f9e4d 20 unsigned short rl_mask = 0x03C;
trmontgomery 18:0e0edd4f9e4d 21 unsigned short ll_mask = 0x007;
trmontgomery 16:62976c3c029e 22
trmontgomery 25:7764baddb7bc 23 unsigned short move_map[] = {1,2,4,1,2,4,1,2,4,1,2,4,1,2,4,1,2,4};
trmontgomery 16:62976c3c029e 24
trmontgomery 25:7764baddb7bc 25 void ra_dance() {
trmontgomery 25:7764baddb7bc 26 //r_arm = 0;
trmontgomery 25:7764baddb7bc 27 //wait(1);
trmontgomery 25:7764baddb7bc 28 for(int p=0; p<12; ++p) {
trmontgomery 25:7764baddb7bc 29 unsigned short pos = move_map[p];
trmontgomery 25:7764baddb7bc 30 switch(pos){
trmontgomery 25:7764baddb7bc 31 case 1: r_arm.write(1.0);
trmontgomery 25:7764baddb7bc 32 case 2: r_arm.write(0.5);
trmontgomery 25:7764baddb7bc 33 case 4: r_arm.write(1.0);
trmontgomery 25:7764baddb7bc 34 }
trmontgomery 25:7764baddb7bc 35 wait(0.5);
trmontgomery 25:7764baddb7bc 36 r_arm = 0.5;
trmontgomery 16:62976c3c029e 37 }
trmontgomery 16:62976c3c029e 38
trmontgomery 25:7764baddb7bc 39 r_arm = 1;
trmontgomery 25:7764baddb7bc 40 wait(0.5);
trmontgomery 25:7764baddb7bc 41 r_arm = 0.5;
trmontgomery 25:7764baddb7bc 42 wait(0.5);
trmontgomery 25:7764baddb7bc 43 r_arm = 1;
trmontgomery 25:7764baddb7bc 44 r_arm.write(.50);
trmontgomery 25:7764baddb7bc 45 r_arm.write()
trmontgomery 25:7764baddb7bc 46
trmontgomery 16:62976c3c029e 47 }
trmontgomery 16:62976c3c029e 48
trmontgomery 25:7764baddb7bc 49 void la_dance() {
trmontgomery 25:7764baddb7bc 50 l_arm = 0;
trmontgomery 25:7764baddb7bc 51 wait(1);
trmontgomery 25:7764baddb7bc 52 for(float p=0; p<1.0; p += 0.1) {
trmontgomery 25:7764baddb7bc 53 l_arm = p;
trmontgomery 25:7764baddb7bc 54 wait(0.2);
trmontgomery 16:62976c3c029e 55 }
trmontgomery 25:7764baddb7bc 56 l_arm.write(.50);
trmontgomery 25:7764baddb7bc 57
trmontgomery 16:62976c3c029e 58 }
trmontgomery 16:62976c3c029e 59
trmontgomery 25:7764baddb7bc 60 void rl_dance() {
trmontgomery 25:7764baddb7bc 61 r_leg = 0;
trmontgomery 16:62976c3c029e 62 wait(1);
trmontgomery 16:62976c3c029e 63 for(float p=0; p<1.0; p += 0.1) {
trmontgomery 16:62976c3c029e 64 r_leg = p;
trmontgomery 16:62976c3c029e 65 wait(0.2);
trmontgomery 16:62976c3c029e 66 }
trmontgomery 16:62976c3c029e 67 r_leg.write(.50);
trmontgomery 25:7764baddb7bc 68
trmontgomery 16:62976c3c029e 69 }
trmontgomery 16:62976c3c029e 70
trmontgomery 25:7764baddb7bc 71 void ll_dance() {
trmontgomery 25:7764baddb7bc 72 l_leg = 0;
trmontgomery 16:62976c3c029e 73 wait(1);
trmontgomery 16:62976c3c029e 74 for(float p=0; p<1.0; p += 0.1) {
trmontgomery 16:62976c3c029e 75 l_leg = p;
trmontgomery 16:62976c3c029e 76 wait(0.2);
trmontgomery 16:62976c3c029e 77 }
trmontgomery 16:62976c3c029e 78 l_leg.write(.50);
trmontgomery 25:7764baddb7bc 79
trmontgomery 16:62976c3c029e 80 }
trmontgomery 16:62976c3c029e 81
trmontgomery 16:62976c3c029e 82
trmontgomery 25:7764baddb7bc 83 void puppet_move(){
trmontgomery 25:7764baddb7bc 84 //while(1){
trmontgomery 25:7764baddb7bc 85 //t_r_arm.start(ra_dance);
trmontgomery 25:7764baddb7bc 86 //wait(1);
trmontgomery 25:7764baddb7bc 87 //t_l_arm.start(la_dance);
trmontgomery 25:7764baddb7bc 88 //wait(1);
trmontgomery 25:7764baddb7bc 89 //t_r_leg.start(rl_dance);
trmontgomery 25:7764baddb7bc 90 //wait(1);
trmontgomery 25:7764baddb7bc 91 //t_l_leg.start(ll_dance);
trmontgomery 25:7764baddb7bc 92 //wait(1);
trmontgomery 25:7764baddb7bc 93 // }
trmontgomery 25:7764baddb7bc 94 ra_dance();
trmontgomery 16:62976c3c029e 95 }
trmontgomery 16:62976c3c029e 96