I want to move two steppers using a joystick. I'm using the Accel Stepper library, and I am using my own code to poll the joystick (which works well btw).
The problem is that even if I'm setting the motors to run at the maximum speed (200 steps/s), I only get at most 1 steps/s, no matter what I've tried.
EDIT : I haven't wired up the stepper drivers yet (TMC2225), but I'm reading the steps number directly from the library ( stepper.currentPosition() ), for testing purposes. It works fine with the constant speed example.
I've tried to set a very large maximum speed, and specifying a move distance, but the results where the same.
Does anyone have an idea on what I am missing ? Thank you very much for the help.
// Steppers definition
AccelStepper steppers[] = {AccelStepper(AccelStepper::DRIVER, STEPPER_1_STEP_PIN, STEPPER_1_DIR_PIN),
AccelStepper(AccelStepper::DRIVER, STEPPER_2_STEP_PIN, STEPPER_2_DIR_PIN)};
// This function is called at setup()
void initSteppers()
{
for (uint8_t i = 0; i < 2; i++)
{
steppers[i].setEnablePin(STEPPER_EN_PIN);
steppers[i].setMaxSpeed(maxMotorSpeed);
steppers[i].setAcceleration(maxMotorAccel);
}
}
// This one is called when the user is allowed to move the motors
void moveWithJoystick()
{
int currentJoystickValue[2] = {};
int loopCount = 0;
while (!joystickReadButton())
{
// Polling the joystick values every 100~200 ms
if (loopCount >= 10000)
{
for (uint8_t i = 0; i < 2; i++)
{
loopCount = 0;
currentJoystickValue[i] = joystickReadAxis(i, JOYSTICK_MOVE_DEADZONE);
// speed value is between -maxSpeed and maxSpeed
float speed = computeManualSpeed(currentJoystickValue[i]);
steppers[i].setSpeed(speed);
}
}
// Polling the steppers to step.
for (uint8_t i = 0; i < 2; i++)
steppers[i].runSpeed();
loopCount += 1;
}
}
Okay, I finnaly found the problem. My code works fine, but I forgot to initialize the steppers at startup. So their max speed defaulted to 1 step/s, hence the stepping rate.