Drew Moore / Mbed 2 deprecated ElevatorLabP2Logic

Dependencies:   Motor mbed

Files at this revision

API Documentation at this revision

Comitter:
TheDoctor822
Date:
Mon May 02 19:06:13 2016 +0000
Commit message:
Logic Control

Changed in this revision

Motor.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.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r c102c15cb7ad Motor.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Motor.lib	Mon May 02 19:06:13 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/simon/code/Motor/#f265e441bcd9
diff -r 000000000000 -r c102c15cb7ad main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon May 02 19:06:13 2016 +0000
@@ -0,0 +1,71 @@
+#include "mbed.h"
+#include "Motor.h"
+
+Serial pc(USBTX,USBRX);
+
+AnalogIn sensor(p19); //PINNUMBER);
+Motor motor(p26, p30, p29);  //change pins
+
+int trigger;  // trigger variable for while loop
+int loop;
+float stop;
+float usrHeight;
+float sensorVolts;
+float height;
+float dc;
+float realSpeed;
+float heightErr;
+float coeff1;
+float coeff2;
+float coeff3;
+float coeff4;
+
+int main()
+{
+    loop = 1;
+    trigger = 1;
+    realSpeed = 0.0;
+    //find good pwm value for going up (.45)
+    //going down(-.45)
+    //stopping(0)
+    pc.baud(115200);
+    motor.speed(0);
+
+while(1) {
+    
+    trigger = 1;
+    pc.scanf("%d,%f", &trigger, &usrHeight);
+
+    wait(2.0);
+    
+    
+    coeff1 = 355.519794247593;
+    coeff2 = -502.781241203052;
+    coeff3 = 251.402617938315;
+    coeff4 = -23.6439180749985;
+
+        while( trigger==1) {
+            
+            //motor.speed(motorPWM);
+            sensorVolts = sensor.read();
+            height = coeff1*(sensorVolts * sensorVolts * sensorVolts) + coeff2*(sensorVolts * sensorVolts) + coeff3*(sensorVolts) + coeff4;
+            pc.printf("%f\n",height);
+            heightErr = usrHeight - height;
+            //pc.printf("Input Height: %f\n", usrHeight);
+            //pc.printf("Height: %f\n", height);
+            //pc.printf("Error: %f\n", heightErr);
+            if (heightErr > 0.5){
+               realSpeed = 0.6;
+               motor.speed(realSpeed);
+               }
+            if (heightErr < -0.5){
+                realSpeed = -0.6;
+               motor.speed(realSpeed);
+                }
+            //pc.printf("%d, %f, %f\n",loop, height, realSpeed);
+            pc.printf("%f\n", realSpeed);
+            wait(0.1);   
+        }
+    } //need to send over loop, measured height, duty cycle value
+    
+}
\ No newline at end of file
diff -r 000000000000 -r c102c15cb7ad mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Mon May 02 19:06:13 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/082adc85693f
\ No newline at end of file