Patrick Clary / Mbed 2 deprecated WalkingRobot

Dependencies:   CircularBuffer Servo Terminal mbed Radio

Revision:
11:9ee0214bd410
Parent:
10:dc1ba352667e
Child:
12:a952bd74d363
diff -r dc1ba352667e -r 9ee0214bd410 RobotLeg.cpp
--- a/RobotLeg.cpp	Tue Apr 09 01:36:50 2013 +0000
+++ b/RobotLeg.cpp	Wed May 15 17:22:22 2013 +0000
@@ -129,8 +129,8 @@
 bool RobotLeg::update(const matrix4& deltaTransform)
 {
     float t, d;
-    vector3 newPosition, newNDeltaPosition, v;
-    const float eps = 0.000001f;
+    vector3 newNDeltaPosition, v;
+    const float eps = 0.00001f;
 
     switch (state)
     {
@@ -140,19 +140,16 @@
         newNDeltaPosition = position - newPosition;
         if (fabs(newNDeltaPosition.x) > eps || fabs(newNDeltaPosition.y) > eps || fabs(newNDeltaPosition.z) > eps)
             nDeltaPosition = newNDeltaPosition;
-        position = newPosition;
         
         // Check if new position is outside the step circle
-        v = position - circleCenter;
+        v = newPosition - circleCenter;
         d = sqrt(v.x*v.x + v.y*v.y);
         
         // Attempt to move to the new position
-        if (!move(position) || d > circleRadius) return false;
-        
-        break;
+        return d < circleRadius;
         
     case stepping:
-    // Compute new position along step trajectory
+        // Compute new position along step trajectory
         t = stepTimer.read();
         newPosition.x = stepA.x + (stepB.x - stepA.x)*0.5f*(1 - cos(stepDelta*t));
         newPosition.y = stepA.y + (stepB.y - stepA.y)*0.5f*(1 - cos(stepDelta*t));
@@ -169,8 +166,27 @@
             stepTimer.stop();
             position = getPosition();
         }
-        break;
+        
+        return true;
     }
     
-    return true;
-}
\ No newline at end of file
+    return false;
+}
+
+
+
+void RobotLeg::apply()
+{
+    if (neutral == state)
+    {
+        position = newPosition;
+        move(position);
+    }
+}
+
+
+
+bool RobotLeg::getStepping()
+{
+    return stepping == state;
+}