/* Quadraped gait file Right turn */ #include // Define servo objects for the four ankle joints Servo ankleFL; Servo ankleFR; Servo ankleBL; Servo ankleBR; // Define servo objects for the four hip joints Servo hipFL; Servo hipFR; Servo hipBL; Servo hipBR; // Define variables int flex1 = 45; // Angle for intial placement of limbs int flexLeft = 45; // Length of left stride int flexRight = 15; // Make right stride one half or one third of left stride to turn right int multiplier = 3; // Make multiplier 2 if right is one half of left // stride and make multiplier 3 if right is one third int delayTime = 500; // Delay between limb movements int startPause = 5000; // Delay to allow robot placement before movement int pos = 0; // Loop counter int smoothnessDelay = 15; void setup() { hipFL.attach(10); ankleFL.attach(11); hipFR.attach(4); ankleFR.attach(5); hipBL.attach(6); ankleBL.attach(7); hipBR.attach(8); ankleBR.attach(9); // Put legs in starting position with // front left and back right legs in forward position and // front right and back left legs in rearward position hipFL.write(90-flexLeft); ankleFL.write(90-flexLeft); hipFR.write(90+flexRight); ankleFR.write(90+flexRight); hipBL.write(90+flexLeft); ankleBL.write(90+flexLeft); hipBR.write(90-flexRight); ankleBR.write(90-flexRight); delay(startPause); } void loop() { // Straighten front left and back right legs // I use one loop to keep the limbs sychronized // Note the right limb must travel twice as far // as the left limb during a left turn, thus the // factor of 2*pos for the right limb loop counter delay(delayTime); for(pos = 0; pos < flexRight; pos += 1) { hipFL.write(90-flexLeft+multiplier*pos); ankleFL.write(90-flexLeft+multiplier*pos); hipBR.write(90-flexRight+pos); ankleBR.write(90-flexRight+pos); delay(smoothnessDelay); } // Bring front right and back left legs forward in three steps // First flex ankles forward delay(delayTime); ankleFR.write(180); ankleBL.write(180); // Second, swing the front right and back left legs forward delay(delayTime); hipFR.write(90-flexRight); hipBL.write(90-flexLeft); // Third, reset front right and back left ankles delay(delayTime); ankleFR.write(90-flexRight); ankleBL.write(90-flexLeft); // Bring front left and back right legs rearward delay(delayTime); for(pos = 0; pos < flexRight; pos += 1) { hipFL.write(90+multiplier*pos); ankleFL.write(90+multiplier*pos); hipBR.write(90+pos); ankleBR.write(90+pos); delay(smoothnessDelay); } // Straighten front right and back left legs delay(delayTime); for(pos = 0; pos < flexRight; pos += 1) { hipFR.write(90-flexRight+pos); ankleFR.write(90-flexRight+pos); hipBL.write(90-flexLeft+multiplier*pos); ankleBL.write(90-flexLeft+multiplier*pos); delay(smoothnessDelay); } // Bring front left and back right legs forward in three steps // First flex ankles forward delay(delayTime); // ankleFL.write(180); hipFL.write(180); ankleBR.write(180); // Second, swing the front left and back right legs forward delay(delayTime); // hipFL.write(90-flex1); ankleFL.write(90-flexLeft); hipBR.write(90-flexRight); // Third, reset front left and back right ankles delay(delayTime); // ankleFL.write(90-flex1); hipFL.write(90-flexLeft); ankleBR.write(90-flexRight); // Bring front right and back left legs rearward delay(delayTime); for(pos = 0; pos < flexRight ; pos += 1) { hipFR.write(90+pos); ankleFR.write(90+pos); hipBL.write(90+multiplier*pos); ankleBL.write(90+multiplier*pos); delay(smoothnessDelay); } }