View unanswered posts | View active topics It is currently Fri Oct 31, 2014 5:18 am






Reply to topic  [ 5 posts ] 
Passing Parameters to Tasks 
Author Message
Moderator
Moderator
User avatar

Joined: Tue Sep 14, 2010 9:19 pm
Posts: 496
Post Passing Parameters to Tasks
Does anybody know how to pass parameters to a task? For example, in a function you can do this:
void runMotors(int power){
motor[wheel] = power;
}

But that does not work in a task. I have been getting by with using global variables like this:

int power = 0;
task runMotors(){
motor[wheel] = power;
}
task main(){
power = 80;
StartTask(runMotors);
}

Passing parameters becomes quite helpful when you have multiple tasks, so does anyone know how to use parameters with tasks? Thanks.

_________________
sudo rm -rf /


Sun Nov 14, 2010 3:57 pm
Profile
Online
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3233
Location: Rotterdam, The Netherlands
Post Re: Passing Parameters to Tasks
You can only use globals to pass information to a task. They are bits of independently running code.

- 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]


Mon Nov 15, 2010 2:44 am
Profile WWW
Moderator
Moderator
User avatar

Joined: Tue Sep 14, 2010 9:19 pm
Posts: 496
Post Re: Passing Parameters to Tasks
Ok. Thank you for the information. Also, is there any way to have a task pause all other tasks while it is running? I have seen HogCPU(), but that just increases that tasks timesharing right?

_________________
sudo rm -rf /


Tue Nov 16, 2010 12:14 am
Profile
Online
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3233
Location: Rotterdam, The Netherlands
Post Re: Passing Parameters to Tasks
hogCPU() will make that task take up -all- of the CPU time. releaseCPU() will revert it back to the normal priority. You can use this mechanism as a way to get exclusive access to devices/the CPU.

- 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 Nov 16, 2010 3:27 am
Profile WWW
Rookie

Joined: Mon Jan 10, 2011 11:39 pm
Posts: 16
Post Re: Passing Parameters to Tasks
AFAIK you can't pause a task, just start of stop it! but why would you want to pause it? would it really matter? whats the difference between starting and stopping it? I have been :poke: (poking) around in RobotC and had no luck figuring out a way to pass variables to a task, and since my RobotC trail ran out, I havnt been able to test new ideas. I am trying to figure out how the StartTask() works. Once I have done that, I might be able to figure out a way to pass variables.

EDIT: Yes! On the cortex it is possible to Pause and Resume tasks. you would just get the task you want to continue running to call the pause and resume for every other task.

_________________
Regards
Stefan Andres Charsley
charsleysa@gmail.com


Tue Jan 11, 2011 12:00 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 5 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.