I'm working on a project that involves running one DC and two stepper motors independently of each other based on serial commands. I have the electrical setup done, and each motor functions great by itself. My trouble comes if I try to control each one independently. For instance, moving one stepper in a step - pause - step - pause (etc.) configuration while having the other stepper do the same configuration, but not in a related fashion.
Is there a way to start a motor and have it repeat without interuption until told to stop while being able to receive and send serial commands and control the motors?
An RTOS is a possible solution. Each motor controlled by a separate task.. The control over serial run in an another task. Have a look at NilRtos here in the forum.
Pololu's Maestro series of programmable motor controllers can handle various numbers of RC servos and stepper motors concurrently (the latter need a separate motor driver module). The controller, once programmed, can function independently of the arduino. Pololu - Mini Maestro 12-Channel USB Servo Controller (Partial Kit)
mkuhr:
Is there a way to start a motor and have it repeat without interuption until told to stop while being able to receive and send serial commands and control the motors?
Yes - design your sketch to work asynchronously i.e. not to stop (block) while waiting for things to happen. The blink without delay example sketch provides a very simple demonstration of this technique. You need to ensure that the libraries you use to drive stepper motors are designed to work that way i.e. not stop and wait (block) for a commanded movement to be completed.
I'm of the opinion that it borders on abuse to teach newbies to use delay() to blink LEDs, debounce switches, and control stepper motors. For more than one simple task, it quickly becomes unmanageable and unuseable.
And that we should -start- with using millis() such as in the Blink Without Delay example Sketch to do all these things.
polymorph:
I'm of the opinion that it borders on abuse to teach newbies to use delay() to blink LEDs, debounce switches, and control stepper motors. For more than one simple task, it quickly becomes unmanageable and unuseable.
And that we should -start- with using millis() such as in the Blink Without Delay example Sketch to do all these things.
Agreed. I'd be much better off not using delays where I can do something else. Looking through the Blink Without Delay example I should be able to get most everything to work. Things will be a bit complicated in my loop() as the program has to also read optical sensors and check and adjust the speeds of the motors. Because precision speed control of the motors is important, would RTOS be a better way to go then running the code with millis()?
mkuhr:
Because precision speed control of the motors is important, would RTOS be a better way to go then running the code with millis()?
In my opinion, nothing that is simple enough to do on an Arduino is complex enough to justify the overhead of an RTOS. Scheduling things yourself is simple and efficient in systems of this scale and enables you to handle time-based events in the same way you handle other events.
polymorph:
I think you should learn how to use PID in the speed control for your motors.
I understand using PID in controlling motors, but it is not necessary for this use. Once the speed is set it does not need to be adjusted. I'm using optical sensors to read out the speed and position.
PeterH:
mkuhr:
Because precision speed control of the motors is important, would RTOS be a better way to go then running the code with millis()?
In my opinion, nothing that is simple enough to do on an Arduino is complex enough to justify the overhead of an RTOS. Scheduling things yourself is simple and efficient in systems of this scale and enables you to handle time-based events in the same way you handle other events.
After reviewing this, I agree. Thanks for the input!