Tasks for Autonomous


I have two functions written that I would like to run simultaneously during autonomous. I feel like I should using Tasks to do this. My two functions are as follows:

Function 1: raise arm and keep arm position using PID control.

Function 2: self straightening driving using optical shaft encoders. I actually have 4 functions for this (driveForward, driveBack, leftTurn, rightTurn), but they are all actually the same, except the direction of driving.

How can I set these up as Tasks so I can have the robot hold the arm up through PID, while driving around?


My team does this by putting the lift PID in a task and then we just change our lift’s target angle variable in the autonomous task.

Try putting the PID in its own task, and when auto starts, immediately start the lift PID task. From there you can just set the angle of your lift and it will move on to the next action in your program while it moves the arm.

I am trying to do the same thing. I am not a programmer, but now I am having to program my robot, and I have very little experience. @Jacob Walter , would you be willing to provide some sort of example? I understand how to do all of this in theory, but even just pseudocode in format would help tremendously.

Just on my phone right now, so pseudo code it will be :stuck_out_tongue:
Just a basic control structure for the lift would work. Start by making a variable to control the lift’s position, maybe set it to equal your lift encoder value.
In the lift control task, use the variable to tell the lift what to do. In your main task, start the lift control task, and then you can just change the lift’s variable and it will adjust accordingly even while doing other things.

Int LiftTargetAngle;

Task LiftControl (){
While (1){
If (lift < LiftTargetAngle){
Lift up
} else {
Lift down

Task Autonomous(){
StartTask (LiftCotrol);
LiftTargetAngle = 90;
Drive forward

While(1)? I haven’t seen that used before, is that actually what I would use? Thank you so much!

Yeah, that would work. It will make the loop continue until you stop the task. While (true) has the same affect. They go forever*

Okay. And how would I end the task?

task thing();
//unless you activate it again, it’ll stop right here
task main()
startask(thing)//it repeats once then stops

what this means, is essentially if you activate it once, it’ll run until the end of the code, unless you put it in a while, and it reactivates it. However if you just put starttask(thing); it’ll stop at the end of the code