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

Multitasking and Waits
http://robotc.net/forums/viewtopic.php?f=52&t=10237
Page 1 of 1

Author:  Synergists [ Mon Jan 12, 2015 12:43 am ]
Post subject:  Multitasking and Waits

Another Question,
For Tele-op, we have programmed the robot so that there are 5 tasks running the robot; task main, driveTask, ballCollectionTask, ballDispensionTask, and goalGrabbingTask. This all works great.

My question is, does it matter if there are waits inside of each task? My understanding is that this would release the CPU for a few hundredths of a second. Does that help improve the efficiency of the program overall and improve response time between the robot and joystick?

Author:  MHTS [ Mon Jan 12, 2015 3:25 am ]
Post subject:  Re: Multitasking and Waits

Synergists wrote:
Another Question,
For Tele-op, we have programmed the robot so that there are 5 tasks running the robot; task main, driveTask, ballCollectionTask, ballDispensionTask, and goalGrabbingTask. This all works great.

My question is, does it matter if there are waits inside of each task? My understanding is that this would release the CPU for a few hundredths of a second. Does that help improve the efficiency of the program overall and improve response time between the robot and joystick?

If these are RobotC tasks, then sure you can have wait statements in each of the tasks. The RobotC VM will take care of switching the CPU between different tasks. However, you must be very careful on what you access in each tasks. If these tasks share common resources, there may be contentions. For example, if a group of global variables is referenced by a task, they might be changed by another task right in the middle of the access. It is especially bad if this group of variables could be gotten into an inconsistent state during task switching. That's why you may need to do hogCPU and releaseCPU to protect a section of code that is referencing a group of variables that are related to each other. If you are not familiar with the concept of preemptive multi-tasking, you may want to avoid using tasks.

Author:  Synergists [ Mon Jan 12, 2015 8:26 pm ]
Post subject:  Re: Multitasking and Waits

Thanks! Both of those are good to know!

Author:  FTC4592 [ Thu Mar 12, 2015 5:38 pm ]
Post subject:  Re: Multitasking and Waits

Also something worth knowing is that you can use semaphores instead of hogCPU to protect variables without having to hogging the cpu for other tasks that don't use that variable.

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