
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.