DE refactored as state machine

Dependencies:   Motor Servo

Files at this revision

API Documentation at this revision

Comitter:
evangeli
Date:
Mon Oct 22 14:34:09 2018 +0000
Commit message:
DE helped refactor code as state machine

Changed in this revision

.gitignore Show annotated file Show diff for this revision Revisions of this file
Motor.lib Show annotated file Show diff for this revision Revisions of this file
README.md Show annotated file Show diff for this revision Revisions of this file
Servo.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-os.lib Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/.gitignore	Mon Oct 22 14:34:09 2018 +0000
@@ -0,0 +1,4 @@
+.build
+.mbed
+projectfiles
+*.py*
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Motor.lib	Mon Oct 22 14:34:09 2018 +0000
@@ -0,0 +1,1 @@
+http://os.mbed.com/teams/Fa2018-es200-3321-proj2-GoodTeam2/code/Motor/#57154dd179bb
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/README.md	Mon Oct 22 14:34:09 2018 +0000
@@ -0,0 +1,57 @@
+# Getting started with Blinky on mbed OS
+
+This guide reviews the steps required to get Blinky working on an mbed OS platform.
+
+Please install [mbed CLI](https://github.com/ARMmbed/mbed-cli#installing-mbed-cli).
+
+## Import the example application
+
+From the command-line, import the example:
+
+```
+mbed import mbed-os-example-blinky
+cd mbed-os-example-blinky
+```
+
+### Now compile
+
+Invoke `mbed compile`, and specify the name of your platform and your favorite toolchain (`GCC_ARM`, `ARM`, `IAR`). For example, for the ARM Compiler 5:
+
+```
+mbed compile -m K64F -t ARM
+```
+
+Your PC may take a few minutes to compile your code. At the end, you see the following result:
+
+```
+[snip]
++----------------------------+-------+-------+------+
+| Module                     | .text | .data | .bss |
++----------------------------+-------+-------+------+
+| Misc                       | 13939 |    24 | 1372 |
+| core/hal                   | 16993 |    96 |  296 |
+| core/rtos                  |  7384 |    92 | 4204 |
+| features/FEATURE_IPV4      |    80 |     0 |  176 |
+| frameworks/greentea-client |  1830 |    60 |   44 |
+| frameworks/utest           |  2392 |   512 |  292 |
+| Subtotals                  | 42618 |   784 | 6384 |
++----------------------------+-------+-------+------+
+Allocated Heap: unknown
+Allocated Stack: unknown
+Total Static RAM memory (data + bss): 7168 bytes
+Total RAM memory (data + bss + heap + stack): 7168 bytes
+Total Flash memory (text + data + misc): 43402 bytes
+Image: .\.build\K64F\ARM\mbed-os-example-blinky.bin
+```
+
+### Program your board
+
+1. Connect your mbed device to the computer over USB.
+1. Copy the binary file to the mbed device.
+1. Press the reset button to start the program.
+
+The LED on your platform turns on and off.
+
+## Troubleshooting
+
+If you have problems, you can review the [documentation](https://os.mbed.com/docs/latest/tutorials/debugging.html) for suggestions on what could be wrong and how to fix it.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Servo.lib	Mon Oct 22 14:34:09 2018 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/simon/code/Servo/#36b69a7ced07
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Oct 22 14:34:09 2018 +0000
@@ -0,0 +1,119 @@
+/*
+ES200 3321 Project 2 
+MIDN 3/C Dietrich, Schwind, Silver
+*/
+
+#include "mbed.h"
+#include "rtos.h"
+#include "stdlib.h"
+#include "Motor.h"
+#include "Servo.h"
+
+// global hardware objects
+Serial pc(USBTX,USBRX); 
+
+Servo servo_1(p24);//rotates hand between palm facing up and palm facing in
+Servo servo_2(p21); //on jar to rotate it in hand
+Motor motor(p29, p30, p26); // drive arm from 90 degrees to forehead
+DigitalIn switch_1(p17); //on protoboard - hit to start 
+DigitalIn switch_2(p18); //on "hand" - hits forehead to turn motor off
+DigitalIn switch_3(p12); //on protoboard - returns arm to start position
+DigitalIn switch_4(p10); //on "hand" - hits desk when going down to turn motor off
+
+
+
+int main() {
+    // setup
+    pc.printf("ES200 3321 Team Peanut Butter Beat Army\r\n");
+    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)
+    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)
+    
+    // state machines start here
+    while(1){
+        
+        // idle state
+        do {
+            pc.printf("main() in idle state, awaiting sw1\r\n");
+            servo_1.write(0.25); //Sets the servo in the initial position - palm facing in
+            servo_2.write(0.0); //Sets the servo in the initial position - Does not matter where
+            ThisThread::sleep_for(200); 
+        } while (!switch_1.read());
+            
+        // peanut butter rotation 
+        pc.printf("main() in peanut butter rotation state LATER\r\n");
+        
+        
+        // palm up state
+        pc.printf("main() going to palm up state\r\n");
+        servo_1.write(.75); //turn the hand to the "palm up" position
+        ThisThread::sleep_for(2000);           //wait for hand to get into "palm up" position
+        
+        // smash state
+        pc.printf("main() smash PB against head state\r\n");
+        motor.speed(0.7);    //turn motor on to drive arm up
+        while (!switch_2.read()){
+            pc.printf("main() awaiting palm switch 2 to finish PB head smash\r\n");
+            ThisThread::sleep_for(100); 
+            }
+        motor.speed(0.0); 
+            
+        // play sound
+        pc.printf("main() in play sound state LATER\r\n");
+        while (!switch_3.read()){
+              pc.printf("main() awaiting switch_3 to recycle\r\n");
+              ThisThread::sleep_for(200); 
+              }; 
+              
+        // lower arm
+        pc.printf("main() lowering arm\r\n"); 
+        motor.speed(-0.5); //turns the motor on to return the arm to the original position      
+        while (!switch_4.read()) {
+            pc.printf("main() awaiting switch_4 during recycle\r\n"); 
+            ThisThread::sleep_for(200);
+        } 
+        motor.speed(0.0); // motor will turn off
+        ThisThread::sleep_for(1000);        //wait 1 second for arm to level out
+        
+        // palm to side
+        pc.printf("main() palm to side position\r\n");
+        servo_1.write(0.25); //Servo 1 will turn on returning the hand to the original "palm in" position
+                
+        pc.printf("main() returning to idle state\r\n");
+        } // while(1)
+} // main()
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+if (switch_1.read() == 1) //User hits switch 1 (button on protoboard)
+{
+
+
+
+/*
+{motor.speed(0);   //turn motor off
+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
+
+if (a == 1) {
+    servo_1.write(...); //Servo on wrist turns to allow pb to come out
+    pc.printf("1\n"); // send signal to Matlab to play Beat Army sound
+    wait(10.0); // wait for Matlab to finish playing the sound NATHAN'S CODE???
+      
+else if (a == 0)
+{
+    pc.printf("2\n"); // send signal to Matlab to play boo sound
+    wait(10.0); // wait for Matlab to finish playing the sound NATHAN'S CODE???
+}
+*/
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-os.lib	Mon Oct 22 14:34:09 2018 +0000
@@ -0,0 +1,1 @@
+https://github.com/ARMmbed/mbed-os/#e1bea44212b8275f7d8ce7253e758c2e25c57482