Jody McAdams avatar Jody McAdams committed 5b0bda5

fix ping sensor anim

Comments (0)

Files changed (1)

Experimental/MicroHorse/MicroHorse.ino

 #include <MathUtil.h>
 #include <Animation.h>
 
+Servo servoPingSensor;
+int ultraSoundSignal = 3; // Ultrasound signal pin
+
 #define DEBUG_RESET 0
-
+ 
+const float updateAnimSPF = 1.0f/60.0f;
+  
 Animation* upperLegServoAnimFR;
 Animation* upperLegServoAnimFL;
 Animation* upperLegServoAnimBR;
 const float overallMovementR = 1.0f;
 const float overallMovementL = 1.0f;
 
-const float animSpeed = 4.0f;
+const float animSpeed = 1.5f;
 
 const float backLegOffset = 0.8f;
 
 //Ping
 const Animation::AnimMode pingAnimMode = Animation::AnimMode_PingPong;
 const int pingAnimNumValues = 2;
-Animation::KeyFrame pingAnimValues[pingAnimNumValues] = {{0.0f,0},{3.0f,180}};
+Animation::KeyFrame pingAnimValues[pingAnimNumValues] = {{0.0f,-90},{2.0f,90}};
 
 const Animation::AnimMode upperLegMode = Animation::AnimMode_Wrap;
 const Animation::AnimMode lowerLegMode = Animation::AnimMode_Wrap;
 
 //Front
 const int numUpperLegAnimValuesF = 4;
-Animation::KeyFrame upperLegAnimValuesF[numUpperLegAnimValuesF] = {{0.0f,20},{1.0f,-80},{2.1f,-20},{3.5f,20}};
+Animation::KeyFrame upperLegAnimValuesF[numUpperLegAnimValuesF] = {{0.0f,20},{1.0f,-60},{2.1f,-20},{3.5f,20}};
 
 //Back
 const int numUpperLegAnimValuesB = 4;
 
 //Front
 const int numLowerLegAnimValuesF = 5;
-Animation::KeyFrame lowerLegAnimValuesF[numLowerLegAnimValuesF] = {{0.0f,-5},{0.9f,90},{1.25f,-40},{2.0f,0},{3.5f,-5}};
+Animation::KeyFrame lowerLegAnimValuesF[numLowerLegAnimValuesF] = {{0.0f,-5},{0.9f,90},{1.25f,-20},{2.0f,0},{3.5f,-5}};
 
 
 //Back
 const int numLowerLegAnimValuesB = 5;
-Animation::KeyFrame lowerLegAnimValuesB[numLowerLegAnimValuesB] = {{0.0f,15},{0.6f,90},{1.7f,-40},{2.0f,0},{3.5f,15}};
+Animation::KeyFrame lowerLegAnimValuesB[numLowerLegAnimValuesB] = {{0.0f,15},{0.6f,90},{1.7f,-20},{2.0f,0},{3.5f,15}};
 
 
 Servo servoUpperFR;
 Servo servoLowerBR;
 Servo servoLowerBL;
 
-Servo servoPingSensor;
-int ultraSoundSignal = 3; // Ultrasound signal pin
-
 enum PingState
 {
   PingState_Idle,
   lastTimeMillis = currTimeMillis;
   
   pingUpdateTimer -= timeDelta;
-  
-  if(timeDelta < 0.0f)
+  if(pingUpdateTimer < 0.0f)
   {
-    timeDelta += 1.0f;
+    pingUpdateTimer += 1.0f;
     
     updatePing(timeDelta);
   }
   
   animUpdateTimer -= timeDelta;
-  
   if(animUpdateTimer < 0.0f)
   {
-    animUpdateTimer += 1.0f/60.0f;
+    animUpdateTimer += updateAnimSPF;
     
-    UpdateAnims(1.0f/60.0f);
+    UpdateAnims(updateAnimSPF);
   }
 } 
 
   lowerLegServoAnimBL->Update(timeDelta);  
   
   pingAnim->Update(timeDelta);
+  float pingAnimVal = pingAnim->CalcAnimVal();
+  pingAnimVal += 90.0f;
   
   float topFrontRightAnimVal =  upperLegServoAnimFR->CalcAnimVal();
   float topFrontLeftAnimVal = -upperLegServoAnimFL->CalcAnimVal();
   bottomBackLeftAnimVal += 90.0f;  
   
  #if !DEBUG_RESET
-  servoPingSensor.write(pingAnim->CalcAnimVal()); 
+  servoPingSensor.write(pingAnimVal); 
    //Set servo values from animations
   servoUpperFR.write(topFrontRightAnimVal);
   servoLowerFR.write(bottomFrontRightAnimVal);
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.