-1

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;
  }
}
SetKat
  • 1
  • 3

2 Answers2

0

Which type of stepper motor you have used ? The problem may occur from you stepper drive, stepper drive configuration also.

At first manually try to rotate your motor at high speed. If you use micro step, then calculation your step ratio and code it accordingly.

Try to find out your motor's max speed. if you want to add acceleration, deacceleration make those from your code.

Maruf Hossain
  • 101
  • 1
  • 3
  • 17
  • Thank you for your answer. I'm planning on using TMC2225 drivers, with step dir control. At the moment, I haven't powered the drivers yet as I want to make sure all my code bricks work before hardware testing. I'm reading the steps valuers directly from the stepper instance : ```steppers[i].currentPosition();``` I've tried this method on the basic constant speed example, and it works fine, but not with my code. – SetKat Feb 23 '23 at 07:12
  • Ok. Please test with your code and share with us that is works fine. – Maruf Hossain Feb 23 '23 at 08:49
  • Okay, as I was expecting, the problem was between the chair and keyboard... Dumb mistake, I forgot to initialize the setppers at startup, and so that's why they were moving at 1 step/s, which was probably the default max speed. I can't believe I spent 3 days on this, but at least it's fixed. Anyway, thank you for your time and answers, have a nice day ! – SetKat Feb 23 '23 at 17:44
0

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.

SetKat
  • 1
  • 3