1. Jody McAdams
  2. ArduinoProjects

Commits

Jody McAdams  committed e577bb7

ping servo activated

  • Participants
  • Parent commits 5dc7521
  • Branches default

Comments (0)

Files changed (1)

File Experimental/MicroHorse/MicroHorse.ino

View file
 Animation* lowerLegServoAnimFL;
 Animation* lowerLegServoAnimBR;
 Animation* lowerLegServoAnimBL;
+Animation* pingAnim;
 
-const float overallMovement = 1.0f;
+const float overallMovementR = 1.0f;
+const float overallMovementL = 0.25f;
 
 const float animSpeed = 3.0f;
 
 
 const float rightSideOffset = 3.5f*0.5f;
 
+//Ping
+const Animation::AnimMode pingAnimMode = Animation::AnimMode_PingPong;
+const int pingAnimNumValues = 2;
+Animation::KeyFrame pingAnimValues[pingAnimNumValues] = {{0.0f,0},{3.0f,180}};
+
 const Animation::AnimMode upperLegMode = Animation::AnimMode_Wrap;
 const Animation::AnimMode lowerLegMode = Animation::AnimMode_Wrap;
 
 Servo servoLowerBR;
 Servo servoLowerBL;
 
+Servo servoPingSensor;
+
 float lastTimeMillis = 0.0f;
 void setup() 
 { 
   //Create animations
+  pingAnim = new Animation(pingAnimValues,pingAnimNumValues,pingAnimMode);
   
   //Left legs
   upperLegServoAnimFL = new Animation(upperLegAnimValuesF,numUpperLegAnimValuesF,upperLegMode);
   servoLowerBR.attach(10);
   servoLowerBL.attach(11);
   
+  servoPingSensor.attach(12);
+  
   //Init time
   lastTimeMillis = millis();
 } 
   upperLegServoAnimBL->Update(timeDelta);
   lowerLegServoAnimBL->Update(timeDelta);  
   
+  pingAnim->Update(timeDelta);
+  
   float topFrontRightAnimVal =  upperLegServoAnimFR->CalcAnimVal();
   float topFrontLeftAnimVal = -upperLegServoAnimFL->CalcAnimVal();
   float topBackRightAnimVal =  upperLegServoAnimBR->CalcAnimVal();
   float bottomBackLeftAnimVal = -lowerLegServoAnimBL->CalcAnimVal();
   
    //Right legs
-  topFrontRightAnimVal *= overallMovement;
-  bottomFrontRightAnimVal *= overallMovement;
-  topBackRightAnimVal *= overallMovement;
-  bottomBackRightAnimVal *= overallMovement;
+  topFrontRightAnimVal *= overallMovementR;
+  bottomFrontRightAnimVal *= overallMovementR;
+  topBackRightAnimVal *= overallMovementR;
+  bottomBackRightAnimVal *= overallMovementR;
   
   //Left legs
-  topFrontLeftAnimVal *= overallMovement;
-  bottomFrontLeftAnimVal *= overallMovement;
-  topBackLeftAnimVal *= overallMovement;
-  bottomBackLeftAnimVal *= overallMovement;
+  topFrontLeftAnimVal *= overallMovementL;
+  bottomFrontLeftAnimVal *= overallMovementL;
+  topBackLeftAnimVal *= overallMovementL;
+  bottomBackLeftAnimVal *= overallMovementL;
   
   //Right legs
   topFrontRightAnimVal += 90.0f;
   bottomBackLeftAnimVal += 90.0f;  
   
  #if !DEBUG_RESET
+  servoPingSensor.write(pingAnim->CalcAnimVal()); 
    //Set servo values from animations
   servoUpperFR.write(topFrontRightAnimVal);
   servoLowerFR.write(bottomFrontRightAnimVal);