c++ – Arduino Code for Juggling Machine (Stepper Motors)

I have built a machine that juggles. An Arduino sends signals to stepper motor drivers that drive NEMA 23 size stepper motors.

juggling machine

Video of the machine: https://youtu.be/-9zD_8erkck

Currently, each arm makes one revolution and then pauses while the other arm makes one revolution. One arm starts before the other arm comes to a complete stop, the amount of overlap is captured by the variable stepover.

I would like to make the machine more consistent and run quieter with less vibration. How can I make it run smoother? Is there a way to do this where the hands will never come to a complete stop?

The stepper motors are running at 800 steps per revolution. I have tried to using more steps/rev for smoother operation, but the accelstepper library will not run the motors fast enough.

I have tried altering the values max_acceleration, max_speed, and stepover. I have not found a way to optimize these values.

#include <AccelStepper.h>
AccelStepper stepper1(AccelStepper::DRIVER, 9, 8);
AccelStepper stepper2(AccelStepper::DRIVER, 4, 3);

int start = 0;
int side = 0;
int max_speed = 6000;
int max_acceleration = 12000;
int stepover = 300;
int step_distance = 800;

void setup()
{
  stepper1.setMaxSpeed(max_speed);
  stepper2.setMaxSpeed(max_speed);
  stepper1.setAcceleration(1234);
  stepper2.setAcceleration(1234);
  stepper1.moveTo(600);
  stepper2.moveTo(-200);
}

void loop()
{
  // This code gets the arms in the right place before startup
  if (start == 0) {
    while (abs(stepper1.distanceToGo()) != 0) {
      stepper1.run();
    }
    while (abs(stepper2.distanceToGo()) != 0) {
      stepper2.run();
    }
    start = 1;
    stepper1.setAcceleration(max_acceleration);
    stepper2.setAcceleration(max_acceleration);
    delay(500);
  }

  // This code moves the left arm
  if (abs(stepper1.distanceToGo()) == 0
      and abs(stepper2.distanceToGo()) < stepover
      and side == 0) {
    stepper1.moveTo(step_distance + stepper1.currentPosition());
    side = 1;
  }

  // This code moves the right arm
  if (abs(stepper2.distanceToGo()) == 0
      and abs(stepper1.distanceToGo()) < stepover
      and side == 1) {
    stepper2.setCurrentPosition(0);
    stepper2.moveTo(step_distance);
    side = 0;
  }

  if (start == 1) {
    stepper2.run();
    stepper1.run();
  }
}