Quick Guidance on Multi-Tasking Project

Hi,

Since it appears to be my first post i'd like to get across that i already spent several weeks reading this forum :slight_smile: great source and great people!

Now:
I have a project in mind and am currently stuck giving me the reason to ask for a quick guidance here.

The idea isn't mindblowingly difficult to describe: 1 Arduino, 5 Steppers that loop to infinity and 1 Solenoid or Servo. Goal is a drawing machine (several videos on youtube - however the uploaders do not seem to be very helpful).
All Steppers should be able to loop their sequence (made of different combinations of start, stop, reverse, pause, accelerate, decelerate, random) and proceed to do so simultaneously.

Now i have come so far, that two steppers do their job rotating in different looped sequences (for now not including de- and accelerations). Only issue, they don't do it simultaneously but proceed their task one after another.

I did read into this and came across multi-tasking. However the material reached from the ServeralThingsAtOnce-StickyPost in this forum to several different RTOS's to conquer this issue.

What is the next step i should look into regarding my problem? Is the ServeralThingAtOnce applicable to this problem or does it really need to have a RTOS?
*btw. FreeRTOS does not seem to be working easily with the Arduino DUE

Just for clarification: im not asking for a code but a tip to what i should look into next. Somehow the SeveralThingsAtOnce example doesn't seem to be applicable to me since it is waiting for the Servo-Intervall or checking for LED states (whereas my stepper motors always change state and do not have intervals as they are moving continuously).
-Please excuse me for not being a pro(-grammer) :slight_smile:

--
Setup: Arduino DUE; 2 x drv8825, 2 x Nema 17s Steppermotors

JHof7:
Somehow the SeveralThingsAtOnce example doesn't seem to be applicable to me since it is waiting for the Servo-Intervall or checking for LED states (whereas my stepper motors always change state and do not have intervals as they are moving continuously).

Several Things at a Time is the sort of thing you need. But instead of flashing an LED you want it to cause a stepper motor to move one step.

You said "but proceed their task one after another." and I presume that is because the individual steps are not interleaved.

A critical question is whether you want the motors to move in a co-ordinated way. For example one motor moves 77 steps in exactly the same time that another motor moves 182 steps. OR whether you want both motors to work at the same speed so the one doing 77 steps finishes first. Both systems are achievable.

Another option for you to study is the MultiStepper feature of the AccelStepper library.

...R

This link may be interesting for you, preemptive multitask kernel for Arduino Due :

http://perso.ensta-paristech.fr/~pessaux/alius/arduino.html#Babix

Robin2:
Several Things at a Time is the sort of thing you need. But instead of flashing an LED you want it to cause a stepper motor to move one step.

You said "but proceed their task one after another." and I presume that is because the individual steps are not interleaved.

A critical question is whether you want the motors to move in a co-ordinated way. For example one motor moves 77 steps in exactly the same time that another motor moves 182 steps. OR whether you want both motors to work at the same speed so the one doing 77 steps finishes first. Both systems are achievable.

Another option for you to study is the MultiStepper feature of the AccelStepper library.

...R

Hi Robin2

Yes the steps aren't interleaved (i just can shuffle the steps of each motor to take but they - of course - still proceed with each their own command leaving the other one in standby). So what happens is that Motor1 may steps 600 for example, only then Motor2 begins stepping for 400 steps.

I'd describe it as totally independent from each other. Speed should be a concern of each individual code.
Example:

"Motor1 step 600 clockwise at 5rpm then wait 2sec then 400 step at 10rpm counterclockwise.
Motor2 step 4 counterclockwise, then wait 60sec then accelerate clockwise from 1rpm to 10rpm for 6000 steps.

  • start both motors at the same time, if one is done before the other: begin their loop again"

Like this, is it still achievable with accelstepper?

Iā€™m still not sure from Reply #3 what your requirement is.

The basic AccelStepper library can cause several motors to move each at its own speed for a separate number of steps all at the same time.

What it does NOT do is adjust the speed so they all complete the steps in the same time period. But I believe the MultiStepper library can do that. However I have written my own code to do that so I have no experience of it.

Try some of the examples that come with AccelStepper and it may help you to express your requirement more clearly.

ā€¦R

JHof7:
The idea isn't mindblowingly difficult to describe: 1 Arduino, 5 Steppers that loop to infinity and 1 Solenoid or Servo. Goal is a drawing machine (several videos on youtube - however the uploaders do not seem to be very helpful).

Yes, it is difficult to describe. Show us a picture.

Most anything I can imagine as a drawing machine would only use 2 steppers in an X-Y or angle-distance configuration. How do you plan to arrange 5? My imagination also includes operating all steppers simultaneously at different speeds. Otherwise it could only draw straight lines in the X-Y direction.

If you prefer thinking in tasks, have a look at the Task Macros. They allow to write concurrent code, as much as an Arduino allows for, and keep you code clean by hiding the otherwise required variables, state machines and more. All that at no extra penalty vs. traditional Arduino code patterns.

@Robin2:

Regarding accelstepper: That might be exactly what im looking for. I don't wish the motors to finish at the same time but to do their loop over and over again. Motor1 might do its loop (for instance: 2steps clockwise, pause 1sec, reloop this) 100 times before Motor2 even finishes its one (for example 20000steps clockwise, pause 6minutes, reloop this).
The whole machine should only stop moving the motors once i unplug it completely from the socket.

@MorganS:

Look at this one for example:

The reason i want to run 5 motors is that i want the top-plates, where the arms are directly attached to, to have its own independent motor rather than having a fixed gear assembly connected to the bottom plate's motor like in the video. So that makes 2 stacked and independent motor driven rotorplates per arm holding the pen (or drawing axis as you might call it).

The 5th motor should turn the table under the pen (and the solenoid / servo should be positioned on the arm, rising or lowering the pen to make the pen contact the paper, thus drawing, or prevent contact).

I think the video is a better reference than me drawing a picture of it :slight_smile:

Thank you for your support! I guess accelstepper and tasks might be the right direction, rather than dealing with RTOS.