Perplexing stepper movement

75 views
Skip to first unread message

jimmyv...@gmail.com

unread,
Aug 14, 2021, 4:22:43 PM8/14/21
to accelstepper
I have a couple steppers being controlled with Accelstepper that I got assistance with a couple years ago and I'm trying to understand why certain functions work and some don't.

The question I have has to pertain to the move() and moveTo() commands and why it works one way with some steppers and not others. In the first if statement for the carriage.move() I move the stepper until my Hall sensor goes High and stops movement.

Further down I call carriage.move(200) to make the stepper move back to a start position but unlike the first carriage.move() I have to use 200 steps to make it move, anything less and the stepper moves in the wrong direction for some reason.

The if statement for the gantry.move(1) works as coded and stops at the Hall sensor but then to move it back I have to use gantry.moveTo(-1) or it doesn't move.

Any help is appreciated.


  if (buttonstate == HIGH && gantryhome == HIGH && start == 1) {

    gantry.move(1);                                 //move to sensor for stapling
    gantry.setSpeed(1000);
  }


  if (buttonstate == HIGH && carriagehome == HIGH && start == 1) {

    carriage.move(-1);                         //move to sensor for stapling
    carriage.setSpeed(1000);
  }

  if (buttonstate == HIGH && staplercurrentState == LOW && staplercounter >=1 && start == 1) {
    roserotate.move(steps);
    roserotate.setSpeed(800);
  }

  if (buttonstate == HIGH && gantryhome == LOW && start == 1) {
    stapler.setSpeed(-8000);
  }

  ///////////////////////////////////////////////////////////////////////////////

  if (staplercounter >= staples && gantryfinish == HIGH && start == 1) {          //Slide gantry back to start position

    stapler.setSpeed(0);                      //turn stapler motor off

    gantry.moveTo(-1);
    gantry.setSpeed(1000);
  }
  if (staplercounter >= staples && carriagefinish == HIGH && start == 1) {          //Slide carriage back to start position

    carriage.move(200);
    carriage.setSpeed(800);
  }

Mike McCauley

unread,
Aug 14, 2021, 5:14:52 PM8/14/21
to accels...@googlegroups.com
Hello,

I think the problem you are seeing is because you are mixing acelereation and
non-acceleration functions.

You should not be calling setSpeed if you want accelerations: it overrides the
speed and movement direction calculations made by move() and moveTo().
You probably instead want to call setMaxSpeed() if you want to chnage the
maximumum speed of movement.

Cheers.
--
Mike McCauley VK4AMM mi...@airspayce.com
Airspayce Pty Ltd 9 Bulbul Place Currumbin Waters QLD 4223 Australia
http://www.airspayce.com 5R3MRFM2+X6
Phone +61 7 5598-7474



gjgsm...@gmail.com

unread,
Aug 14, 2021, 9:17:54 PM8/14/21
to accelstepper
Further to Mike's post...

This may or may not be relevant, so please forgive me if I am 'preaching to the choir'!

FWIW, the following is my attempt to explain the use of the move() and moveTo() functions:

stepperX.moveTo(200); // '(200)' is your desired 'Target Positioin'.
stepperx.run();

// To move back to the 'start' position
stepperX.moveTo(0); // '(0)' is now your 'Target Positioin'.
stepperx.run(); // '(0)' is the stepper Current Position on 'boot' or 'reset', ie the 'start' position.

// If you were to...

stepperX.move(-200);        // This will also move the stepper CCW 200 steps back to the 'start', (0) position.
// But if you do this instead...
stepperX.move(100); // This will move the stepper CW 100 steps further from the Start Position.

TIP.
stepperX.moveTo(0); // This will always move the stepper Start (0) position from any current position.
stepperx.run();

Recap.
stepperX.moveTo(); Uses 'Targets'. 
All targets positions within a 360deg rotation are always fixed unless reset by setCurrentPosition(); or a reboot/reset.
stepperX.move();   Uses 'steps' only, not targets.

jimmyv...@gmail.com

unread,
Aug 14, 2021, 10:10:26 PM8/14/21
to accelstepper
I had a lot of help from someone in this group writing this code so understanding what the code is doing is still a bit over my head.
In the setup() I call acceleration and max speed so the stepper will move as fast as it can right away(knowing that if I did it on gradual acceleration it would move faster but it is only moving a short distance).
I call this in the setup
  gantry.setMaxSpeed(1500.0);
  gantry.setAcceleration(1000.0);
  carriage.setMaxSpeed(10000.0);
  carriage.setAcceleration(15000.0);

I'm moving the steppers between hall sensors so I just use a single step and check if it needs another step until sensor goes high. I tried using runSpeed() but it wouldn't stop at the sensor. 

I home the carriage.move() in the setup() using a while statement and runSpeed() and it stops at the sensor but doesn't seem to work the same in the loop().

Any idea why the second move from the carriage.move() needs 200 steps to make it move the correct direction?

jimmyv...@gmail.com

unread,
Aug 14, 2021, 10:18:58 PM8/14/21
to accelstepper
That helps to spell it out like that, I kind of understood it when I read the class definitions. 

When I decided to use hall sensors to control movement I thought just making the steppers run with the run() function would work for me but it didn't want to stop at the sensors so I changed it to the move() function and it seemed to work the way I wanted it too.

jimmyv...@gmail.com

unread,
Aug 15, 2021, 12:14:44 PM8/15/21
to accelstepper
After thinking about it awhile I really don't need the move() calls do I?

I can just tell the motors to run and have the hall sensors stop them.

 if (buttonstate == HIGH && gantryhome == HIGH && start == 1) {

    gantry.setSpeed(1000);
  }

  if (buttonstate == HIGH && carriagehome == HIGH && start == 1) {

    carriage.setSpeed(1000);
  }

  if (buttonstate == HIGH && staplercurrentState == LOW && staplercounter >=1 && start == 1) {
    roserotate.move(steps);
    roserotate.setSpeed(800);
  }

  if (buttonstate == HIGH && gantryhome == LOW && start == 1) {
    stapler.setSpeed(-8000);
  }

  ///////////////////////////////////////////////////////////////////////////////

  if (staplercounter >= staples && gantryfinish == HIGH && start == 1) {          //Slide gantry back to start position

    stapler.setSpeed(0);                      //turn stapler motor off

    gantry.setSpeed(-1000);
  }
  if (staplercounter >= staples && carriagefinish == HIGH && start == 1) {          //Slide carriage back to start position

    carriage.setSpeed(-800);
  }
gantry.runSpeed();
carriage.runSpeed();
roserotate.runSpeedToPosition();
Reply all
Reply to author
Forward
0 new messages