when reversing direction, motor steps back few steps in opposite direction, different speeds

236 views
Skip to first unread message

Teackele Soepboer

unread,
Jul 23, 2013, 8:27:09 AM7/23/13
to accels...@googlegroups.com
Hello,

Working on a project with 2 stepper motors.

Setup
-Arduino Mega
-itead driver board (A3967 chips) (http://imall.iteadstudio.com/development-platform/arduino/shields/im120417015.html)
-mercury stepper motors (https://www.sparkfun.com/products/9238), setup at 1/8 steps

Having the following problems
-when stepperY has reached it's position, stepperX willl speed up. is this an arduino performance problem (ie speed calculations eating up processor time?)
-when changing direction at the 10000,2000 point, both stepper will first continue a few steps very slowly in the previous direction. If i remove the setspeeds on direction change, this problem goes away. the code below is just an example to illustrate the problem. in the real project i switch between constant speed (ie calling .runSpeedToPosition) for drwaing and accelerated speed (calling .run) for
positioning


regards Teackele

Below the code to reproduce

#include <AccelStepper.h>

#define  MAX_SPEED     3200  // 2rpm
#define  ACCELERATION  6400  // 6400  ssteps/sec/sec (0.5 sec to topspeed);
#define  SAFE_SPEED    800

AccelStepper stepperX(1,2,3);
AccelStepper stepperY(1,6,7);


void setup() {
  stepperX.setMaxSpeed(MAX_SPEED);
  stepperX.setSpeed(SAFE_SPEED);
  stepperX.setAcceleration(ACCELERATION);

  stepperY.setMaxSpeed(MAX_SPEED);
  stepperY.setSpeed(SAFE_SPEED);
  stepperY.setAcceleration(ACCELERATION);
 
}

void loop() {
 
  if (stepperX.currentPosition() == stepperX.targetPosition() &&
      stepperY.currentPosition() == stepperY.targetPosition()) {
   
    if (stepperX.currentPosition() == 0) {
      stepperX.moveTo(10000);
      stepperX.setSpeed(SAFE_SPEED);
      stepperY.moveTo(2000);
      stepperY.setSpeed(SAFE_SPEED);
    } else {   
      stepperX.moveTo(0);
      stepperX.setSpeed(SAFE_SPEED);
      stepperY.moveTo(0);
      stepperY.setSpeed(SAFE_SPEED);
    }
   }
 
  stepperX.run();
  stepperY.run();
 
}

Aleksei Romanov

unread,
Dec 30, 2021, 12:37:19 PM12/30/21
to accelstepper
Доброе время суток Хотел спросить 
Так понимаю вы используете в режиме скорость транспорта в качестве спидометр
Возможно поделиться скетчем ?
Есть только скетч в качестве тест стрелок немного его переписал. Но так как еще учусь в программирование далее как его дописать не пойму

вторник, 23 июля 2013 г. в 21:27:09 UTC+9, teac...@gmail.com:
sketch_test_strelok.ino

Aleksei Romanov

unread,
Dec 30, 2021, 12:39:52 PM12/30/21
to accelstepper
Драйвер использую А4988 и двигатель vid2905

вторник, 23 июля 2013 г. в 21:27:09 UTC+9, teac...@gmail.com:
Hello,
positioning

Jim Larson

unread,
Jan 6, 2022, 9:15:49 PM1/6/22
to accelstepper
Looking at your example code, I see two problems.
First, when you use run() AccelStepper will accelerate your motor to the maximum speed. Any settig of speed by setSpeed() will be ignored. The maximum number of steps per second for all motors (assuming an Uno or similar) is about 4500 steps per second. The combined speed of your two motors is 6400 steps per second. That's too fast! So AccelStepper does the best it can. When one of the motors stops, the other will now be able to speed up. This is what you are reporting.
Second, When you change direction while the motor are running, AccelStepper will first decelerate to a stop, then start accelerating again in the new direction. Again, exactly what you report.

You may find the following of use:

HTH
     -jim
Reply all
Reply to author
Forward
0 new messages