Help with an application

Hi!

I’m developing an application, that basically consists in controlling velocity and position of two stepper motors, at the same time.

They need to work at the same time, sometimes at different velocities and/or directions, but they need to end at the same time. For example, they might be running at different velocities and directions, but the two of them have to end their cycle in, let’s say, 20 seconds, or 30 seconds… or whatever time they need to be functioning.

Can anybody give me some advice about how to do this? Do I need to create different processes, or one multithreaded process… how do I do that? Thanks in advance!

Antonio

Hello Antonio,
Read “Getting Started with QNX Neutrino 2â€

This has nothing to do with the operating system. It’s basically a mathematical problem. Unless you have multi-core nothing really happens at the same time.

Basically all you need is

for ( ;; )
{
receive();
{
if ( timerStepMotor )
{
processStepMotor1();
processStepMotor2();
}
}

for ( ;; )
{
receive();
{
if ( timerStepMotor )
{
processStepMotor1();
processStepMotor2();
}
}

By doing this, processStepMotor2() runs after processStepMotor1() is finished?..

my problem is… that i’m programming a linear 2-axis trajectory, wich is going to be done by controlling those motors in the needed direction and velocities, one motor per axis. The thing is, they have to run at “the same time”(I know it can’t be done actually at the same time, like you mentioned before), so in case I have a diagonal trajectory, this trajectory can be made correctly. If one motor runs once the other has finished running, i will have like 2 linear trajectories, instead of 1 diagonal; I’ll end up in the same point, but with a different trajectory that the one that I need… am I expressing correctly?
So… can it be done somehow? Can it be done by doing a code something like you said before? Thanks very much! :slight_smile:

Antonio

Antonio,

In Mario’s pseudo-code example, the processStepMotor1() call is meant to represent where you calculate the end point of the stepper motor. Then you send the command to the hardware.

You DO NOT wait there till the motor reaches the end point. You simply send the command to drive the hardware and then move on to processStepMotor2.

The code on the computer will only take microseconds to complete while the actual stepper motors will take likely take seconds to reach their destination.

The receive() call is meant to block while you either wait for a new command to drive the motors to a different end point or wait for some sensor inputs telling you where the motors currently are in case you need make some corrections to the path.

Tim

One quick question… what’s the difference between using several processes, and using a multitheaded process?.. and… What’s the difference between a thread and a process?.. I read that “A thread is a single flow of execution or control, and that a process is a collection of one or more threads that share many things.” But I don’t completely understand the difference between them.

Thanks in advance!
Antonio

Threads inside a process share the same virtual data address and code space. That means threads share variables. Process are isolated from one another.

A context switch from thread to thread ( if in the same process ) is faster then process to process because there is less work involved.

If one process crashes it doesn’t affect the other processes. If a thread crashes it usually takes down the process it’s part of, thus all other threads as well.

Of course, the reason that this particular thread crashed, is quite likely to be that some other thread (in the same process space) corrupted some data upon which the victim thread relies for proper operation. This is why the following mantra should be committed to memory:

  1. All threads should be inside their own process.
  2. See #1

:slight_smile:

Of course, this mantra should be very gently seasoned with the realities of performance…