ROBOTC.net forums
http://www.robotc.net/forums/

tasks
http://www.robotc.net/forums/viewtopic.php?f=55&t=5558
Page 1 of 1

Author:  robusto [ Fri Mar 01, 2013 12:00 am ]
Post subject:  tasks

Does the simulator support tasks? I am seeing behaviour that suggests it doesn't, at least not fully.

If I have this program structure

task a()
{
<statements>
}

task main()
{
StartTask(a);

}

task a starts as expected. If however I add another task say b thus

task a()
{
<statements>
}

task b()
{
<statements>
}

task main()
{
StartTask(a);

}

task a does not start or, if it starts, does not execute properly. Note that task b is not started; it is not even referenced. The stall will happen even if task b does nothing at all.

Any ideas?

Rob

Author:  mightor [ Fri Mar 01, 2013 12:40 am ]
Post subject:  Re: tasks

It would be very helpful if you could include more than pseudo code to demonstrate a bug. Please include a program that can reproduce the issue and either paste in inside [ code][/ code] blocks (minus the spaces) or attach it to the post.

Regards,
Xander

Author:  robusto [ Fri Mar 01, 2013 1:22 am ]
Post subject:  Re: tasks

Code:
#pragma config(Sensor, S1,     touchSensor,              sensorTouch)
#pragma config(Sensor, S2,     compassSensor,            sensorVirtualCompass)
#pragma config(Sensor, S3,     lightSensor,              sensorLightActive)
#pragma config(Sensor, S4,     sonarSensor,              sensorSONAR)
#pragma config(Motor,  motorA,          gripperMotor,       tmotorNormal, PIDControl, encoder)
#pragma config(Motor,  motorB,          rightMotor,         tmotorNormal, PIDControl, encoder)
#pragma config(Motor,  motorC,          leftMotor,          tmotorNormal, PIDControl, encoder)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//
// This is for the NXT model, not TETRIX


task move()
{
   while (true)
   {
      motor[leftMotor] =70;
      motor[rightMotor] =70;
   }
}


task a()
{

}




task main()

{
      StartTask(move);

}


Run this in Curriculum and Level Builder worlds and nothing happens. Edit out or delete task a() and the robot will move forward as specified in task move()

Author:  jbflot [ Fri Mar 01, 2013 9:51 am ]
Post subject:  Re: tasks

Hi Robusto,

Tasks should work fine in RVW.

There was one problem with your code - even when using multiple tasks, "task main()" is still in charge of how long your program runs. In the code you provided, task main starts your "move" task, and then has nothing else. When the robot reaches the closing curly brace of task main, the robot stops running all tasks. This happens very quickly, so you never see the robot run (even though the program ran for about a millisecond).

To correct this, make sure your "task main" has code that makes it "keep going", even if you don't want it to do anything. For example, I put a 5 second wait command in, and it runs for 5 seconds:

Code:
task main()
{
      StartTask(move);
      wait1Msec(5000);

}

Author:  Coder A [ Fri Mar 01, 2013 10:01 am ]
Post subject:  Re: tasks

In the general settings, there is a checkbox labeled "create stopalltasks() epilog at end of task main". Uncheck it to disable this feature. Then the only thing special about main is it starts first.

Author:  robusto [ Sun Mar 03, 2013 7:14 pm ]
Post subject:  Re: tasks

Coder A wrote:
In the general settings, there is a checkbox labeled "create stopalltasks() epilog at end of task main". Uncheck it to disable this feature. Then the only thing special about main is it starts first.



Yes, that's the answer. Thanks.

It was very strange that the addition of a second task in the code (task a in my original listing - a task that does nothing at all and is not started) - caused the the program to stall. Take that code out and the program runs as you would expect (task move executes) , and this is without unchecking "create stopalltasks() epilog at end of task main" and without a wait in task main. Try it and see!

Author:  Coder A [ Sun Mar 03, 2013 8:53 pm ]
Post subject:  Re: tasks

You are welcome. I am glad I could help!

Do you mean test this on the emulator or robot virtual worlds?

Author:  robusto [ Mon Mar 04, 2013 7:15 pm ]
Post subject:  Re: tasks

Coder A wrote:
You are welcome. I am glad I could help!

Do you mean test this on the emulator or robot virtual worlds?



I have tested this in Virtual worlds. The "PC-based emulator" is not available to me as a compiler target (because my copy of robotc is a trial?). Surely though, virtual worlds itself uses the emulator. Pretty strange if there two emulators.

Author:  mightor [ Tue Mar 05, 2013 1:58 am ]
Post subject:  Re: tasks

The PC based emulator is just the brick, no sensors or world.

= Xander

Author:  Coder A [ Tue Mar 05, 2013 11:58 am ]
Post subject:  Re: tasks

I won't be able to test that, as don't have VW, but I will watch out for strange task stuff on the emulator.

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/