0

I'm using the FlexyStepper library. Unfortunately there's no way to open an issue on GitHub so I'm going to ask my question here.

I think there's a bug in the calculations. In my application (it's not a CNC, just a rotary axis used for theatrical effects) I may need to change the target even if the current target has not reached yet.

This is supported by the library, there's also an example. I modified this example and created this small sketch to simulate the problem:

#include <FlexyStepper.h>

const int MOTOR_STEP_PIN = PE13;
const int MOTOR_DIRECTION_PIN = PE14;

#define TARGET_HIGH 2000
#define TARGET_LOW  0

FlexyStepper stepper;
unsigned long previousMillis = 0;
unsigned long target = TARGET_LOW;
int cycles = 100;

void setup() 
{
  Serial.begin(115200);
  stepper.connectToPins(MOTOR_STEP_PIN, MOTOR_DIRECTION_PIN);
  stepper.setSpeedInStepsPerSecond(5000);
  stepper.setAccelerationInStepsPerSecondPerSecond(1000);
  stepper.setCurrentPositionInSteps(0);
  delay(5000);
}

void loop() 
{
  unsigned long currentMillis = millis();
  
  if (currentMillis - previousMillis > 1000)
  {
    previousMillis = currentMillis;

    if (cycles)
    {
      if (target == TARGET_LOW) target = TARGET_HIGH;
      else target = TARGET_LOW;

      stepper.setTargetPositionInSteps(target);
      cycles--;
    }
    else
    {
      stepper.setTargetPositionInSteps(0);
    }
  }
  stepper.processMovement();
}

At first, it remains still at position 0 for few seconds so you can take a note where it is. Then, every seconds it changes its target between TARGET_LOW and TARGET_HIGH. Of course it cannot reach them because the new target comes before the current has reached. At the end, it returns to 0.

I expected the motor oscillates between the two points in a symmetrical way (because acceleration and deceleration are the same). Instead it moves randomly but the most important thing is the final 0 is very different than the initial one.

Initial position Final position

I'm using professional stepper and drivers (23SM080-028-8W-F10-1.7-CE and MSD-50-5.6-D). I'm not new to stepper motors and I'm sure I'm not loosing steps. I set the current slightly over the nominal one to test it. And the speed/acceleration settings are very small for such a motor.

Any idea why it seems to do the wrong math?

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.