How to wait until TargetPosition reached with stepper

Supporting Visual Studio on Windows
Plan9
Fresh meat
Posts: 2
Joined: Tue Dec 31, 2013 12:19 pm
Contact:

How to wait until TargetPosition reached with stepper

Postby Plan9 » Mon Jan 06, 2014 11:56 am

I am using a 1067 stepper controller and would like to perform a series of TargetPosition commands that wait until the previous TargetPosition is reached. I've tried looping with a check of the Stopped condition but this just gets stuck in a loop. (I know this is bad practice on an event based system any way.) The work around I have at the moment is to calculate the travel time from current position to target position base on distance and velocity (with a little extra fro acceleration/deceleration) and place a Thread.Sleep command between TargetPosition calls. Trouble is it keeps the _OnPositionChange event handler from executing.

I am using VB2005. What's the best way to handle this problem.

Thanks,
Richard

User avatar
Patrick
Lead Developer
Posts: 3067
Joined: Mon Jun 20, 2005 8:46 am
Location: Canada
Contact:

Re: How to wait until TargetPosition reached with stepper

Postby Patrick » Mon Jan 06, 2014 2:04 pm

you can loop waiting for stopped to become true - this is how I would do it, just make sure you have a timeout condition for the loop so it doesn't deadlock your system. Also, most importantly, you have to loop somewhere that won't interfere with the library threads - this means not in an event handler, or a GUI event handler, or anything like that, just in your main loop - or if you are using a GUI you would need a timer or background worker or something like that to poll stopped.

-Patrick

Plan9
Fresh meat
Posts: 2
Joined: Tue Dec 31, 2013 12:19 pm
Contact:

Re: How to wait until TargetPosition reached with stepper

Postby Plan9 » Mon Jan 06, 2014 2:52 pm

Thanks Patrick,

Had to stop thinking in a linear fashion and put my "Event" based hat on. Used the Stopped event to trigger the sequence of TargetPosition calls using IF statements to step through the sequence. As it completed each TargetPosition I would flag it as complete so the next time through it would execute the next step in the sequence.

Works smooth now.

Richard


Return to “VB .NET”

Who is online

Users browsing this forum: No registered users and 1 guest