AccelStepper .stop deaccelerates rather than being a hard stop

The application is setup with

stepper.setMaxSpeed (800); //
stepper.setAcceleration(200); //higher faster

Simple enough . . .

I have a routine to find a limit switch. When the switch is triggered I issue .stop & set the position as 0 (my new home position).

but it is not a hard stop, it decelerates thus traveling past the limit switch which of course makes sense because of the .setAcceleration command.

I want to disable .setAccceleration when hunting for the limit switch. Once my endpoints are set, I can re-enable the .setAcceleration back to normal.

I don't know how to do this.

I have tried stepper.setSpeed in setup and stepper.runSpeed() in loop which works. I get a hard stop.

After that I want to do position movements with .setAcceleration, .moveTo and .run (notrunSpeed!)

I think I am going about this wrong or don't know of the correct function. Cranking up the value for .setAcceleration won't work because it is still not a hard stop.


The thought would be just run your limit hunting with .setSpeed &.runSpeed initially, the use .setAcceleration and .run.

But I want to jump back and forth for re-calibration at anytime.


What's the generally accepted way to find limit position with a hard stop, then jump into positional movements with .setAcceleration?

Does someone have a link to a code example?

When trying to find a limit switch just move the motor one step at a time.

Many systems cruise through the limit switch at some speed, stop and back up enough to pass it and then approach it over a shorter distance one step at a time.

What happens if you do stepper.moveTo( stepper.currentPosition());

But you must keep in mind that an attempt at a sudden stop can cause the motor to miss steps.

...R

ok I will give it a shot.

What happens if you do stepper.moveTo( stepper.currentPosition());

It accelerates.

I cranked the acceleration rate up to 1200 and slowed down the speed. So I have it stopping pretty hard even with acceleration. Not ideal, but it works.

I am running 32 micro step mode and only opening 90 degrees at a pretty slow speed. The current fix seems ok.

Thanks again Robin or the quick reply . .

My 3D printer moves towards the limit at high speed, touches the limit, then backs off and touches it again at a slower speed. Perhaps that would work for you.

DivinerGregg:
I want to disable .setAccceleration when hunting for the limit switch. Once my endpoints are set, I can re-enable the .setAcceleration back to normal.

No, that will miss steps and make for inaccurate/random homing. Its worth studying the various
options and methods EMC2 (aka LinuxCNC) uses for homing - out of the box its highly configurable,
but basically allows for fast, then slow pass, and also can arrange that homing is done in a particular
direction (assumption is the homing sensor is more accurate in one direction).

Emergency stop is another thing - that might be sensible to implement by disabled all calls to run():

boolean emergency_stop = false ;

void loop ()
{
  if (! emergency_stop)
  {
    xmotor.run () ;
    ymotor.run () ;
    zmotor.run () ;
  }
  ....
}