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

Passing Parameters to Tasks
http://robotc.net/forums/viewtopic.php?f=11&t=2744
Page 1 of 1

Author:  magicode [ Sun Nov 14, 2010 3:57 pm ]
Post subject:  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.

Author:  mightor [ Mon Nov 15, 2010 2:44 am ]
Post subject:  Re: Passing Parameters to Tasks

You can only use globals to pass information to a task. They are bits of independently running code.

- Xander

Author:  magicode [ Tue Nov 16, 2010 12:14 am ]
Post subject:  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?

Author:  mightor [ Tue Nov 16, 2010 3:27 am ]
Post subject:  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

Author:  charsleysa [ Tue Jan 11, 2011 12:00 am ]
Post subject:  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.

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