Pseudo Code
Dependencies: mbed Motor Servo
main.cpp@3:770e110905d9, 2018-10-16 (annotated)
- Committer:
- msilver
- Date:
- Tue Oct 16 14:46:15 2018 +0000
- Revision:
- 3:770e110905d9
- Parent:
- 2:b4a690fadc9b
- Child:
- 4:8079e89199ff
m
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 | 2:b4a690fadc9b | 11 | Servo servo_1(p#);//rotates hand between palm facing up and palm facing in |
msilver | 2:b4a690fadc9b | 12 | Servo servo_2(p#); //inside jar to burst pb out |
msilver | 2:b4a690fadc9b | 13 | Motor motor(p#, p#, p#); // drive arm from 90 degrees to forehead |
msilver | 2:b4a690fadc9b | 14 | DigitalIn switch_1(p#); //in palm (when pb jar is put in the hand, hits the switch to activate the servo on the hand) |
msilver | 2:b4a690fadc9b | 15 | DigitalIn switch_2(p#); //on forehead (turn motor off) |
msilver | 2:b4a690fadc9b | 16 | DigitalIn switch_3(p#); //on lid? (when you put the contents back in the jar it signals arm to start moving back down to starting position?) |
msilver | 2:b4a690fadc9b | 17 | DigitalIn switch_4(p#); //on (desk?) to signal the motor to stop when arm reaches starting position |
msilver | 1:d90f940d6ed2 | 18 | |
msilver | 1:d90f940d6ed2 | 19 | int main() { |
msilver | 2:b4a690fadc9b | 20 | |
msilver | 2:b4a690fadc9b | 21 | 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 | 2:b4a690fadc9b | 22 | servo_2.calibrate(0.0009, 45.0); //Calibrates the servo_2 timing by setting the pulse width and range of motion (45*2 = 90 degrees) |
msilver | 3:770e110905d9 | 23 | servo_1.write(0.5); //Or what ever number sets the servo in the initial position |
msilver | 2:b4a690fadc9b | 24 | |
msilver | 2:b4a690fadc9b | 25 | /*Hand starts with palm facing in |
msilver | 2:b4a690fadc9b | 26 | User puts jar into hand |
msilver | 3:770e110905d9 | 27 | Hits switch (wait a set time before turning servo on) that turns servo on to turn the hand to position where palm is facing up |
msilver | 3:770e110905d9 | 28 | if (switch_1.read() == 1) { |
msilver | 3:770e110905d9 | 29 | wait (...); |
msilver | 3:770e110905d9 | 30 | servo_1.write(1.0); //or whatever number sets the servo to the "palm up" position |
msilver | 3:770e110905d9 | 31 | wait (...); |
msilver | 3:770e110905d9 | 32 | motor.speed(...);} |
msilver | 3:770e110905d9 | 33 | |
msilver | 0:3c51dfd71129 | 34 | Motor drives arm from elbow at 90 degrees up to forehead (hit switch to turn motor off) |
msilver | 3:770e110905d9 | 35 | if (switch_2.read() == 1) { |
msilver | 3:770e110905d9 | 36 | motor.speed(0); |
msilver | 3:770e110905d9 | 37 | int a = rand()%1; //Generate random integer 0 or 1 to determine if the jar will open or not} |
msilver | 3:770e110905d9 | 38 | |
msilver | 3:770e110905d9 | 39 | if (a == 1) { |
msilver | 3:770e110905d9 | 40 | servo_2.write(1.0); //Servo inside jar turns on to break the lid and make pb fall out |
msilver | 3:770e110905d9 | 41 | |
msilver | 3:770e110905d9 | 42 | pc.printf("1\n"); // send signal to Matlab to play sound |
msilver | 3:770e110905d9 | 43 | wait(10.0); // wait for Matlab to finish playing the sound |
msilver | 3:770e110905d9 | 44 | |
msilver | 2:b4a690fadc9b | 45 | Speaker will go off saying “beat Army” - send code through MatLab |
msilver | 3:770e110905d9 | 46 | if (switch_3.read() == 1) //When user puts contents back in the jar and lid on, hits a switch (when lid goes back on?) |
msilver | 3:770e110905d9 | 47 | { motor.speed(-...); //turns the motor on to return the arm to the original position |
msilver | 2:b4a690fadc9b | 48 | |
msilver | 3:770e110905d9 | 49 | } |
msilver | 3:770e110905d9 | 50 | else if (a == 0) |
msilver | 3:770e110905d9 | 51 | { |
msilver | 0:3c51dfd71129 | 52 | Servo inside pb jar will not turn on |
msilver | 2:b4a690fadc9b | 53 | Speaker will say “boo” - send code through MatLab |
msilver | 3:770e110905d9 | 54 | } |
msilver | 0:3c51dfd71129 | 55 | --switch will not be hit when lid goes back (since it never came off) so will the user have to manually move the arm back to the starting position? Will they press the button on the lid so the motor turns on? |
msilver | 3:770e110905d9 | 56 | |
msilver | 3:770e110905d9 | 57 | if (switch_4.read() == 1)// When switch 4 is hit { |
msilver | 3:770e110905d9 | 58 | motor.speed(0); // motor will turn off |
msilver | 3:770e110905d9 | 59 | servo_1.write(...) //Servo 1 will turn on returning the hand to the original position |
msilver | 3:770e110905d9 | 60 | } |
msilver | 1:d90f940d6ed2 | 61 | */ |
msilver | 2:b4a690fadc9b | 62 | } |