Fa2018-es200-3321-proj2-GoodTeam#2 / Mbed 2 deprecated Project_2_Code

Dependencies:   mbed Motor Servo

Committer:
msilver
Date:
Tue Oct 09 15:43:44 2018 +0000
Revision:
2:b4a690fadc9b
Parent:
1:d90f940d6ed2
Child:
3:770e110905d9
Project 2 Code

Who changed what in which revision?

UserRevisionLine numberNew 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 2:b4a690fadc9b 23
msilver 2:b4a690fadc9b 24 /*Hand starts with palm facing in
msilver 2:b4a690fadc9b 25 User puts jar into hand
msilver 0:3c51dfd71129 26 Hits switch that turns servo on to turn the hand to position where palm is facing up
msilver 0:3c51dfd71129 27 Motor drives arm from elbow at 90 degrees up to forehead (hit switch to turn motor off)
msilver 0:3c51dfd71129 28 (I don’t know if this next step will happen as a result of the same switch that turned the motor off or with a different switch)
msilver 2:b4a690fadc9b 29 Random number if the jar will open or not
msilver 2:b4a690fadc9b 30 int a = rand()%1; //Generate random integer 0 or 1
msilver 2:b4a690fadc9b 31 If open -- if (a == 1)
msilver 0:3c51dfd71129 32 When switch is hit to turn motor off? Servo inside jar turns on to break the lid and make pb fall out
msilver 2:b4a690fadc9b 33 Speaker will go off saying “beat Army” - send code through MatLab
msilver 0:3c51dfd71129 34 When user puts contents back in the jar and lid on, hits a switch (when lid goes back on?) that turns the motor on to return the arm to the original position
msilver 0:3c51dfd71129 35 When switch 4 is hit, motor will turn off
msilver 0:3c51dfd71129 36 Servo 1 will turn on (with the same switch that turned motor off if possible) returning the hand to the original position
msilver 2:b4a690fadc9b 37
msilver 2:b4a690fadc9b 38 If stay closed -- if (a == 0)
msilver 0:3c51dfd71129 39 Servo inside pb jar will not turn on
msilver 2:b4a690fadc9b 40 Speaker will say “boo” - send code through MatLab
msilver 0:3c51dfd71129 41 --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 1:d90f940d6ed2 42 */
msilver 2:b4a690fadc9b 43 }