View unanswered posts | View active topics It is currently Tue Sep 23, 2014 8:29 pm






Reply to topic  [ 10 posts ] 
tasks 
Author Message
Rookie

Joined: Thu Jul 19, 2012 11:14 am
Posts: 18
Post 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


Fri Mar 01, 2013 12:00 am
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3223
Location: Rotterdam, The Netherlands
Post 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

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Fri Mar 01, 2013 12:40 am
Profile WWW
Rookie

Joined: Thu Jul 19, 2012 11:14 am
Posts: 18
Post 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()


Fri Mar 01, 2013 1:22 am
Profile
Site Admin
Site Admin

Joined: Tue May 15, 2007 9:02 am
Posts: 405
Post 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);

}

_________________
Jesse Flot
CMU Robotics Academy
ROBOTC Support


Fri Mar 01, 2013 9:51 am
Profile
Moderator
Moderator

Joined: Thu Jan 03, 2013 5:10 pm
Posts: 198
Location: The plateau north of the Ohio River Valley, also known as Cave Country.
Post 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.

_________________
I'm not a robot! I'm british! ~ quote from an asparagus
I am not a robot! I am a unicorn! ~ quote from a robot


Fri Mar 01, 2013 10:01 am
Profile
Rookie

Joined: Thu Jul 19, 2012 11:14 am
Posts: 18
Post 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!


Sun Mar 03, 2013 7:14 pm
Profile
Moderator
Moderator

Joined: Thu Jan 03, 2013 5:10 pm
Posts: 198
Location: The plateau north of the Ohio River Valley, also known as Cave Country.
Post Re: tasks
You are welcome. I am glad I could help!

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

_________________
I'm not a robot! I'm british! ~ quote from an asparagus
I am not a robot! I am a unicorn! ~ quote from a robot


Sun Mar 03, 2013 8:53 pm
Profile
Rookie

Joined: Thu Jul 19, 2012 11:14 am
Posts: 18
Post 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.


Mon Mar 04, 2013 7:15 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3223
Location: Rotterdam, The Netherlands
Post Re: tasks
The PC based emulator is just the brick, no sensors or world.

= Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Tue Mar 05, 2013 1:58 am
Profile WWW
Moderator
Moderator

Joined: Thu Jan 03, 2013 5:10 pm
Posts: 198
Location: The plateau north of the Ohio River Valley, also known as Cave Country.
Post 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.

_________________
I'm not a robot! I'm british! ~ quote from an asparagus
I am not a robot! I am a unicorn! ~ quote from a robot


Tue Mar 05, 2013 11:58 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 10 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.