How do i set the task priority of user control and other tasks? The competition template in VCS has usercontrol defined as a function so
usercontrol.setPrority(1);
doesn’t seem to work because usercontrol is not a task. Will
main.setPrority(1);
have the same effect? It results in an error when I try it. My problem is my background task that displays LCD values is cutting down response time of user input.
Short answer, don’t change thread priority. Here’s why: if you have a priority thread, schedulers can tend to only run that thread if it’s allowed to run and not sleeping. [James has alluded to VCS’ scheduler having measures to avoid this scenario. Watch for his elaboration.] Also, it might not even solve your problem, depending on the nature of your problem.
And yes,
main
and
usercontrol
are functions, [not the actual threads themselves,] so they will not have the methods of the
thread
class. You won’t have access to the thread objects that run those functions. To do anything just based on “currently running thread” look at the
vex::this_thread
namespace. And then don’t use
this_thread::setPriority
. It will only cause headaches. A better practice would be to make sure that the threads you don’t care about spend a lot of time sleeping so the threads you care about run more often. There are some additional nuances when you involve the nature of the thread scheduler, but for VCS I can’t speak as an authority on how they do scheduling beyond that they used a cooperative scheduler the last time I checked.
If your LCD display value is causing issues with response time in driver, add a vex::task::sleep(30); or a similar wait time to your display code, and that should fix that issue. Can you post your code for driver and the display updating so we can see exactly what is going on?
That will get you a nice, edge-triggered callback for the event of the individual button press. Much easier to deal with than a periodic checking in a dedicated task.