accelStepper: how to set starting speed, then accelerate

Hello All,

I am working on a test setup to determine the max pump rate of piston dispense pumps that use a NEMA 17 stepper motor. Therefore, I am trying to move the piston back and forth as fast as I can. I am using an Uno, and a Pololu stepper motor driver.

The pump motor has the following specifications:
Max speed: 4000 half steps/sec
Max acceleration: 10000 half steps/sec^2
Max starting velocity: 1000 half steps/sec

I have successfully run the pump in the past using the following method (simplified):

void setup() {
// code to set micro stepping mode to 1/2 step
stepper.setMaxSpeed(4000);
stepper.setAcceleration(10000);
}

void loop() {
stepper.move(6000); // # of half steps for single dispense
stepper.runToPosition();
delay(30); // time delay for valve switching
stepper.move(-6000); // # of half steps for singe aspirate
stepper.runToPosition();
delay(30)
}

This allows me to cycle the pump and achieve ~46.6 mL/min. I would like to take advantage of the fact that the motor is able to instantaneously start at a speed of 1000 half steps/sec and then accelerate up to 4000 half steps/sec. By my calculation, if I am able to start at a speed of 1000, my max dispense rate will increase to ~51.3 mL/min. Achieving this dispense rate would be very valuable for my project.

Is there any way to achieve a starting speed of 1000 half steps/sec using the accelStepper library and then begin accelerating at 10000 half steps/sec^2 from there?

I have looked around the forum and can seem to find an example of this. I am open to "creative" ideas as long as the speed of the pump is not affected.

Please let me know if I can provide further information.

Thanks!

AccelStepper library is open-source, you can create your own version if you can figure out how to extend it.
As it is it definitely doesn't support this (it would fail on big stepper motors).

I wonder what would happen if you use stepper.runSpeed() to set the starting speed and then switch to stepper.run() for the acceleration. Just a wild thought - I have never tried it.

It is not very difficult to write your own acceleration code - see this Simple acceleration code.

...R

runSpeed() doesn't set the speed, setSpeed() does that. This might work, actually.

Try

  setSpeed(...) ;
  moveTo (...) ;

I never use setSpeed because it will make a normal stepper stall due to the lack of speed ramping. Note that
the argument to setSpeed is a signed value, this matters!

MarkT:
runSpeed() doesn't set the speed, setSpeed() does that.

Yes, but after setSpeed() you need to use runSpeed() to make it move.

I was surmising that if the OP calls runSpeed() repeatedly for a few seconds to establish the starting speed it may have the effect he wants if she then changes to calling run() to get the benefit of the acceleration

...R

MarkT and Robin2,

Thank you very much for the suggestions! I will try using stepper.runSpeed() then calling stepper.run() afterwards to take advantage of the acceleration.

If this does not work, I can try to code my own acceleration. Robin2, thanks for the link to your acceleration code! I've never tried something like that. I may give it a shot if I can't get something else to work.

In a previous project, I wrote a homing routine that "jolted" the motor on with no acceleration ramp. Abbreviated code below:

for (x = 1; x < 1000; x++) { // Backs off 500 pulses, or 125 full steps
        digitalWrite(stp, HIGH);
        delayMicroseconds(125); // Approx 4000pps at 1/4 stepping (5 RPS)
        digitalWrite(stp, LOW);
        delayMicroseconds(125);
        }

Perhaps I can start the speed using a similar for loop to the above and then call stepper.runToPosition to begin accelerating. Otherwise, I may have to try to write my own acceleration code.

Once again thanks for the suggestions!