View unanswered posts | View active topics It is currently Sat Sep 20, 2014 1:54 am






Reply to topic  [ 3 posts ] 
Problem in MultiTasking 
Author Message
Rookie

Joined: Sat Mar 14, 2009 3:53 am
Posts: 6
Post Problem in MultiTasking
When i type some codes as below, task one and two don't work.
And how to stop one task while another task keeps running??
Also, sub-functions or multitasks is preferred to use??

task one()
{
...
}

task two()
{
....
}

task main9)
{
StartTask(one);
StartTask(two);
}


Sun Mar 22, 2009 7:37 am
Profile
Rookie

Joined: Sat Aug 30, 2008 2:25 am
Posts: 25
Post Re: Problem in MultiTasking
Tasks have always worked fine for me, I usually have one task monitoring and responding to sensors (so they are always alert).

Quote:
Also, sub-functions or multitasks is preferred to use??


I'm not quite sure what that means, but if you mean functions vs. tasks, they both have their place and are really two different things. You could call a function from a task.

If you need something to run in parallel, then a task is the obvious place to put it.


Fri Mar 27, 2009 8:59 pm
Profile
Rookie

Joined: Fri Nov 21, 2008 12:05 am
Posts: 4
Post Re: Problem in MultiTasking
Swonder,

I think maybe an example of a program with tasks can help. For example, I recently wrote one to create an emergency ctop button on my robot. (Eventually it will have more than one motor running and maybe another task for monitoring some sensors, but for now it is just an example).

This program works as follows:

The robot waits for a button (a touch sensor) to be pressed before starting the program. Then it has a small wait loop (for the button to be released) and then starts the emergencyStop function, which tests to see if the button is pressed or not. In the mean time, the main task keeps running that motor, trapped in an infinite while loop. When the button is pressed again, the emergencyStop task exits its while loop and stops all tasks, ending the program.

Your syntax for the task stuff seems correct, but it would help if you posted the rest of your code to see where it may not be working. Hope this helps.

Good luck,

-Mike

Quote:
//*!!Code automatically generated by 'RobotC' configuration wizard. !!*//
//*!!Analog, 0, , , !!*//
//*!!Camera, 0, , , !!*//
//*!!PSCtrl, 0, , , !!*//
//*!!Sensor, in1, touchSensor, sensorTouch, , !!*//
//*!! !!*//
//*!!Start automatically generated configuration code. !!*//
const tSensors touchSensor = (tSensors) in1; //sensorTouch //*!!!!*//
//*!!CLICK to edit 'wizard' created sensor & motor configuration. !!*//

/*************************************************************************
VEX - EMERGENCY STOP BUTTON

Description: This Program uses task control to implement a bumper switch
as a start button and an emergency stop button.

Configuration: This program is written to work with RUFUS
Motor - port1
Bumper Switch - in1

Additional Notes: The main code goes into the main task after the
emergencyStop function has been called.

*************************************************************************/

task emergencyStop()
{
wait1Msec(20);
while(SensorValue(touchSensor)==0)
{
wait1Msec(15);
}
StopAllTasks();
}

task main()
{
while(SensorValue(touchSensor)==0)
{
wait1Msec(15);
}

wait1Msec(500);

StartTask (emergencyStop);

while(true)
{
motor[port1] = 63; //Motor on port1 is run at half (63) power forward
}

}


An important thing to look for is that if any task starts another task, the tasks must be declared in order.


Thu Jan 14, 2010 5:29 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 3 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.