Go Down

Topic: Nonblocking Library for driving servos and steppers with variable speed (Read 128 times) previous topic - next topic

MicroBahner

I am a model railroader and developed a library that may be useful for other model railroaders or modell-makers too.

I did it with these requirements in mind:
Drive servo's
I know there are lots of libs, that can do that and there is even a lib included in the IDE.
But I did'n find any lib, that can control the speed of the servo ( if someone knows one, let me know ). When you do a write on the servo with my lib, it moves slowly to the destination and - even better - the sketch runs on. It is'nt blocked. You can even use a delay() in your sketch while the servo is moving. The methods are widely compatible to the standard lib ( with some extensions ).

Drive steppers
It's the same: the methods are not blocking. Even while a delay() is active the motor runs on.
You can set a reference-point. If this is done, the motor can be positioned absolutely just like a servo, but without a angle-limitation ( ok, not quite true, there is a limitation of +/-2.147.483.684 steps. If this is overrun it looses the reference point ;-) )
Because the steps are created by interrupts, the maximum step frequency is limited ( about 2kHz ).

Drive leds,
Ok, that should be a simple task where you don't need a lib. But with my lib, you can switch it on/off softly to simulate a light bulb. I used that e.g. for light signals. And this works on all digital outputs, not only on PWM capable ones.

Everything ( servo's, steppers and leds ) can be used simultaneously. All functions share timer 1 of the arduino.

If someone is interested, you can have a look at the manual. Or download the lib here

Robin2

The Arduino IDE includes a servo sweep example that illustrates how to manage the speed.

And the AccelStepper library is commonly used for the non-blocking control of stepper motors.

The use of the delay() function is rarely a good thing.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

MicroBahner

The Arduino IDE includes a servo sweep example that illustrates how to manage the speed.
But you have to do it in the sketch. In the meantime by browsing this forum I found another lib which can do it.

And the AccelStepper library is commonly used for the non-blocking control of stepper motors.
Yes I know that there are more sophisticated stepper libs, but I found it difficult or even impossible to combine servo and stepper libs because mostly they use the same timer. Or they have a method that has to be called in the loop frequently, which may be difficult in big sketches.


There are always many alternatives - so forget it  - my lib is nothing more than another - may be superfluous - alternative with its pros and cons  ;)

P.S.
The use of the delay() function is rarely a good thing.
Thats true, but its widely used  :D

Isaac96

Haha. One problem with delay() is that it is ignored in interrupt loops, as I discovered to my loss. :(
Do not PM me for help. I will delete immediately.
CONNECT THE GROUNDS!

After Tuesday, even the calendar goes W T F

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy