Acceleration problem.

804 views
Skip to first unread message

quin...@gmail.com

unread,
Apr 27, 2014, 5:19:07 PM4/27/14
to accels...@googlegroups.com
Hello, I hesitated a long time before you write, but I can not find the solution to my problem.
I enclose the copy of your library Arduino program.
You have a very good library, work fine, thank you.

// MultiStepper.pde
// -*- mode: C++ -*-
//
// Shows how to multiple simultaneous steppers
// Runs one stepper forwards and backwards, accelerating and decelerating
// at the limits. Runs other steppers at the same time
//
// Copyright (C) 2009 Mike McCauley
// $Id: MultiStepper.pde,v 1.1 2011/01/05 01:51:01 mikem Exp mikem $

#include <AccelStepper.h>

// Define some steppers and the pins the will use
AccelStepper stepper1(1,2,3);// step pin = 2 dir pin = 3 :
AccelStepper stepper2(1,6,7);// step pin = 2 dir pin = 3 :

void setup()

    stepper1.setMaxSpeed(3200);
    stepper1.setAcceleration(1600);
    stepper1.moveTo(3200);
   
    stepper2.setMaxSpeed(1600);
    stepper2.setAcceleration(800);
    stepper2.moveTo(1600);
   

}

void loop()
{

    stepper1.run();
    stepper2.run();
 
}


This works fine, the two engines are running for 1 second at different speeds and even acceleration.
But when I change the speed I do not know how to set the acceleration for the two motors run for 1 second.
Is there a mathematical formula to apply?
Thank you for your help.
Greetings.

Mike McCauley

unread,
Apr 27, 2014, 9:01:12 PM4/27/14
to accels...@googlegroups.com
Hello,

it is not normal to change the accelertion at run time (although you can).

Usually you will choose a maximum accelertion your machanical system can
handle and set it once in the setup().

Then you just change the target position occasionally and call run() as often
as possible.

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

quin...@gmail.com

unread,
Apr 28, 2014, 4:46:07 AM4/28/14
to accels...@googlegroups.com

Hello, thank you for your quick response.
Good day.
Greetings.

jimc

unread,
May 3, 2014, 11:57:24 AM5/3/14
to accels...@googlegroups.com
Mike,

it is not normal to change the accelertion at run time (although you can).

Usually you will choose a maximum accelertion your machanical system can
handle and set it once in the setup().

Then you just change the target position occasionally and call run() as often
as possible. 

Thanks for making your library available. Last night I replaced calls to the Arduino Stepper library to yours for the extra control, but I have a few comments, the first related to your reply above.
1. My stepper is moving a slider, and while I want modest acceleration (best torque at low speed), I want rapid deceleration if I hit the limit switches as I have just 1.4 turns of travel from the limit switch to the end of the slider. In that case, I do change acceleration at run time.
2. I like to use LEDs as visual indicators of logic - moving up, moving down, flashing at the limits - but these involve blocking delays for flashing (I may try another timer library for that). And the delays interfere will calling your run() function to service the stepper motor. As an alternative, I put in code to call run() from an interrupt service routine (ISR) that is called every 0.1ms when timer 3 overflows, and it seems to work but I wondered about any consequences. Global variables modified in the ISR should be declared as volatile but I don't see how to do that with the stepper object, and perhaps its not even necessary. I would be interested in your comments, or from anyone else.
3. Acceleration is not particularly smooth until I set the interrupts to 0.1 ms intervals. Even at 1ms acceleration is in big steps.
4. I have 2 speeds - normal for regular but infrequent position changes (usually a turn or 2, up or down), and fast for returning (up) to the end of the slide travel. A switch is read by the Arduino to go from one speed to the other. Going from slow to fast engages the acceleration, but going back is immediate with no deceleration. I think this is because the speed is changes with setMaxSpeed() and the library doesn't decelerate to a lower max speed value - is that correct?

Again, thanks.

Mike McCauley

unread,
May 3, 2014, 6:14:47 PM5/3/14
to accels...@googlegroups.com
Hello,

maybe you dont need accceleration at all?
Calling run() from within an ISR is prob dangerous.
Suggest you get a differtn way to handle your LEDS that dont block.

Cheers.

jimc

unread,
May 4, 2014, 5:28:38 PM5/4/14
to accels...@googlegroups.com
Mike,

Thanks for your responses. I have to say that fooling around with the Arduino and making it do something useful is too much fun. The project is to scan electron micrographs (film) automatically with a hobby robot arm loading and unloading an optical microscope stage. This is one of 2 Arduinos (Arduini?) and it manages the discard pile that currently gets jammed using a passive drop-into-a-box system.

maybe you dont need accceleration at all?

Perhaps not, but I expect it is less strain on the motor than commanding it to go immediately from 0 to the final speed, which is impossible to do when loaded. (The motor is driving a slider - 1mm/turn - to move up to 3.5 kg).

Calling run() from within an ISR is prob dangerous.

I expect so, and yet so far its working beautifully. Calling run() or runSpeed() off an ISR function is very easy and serves the stepper motor timing well, leaving me free to worry about other things! I am not very experienced in C++ (but certainly in C, and from some time back in micro-controllers and assembly) but I wonder if I can modify your library code for this application and declare any variables modified by the run() function as volatile. I doubt run() makes any memory calls or does anything disallowed in ISR's.
 
Suggest you get a differtn way to handle your LEDS that dont block.

I agree. Just in the first draft of the code, so I will look at that in the next round of modifications, probably think about a timed event queue to be serviced in the same ISR as the run() function.

James Conway
Reply all
Reply to author
Forward
0 new messages