Note: Running simultaneous script utility functions

In regards to 599_Competition_Scripting_Template:

Suppose you want to combine two script steps into one and run them simultaneously.       Here is a sample script that moves a distance and has a 2 second timeout in case the move doesn’t finish.

void Script_name_1()
{
switch(step)
{

case 1:

int done1= Move_dist_ch1(300, 50); //command a rate of pwm 50 and move to dist1 = 300
int done2=Ms_timer_T1(2000) ;  // waits 2 seconds before done

done = (done1>0  ||  done2>0) ; //  Sets done = 1 when either done1 or done2 is completed else o.

break;

default:
Reset_scripts();
}
}

done = (done1>0 || done2>0)  is equivalent to the following  if test and is easier.
if(done1>0 || done2>0)
{done = 1;}
else
{done = 0;}

We had trouble with this method in the past because we did not set done = 0 as the default.  This was normally set to zero by the  utility function  returning a zero.  E.g.  done = Move_dist_ch1(..) .

Changing this to done1 = Move_dist_ch1(..)  did not reset done = 0 so we have make sure to use the above coding.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: