Pseudo Code
Dependencies: mbed Motor Servo
main.cpp@4:8079e89199ff, 2018-10-22 (annotated)
- Committer:
- msilver
- Date:
- Mon Oct 22 14:06:02 2018 +0000
- Revision:
- 4:8079e89199ff
- Parent:
- 3:770e110905d9
Project 2 Code 22OCT
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
msilver | 1:d90f940d6ed2 | 1 | /*Project 2 – Mechatronics – MIDN Dietrich, Schwind, Silver*/ |
msilver | 0:3c51dfd71129 | 2 | |
msilver | 1:d90f940d6ed2 | 3 | //Libraries |
msilver | 1:d90f940d6ed2 | 4 | #include "mbed.h" |
msilver | 1:d90f940d6ed2 | 5 | #include "stdio.h" |
msilver | 1:d90f940d6ed2 | 6 | #include "stdlib.h" |
msilver | 2:b4a690fadc9b | 7 | #include "Motor.h" |
msilver | 2:b4a690fadc9b | 8 | #include "Servo.h" |
msilver | 1:d90f940d6ed2 | 9 | |
msilver | 2:b4a690fadc9b | 10 | //Declare servos, motors, and switches |
msilver | 4:8079e89199ff | 11 | Servo servo_1(p24);//rotates hand between palm facing up and palm facing in |
msilver | 4:8079e89199ff | 12 | Servo servo_2(p21); //on jar to rotate it in hand |
msilver | 4:8079e89199ff | 13 | Motor motor(p29, p30, p26); // drive arm from 90 degrees to forehead |
msilver | 4:8079e89199ff | 14 | //DigitalIn switch_1(p#); //on protoboard - hit to start |
msilver | 4:8079e89199ff | 15 | DigitalIn switch_2(p18); //on "hand" - hits forehead to turn motor off |
msilver | 4:8079e89199ff | 16 | //DigitalIn switch_3(p#); //on protoboard - returns arm to start position |
msilver | 4:8079e89199ff | 17 | DigitalIn switch_4(p20); //on "hand" - hits desk when going down to turn motor off |
msilver | 1:d90f940d6ed2 | 18 | |
msilver | 1:d90f940d6ed2 | 19 | int main() { |
msilver | 4:8079e89199ff | 20 | servo_1.calibrate(0.0009, 45.0); //Calibrates the servo_1 timing by setting the pulse width and range of motion (45*2 = 90 degrees) |
msilver | 4:8079e89199ff | 21 | servo_2.calibrate(0.0009, 90.0); //Calibrates the servo_2 timing by setting the pulse width and range of motion (45*2 = 90 degrees) |
msilver | 2:b4a690fadc9b | 22 | |
msilver | 4:8079e89199ff | 23 | while(!switch_1) |
msilver | 4:8079e89199ff | 24 | servo_1.write(.25); //Sets the servo in the initial position - palm facing in |
msilver | 4:8079e89199ff | 25 | servo_2.write(0); //Sets the servo in the initial position - Does not matter where |
msilver | 2:b4a690fadc9b | 26 | |
msilver | 4:8079e89199ff | 27 | if (switch_1.read() == 1) //User hits switch 1 (button on protoboard) |
msilver | 4:8079e89199ff | 28 | { |
msilver | 4:8079e89199ff | 29 | int i=0; //declare i as an integer and initialize it to 0 |
msilver | 4:8079e89199ff | 30 | for (i=0; i<=10; i++) //rotate the pb jar for a cycle of 10 counts |
msilver | 4:8079e89199ff | 31 | { servo_2.write(0.0); //initial position |
msilver | 4:8079e89199ff | 32 | servo_2.write(1.0); //final position |
msilver | 4:8079e89199ff | 33 | } |
msilver | 4:8079e89199ff | 34 | servo_1.write(.75); //turn the hand to the "palm up" position |
msilver | 4:8079e89199ff | 35 | wait (2); //wait for hand to get into "palm up" position |
msilver | 4:8079e89199ff | 36 | motor.speed(.7); //turn motor on to drive arm up |
msilver | 3:770e110905d9 | 37 | |
msilver | 4:8079e89199ff | 38 | if (switch_2.read() == 2) //when switch hits forehead |
msilver | 4:8079e89199ff | 39 | {motor.speed(0); //turn motor off |
msilver | 4:8079e89199ff | 40 | int a = rand()%1;} //Generate random integer 0 or 1 to determine if the jar will open or not - what sound will play and if jar opens |
msilver | 3:770e110905d9 | 41 | |
msilver | 3:770e110905d9 | 42 | if (a == 1) { |
msilver | 4:8079e89199ff | 43 | servo_1.write(...); //Servo on wrist turns to allow pb to come out |
msilver | 4:8079e89199ff | 44 | pc.printf("1\n"); // send signal to Matlab to play Beat Army sound |
msilver | 4:8079e89199ff | 45 | wait(10.0); // wait for Matlab to finish playing the sound NATHAN'S CODE??? |
msilver | 3:770e110905d9 | 46 | |
msilver | 3:770e110905d9 | 47 | else if (a == 0) |
msilver | 3:770e110905d9 | 48 | { |
msilver | 4:8079e89199ff | 49 | pc.printf("2\n"); // send signal to Matlab to play boo sound |
msilver | 4:8079e89199ff | 50 | wait(10.0); // wait for Matlab to finish playing the sound NATHAN'S CODE??? |
msilver | 4:8079e89199ff | 51 | } |
msilver | 3:770e110905d9 | 52 | |
msilver | 4:8079e89199ff | 53 | if (switch_3.read() == 1) //When user is ready to return arm to start position, hits switch_3 on protoboard |
msilver | 4:8079e89199ff | 54 | { motor.speed(-.5); //turns the motor on to return the arm to the original position |
msilver | 4:8079e89199ff | 55 | } |
msilver | 4:8079e89199ff | 56 | |
msilver | 4:8079e89199ff | 57 | if (switch_4.read() == 1)// When switch 4 is hit |
msilver | 3:770e110905d9 | 58 | motor.speed(0); // motor will turn off |
msilver | 4:8079e89199ff | 59 | wait(1); //wait 1 second for arm to level out |
msilver | 4:8079e89199ff | 60 | servo_1.write(.25) //Servo 1 will turn on returning the hand to the original "palm in" position |
msilver | 3:770e110905d9 | 61 | } |
msilver | 4:8079e89199ff | 62 | */ |