OpenQNX :: The QNX Community Portal

Oct 12, 2008 - 05:40 PM
Google
  Web openqnx.com   
     Create an account Home · Submit News · QNX Forums · QNX Download · Search   
_
Main Menu
Who's Online
There are 17 unlogged users and 0 registered users online.

You can log-in or register for a user account here.

Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
samaantonio
Post subject: Help with an application  PostPosted: May 13, 2008 - 05:24 PM
Active Member


Joined: Feb 08, 2008
Posts: 23

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
 
 View user's profile Send private message  
Reply with quote Back to top
ysinitsky
Post subject: RE: Help with an application  PostPosted: May 13, 2008 - 06:23 PM
Senior Member


Joined: Dec 14, 2005
Posts: 138

Hello Antonio,
Read “Getting Started with QNX Neutrino 2” by R. Krten. If the book is unavailable, contact your QNX sales representative or QSSL directly.
As to the (usually worthless) general advice – do not use multiple threads unless you really must do so. Avoid multiple threads if you are new to QNX.
Limit you interprocess communications to Send-Receive-Reply.
Thanks,
Yuriy
 
 View user's profile Send private message  
Reply with quote Back to top
mario
Post subject: RE: Help with an application  PostPosted: May 13, 2008 - 09:56 PM
QNX Master


Joined: Sep 01, 2002
Posts: 2917

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();
}
}
 
 View user's profile Send private message Visit poster's website  
Reply with quote Back to top
samaantonio
Post subject: RE: Help with an application  PostPosted: May 14, 2008 - 02:48 AM
Active Member


Joined: Feb 08, 2008
Posts: 23

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! Smile

Antonio
 
 View user's profile Send private message  
Reply with quote Back to top
Tim
Post subject:   PostPosted: May 14, 2008 - 01:47 PM
Senior Member


Joined: Mar 10, 2004
Posts: 575

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
 
 View user's profile Send private message Visit poster's website  
Reply with quote Back to top
samaantonio
Post subject:   PostPosted: May 19, 2008 - 01:22 AM
Active Member


Joined: Feb 08, 2008
Posts: 23

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
 
 View user's profile Send private message  
Reply with quote Back to top
mario
Post subject:   PostPosted: May 20, 2008 - 11:41 AM
QNX Master


Joined: Sep 01, 2002
Posts: 2917

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.
 
 View user's profile Send private message Visit poster's website  
Reply with quote Back to top
rgallen
Post subject:   PostPosted: May 22, 2008 - 06:43 PM
QNX Master


Joined: Jul 11, 2002
Posts: 607

mario wrote:
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

Smile

Of course, this mantra should be *very* gently seasoned with the realities of performance...
 
 View user's profile Send private message Visit poster's website  
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2007 The PNphpBB Group
Credits
All logos and trademarks in this site are property of their respective owners. The comments are property of their posters.
Powered by OpenQNX: The QNX Community Portal Site
QNX and the QNX logo are registered trademarks of QNX Software Systems.