afdfdf

Dependencies:   mbed weelio

Revision:
22:5e7356dc1d71
Parent:
21:b0e9b4d19d4d
--- a/main.cpp	Sat Nov 23 00:55:46 2019 +0000
+++ b/main.cpp	Wed Nov 27 19:23:04 2019 +0000
@@ -42,17 +42,28 @@
 #include <iostream>
 #include <cmath>
 
-const float MAX_SPEED = 0.0014f;
-const float MIN_SPEED = 0.1f;
+const float MAX_SPEED = 0.0003f;
+const float MIN_SPEED = 0.024095f;
+//const float MIN_SPEED = 0.5f;
+
+
+const float MAX_DEGREES = 10.0f;
+const float MIN_DEGREES = 0.0f;
 
-const float MAX_DEGREES = 5.0f;
-const float MIN_DEGREES = 0.0f;
+
+
+float clamp(float degrees)
+{
+    if(degrees < MIN_DEGREES) return MIN_DEGREES;
+    else if (degrees >= MAX_DEGREES) return MAX_DEGREES;
+    else return degrees;
+}
 
 
 
 float degrees_to_period(float degrees)
 {
-    return (((MAX_SPEED - MIN_SPEED)/(MAX_DEGREES)) * std::abs(degrees) + MIN_SPEED);
+    return (((MAX_SPEED - MIN_SPEED)/(MAX_DEGREES)) * clamp(std::abs(degrees)) + MIN_SPEED);
 }
 
 
@@ -122,13 +133,14 @@
 
     M1_dir = 1;
     M2_dir = 0;
-    
+
     M1_step = 0.5f;
     M2_step = 0.5f;
 
     float angle;
     float period;
-
+    
+    float test = 1.05f;
 
     for(;;) {
         vec3 = get_accel();
@@ -145,10 +157,16 @@
             M1_dir = 1;
             M2_dir = 0;
         }
+        
 
         //Control stepper motor.
-        out.printf("%f %f\r\n", period, angle);
+        out.printf("%f %f %f\r\n", period, angle, degrees_to_period(MAX_DEGREES/test));
+        //if(angle < 2.0f || angle > -2.0f)
         M1_step.period(period);
         M2_step.period(period);
+        //M1_step.period(0.0003);
+        //M2_step.period(0.0003);
+        //M1_step.period(degrees_to_period(MAX_DEGREES/test));
+        //M2_step.period(degrees_to_period(MAX_DEGREES/test));        
     }
 }
\ No newline at end of file