|
Page 1 of 1
|
[ 10 posts ] |
|
| Author |
Message |
|
robusto
Rookie
Joined: Thu Jul 19, 2012 11:14 am Posts: 18
|
 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 |
|
 |
|
mightor
Moderator
Joined: Wed Mar 05, 2008 8:14 am Posts: 2864 Location: Rotterdam, The Netherlands
|
 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
_________________| Some people, when confronted with a problem, think, "I know, I'll use threads," | and then two they hav erpoblesms. (@nedbat)| My Blog: I'd Rather Be Building Robots| ROBOTC 3rd Party Driver Suite: [ Project Page]
|
| Fri Mar 01, 2013 12:40 am |
|
 |
|
robusto
Rookie
Joined: Thu Jul 19, 2012 11:14 am Posts: 18
|
 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 |
|
 |
|
jbflot
Site Admin
Joined: Tue May 15, 2007 9:02 am Posts: 383
|
 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:
|
| Fri Mar 01, 2013 9:51 am |
|
 |
|
Coder A
Expert
Joined: Thu Jan 03, 2013 5:10 pm Posts: 138 Location: Southern Indiana
|
 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 asparagusI am not a robot! I am a unicorn! ~ quote from a robotPlay chess for free!
|
| Fri Mar 01, 2013 10:01 am |
|
 |
|
robusto
Rookie
Joined: Thu Jul 19, 2012 11:14 am Posts: 18
|
 Re: tasks
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 |
|
 |
|
Coder A
Expert
Joined: Thu Jan 03, 2013 5:10 pm Posts: 138 Location: Southern Indiana
|
 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 asparagusI am not a robot! I am a unicorn! ~ quote from a robotPlay chess for free!
|
| Sun Mar 03, 2013 8:53 pm |
|
 |
|
robusto
Rookie
Joined: Thu Jul 19, 2012 11:14 am Posts: 18
|
 Re: tasks
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 |
|
 |
|
mightor
Moderator
Joined: Wed Mar 05, 2008 8:14 am Posts: 2864 Location: Rotterdam, The Netherlands
|
 Re: tasks
The PC based emulator is just the brick, no sensors or world.
= Xander
_________________| Some people, when confronted with a problem, think, "I know, I'll use threads," | and then two they hav erpoblesms. (@nedbat)| My Blog: I'd Rather Be Building Robots| ROBOTC 3rd Party Driver Suite: [ Project Page]
|
| Tue Mar 05, 2013 1:58 am |
|
 |
|
Coder A
Expert
Joined: Thu Jan 03, 2013 5:10 pm Posts: 138 Location: Southern Indiana
|
 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 asparagusI am not a robot! I am a unicorn! ~ quote from a robotPlay chess for free!
|
| Tue Mar 05, 2013 11:58 am |
|
|
|
Page 1 of 1
|
[ 10 posts ] |
|
Who is online |
Users browsing this forum: No registered users and 3 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
|
|