Intermediate Level: Multi-Servo Choreography

Intermediate Level: Multi-Servo Choreography

animation
actuators
servo

Goal: Control 3 servos (base, arm, gripper) to perform a pick-and-place sequence.

Challenge: All servos must move simultaneously and arrive at target positions at the same time.

Technique: Linear interpolation across all axes

// Calculate steps needed
int steps = duration / 20;  // 20ms per step (50 Hz servo rate)

// Move all servos proportionally
for (int i = 0; i <= steps; i++) {
  float progress = (float)i / steps;
  baseServo.write(startBase + (targetBase - startBase) * progress);
  armServo.write(startArm + (targetArm - startArm) * progress);
  delay(20);
}

What to observe: All servos start and finish together. Without interpolation, fast-moving axes would finish early, causing jerky motion.

Back to the chapter