a

Dependencies:   mbed mbedWSEsbc

Revision:
0:40605c19e1a6
Child:
1:ca98a3ae7a70
diff -r 000000000000 -r 40605c19e1a6 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Nov 06 03:04:52 2017 +0000
@@ -0,0 +1,90 @@
+/* Harrison Kubena and Rav Dhingra
+ES305 Lab 1 - Motor Ticker
+27 August 2017 */
+
+#include "mbed.h"
+#include "mbedWSEsbc.h"
+#define PI (3.14159)
+
+//declare objects
+Ticker Controller; //declare ticker obj
+
+//declare variables
+float TotalTime;
+float Time;
+float Tsamp = 0.0083;
+float Tstream = 0.01;
+float userDC;
+float ang, angp, speed;
+float dc;
+float enc1;
+float lowDC;
+
+void ctrCode();
+void twoStepCode();
+
+//enter main
+int main()  {  
+    //init mbed
+    
+    mbedWSEsbcInit(115200);
+    mot_en1.period(0.020);
+    
+    while(1)    {
+        
+        pc.scanf("%f,%f", &TotalTime, &lowDC);
+        Time = 0.0;
+        t.reset();
+        Controller.attach(&twoStepCode,Tsamp);
+        t.start();
+        
+        //data streaming
+        
+        while(Time <= TotalTime)    {
+            
+            Time = t.read();
+            pc.printf("%f, %f, %f\n", Time, speed, dc);
+            wait(Tstream);
+                                    }
+            Controller.detach();
+            mot_control(1,0.0);
+                }
+            }  
+// additional function definitions
+void ctrCode()  {
+        //read encoder
+        enc1 = LS7366_read_counter(1);
+        //convert counts to rads
+        ang = 2.0*PI*enc1/6400.0;
+        //estimate speed
+        speed = (ang-angp)/Tsamp;
+        //age variables
+        angp = ang;
+        //compute duty cycle
+        dc = userDC;
+        //send the duty cycle to motor
+        mot_control(1,dc); }
+        
+void twoStepCode()  {
+        //read encoder
+        enc1 = LS7366_read_counter(1);
+        //convert counts to rads
+        ang = 2.0*PI*enc1/6400.0;
+        //estimate speed
+        speed = (ang-angp)/Tsamp;
+        //age variables
+        angp = ang;
+        //compute duty cycle
+        if(Time<0.1){
+            dc = 0.0;
+            } else if(Time<0.55){
+            dc = lowDC;
+            } else {
+            dc = 0.10;
+            }   
+        //send the duty cycle to motor
+        mot_control(1,dc); }
+                
+                
+
+        
\ No newline at end of file