Heres my first rendition
Before anything, I’ll define some stuff.
LateralTrack = both of my tracking wheels (LeftTrack and RightTrack) rotation divided by 2 (for average)
RLateralPID = Reverse Lateral PID
FLateralPID = Forward Lateral PID
I start by having my function call one line (int degrees)
because the two lines
desiredLateralValue = 500;
waitUntil(LateralTrack > 500);
will always have the same value
in this chunk of code, I give the task a time parameter to run in (1.5 seconds) which is a complete guess
vex::task test1(drivePID);
resetDriveSensors= true;
desiredLateralValue = 500;
wait(1.5, sec);
vex::task::stop(test1);
in this chunk of code, Instead of giving the task a time parameter, I use my tracking wheels to stop the task for me so I dont have to guess how long it will take to run the task (I want the task to run for as long as my robot moves)
vex::task test01(drivePID);
resetDriveSensors= true;
desiredLateralValue = 500;
waitUntil(LateralTrack > 500);
vex::task::stop(test01);
(let me know if this would work))
Moving on, I decided that I would take the second chunk and use it for my task as it is probably more accurate and I don’t have to guess how long the task needs to run for
Below is how I’m attempting to condense it.
void FLateralPID(int degrees){
resetDriveSensors = true;
desiredLateralValue = degrees;
waitUntil(LateralTrack > degrees);
}
void RLateralPID(int degrees){
resetDriveSensors = true;
desiredLateralValue = -(degrees);
waitUntil(LateralTrack < degrees);
}
I made two functions, one for forward and one for reverse.
EXPLANATION
To start off, I added the line resetDriveSensors = true;
which is defined here
bool enableDrivePID = true;
if (resetDriveSensors) {
resetDriveSensors = false;
LeftDrive.setPosition(0,degrees);
RightDrive.setPosition(0,degrees);
LeftTrack.setPosition(0,degrees);
RightTrack.setPosition(0,degrees);
}
This section resets my motor position and my tracking wheel position to zero.
–
Next, I have my desired value (this can be positive or negative depending on if I want to go forward or reverse, hence the reason I made two functions)
examples of both lines below
(desiredLateralValue = degrees;
) OR (desiredLateralValue = -(degrees);
)
Referring to the code above, this line will either have -(degrees) or (degrees). I wrote this so that I don’t have to worry about if the desired value is negative or positive, I just write how far I want to go.
–
The final line in this sequence depends if I’m going forward or reverse
Forward- waitUntil(LateralTrack > degrees);
Reverse- waitUntil(LateralTrack < degrees);
Like I mentioned before, this is here to tell the task when to stop running. If the value of the tracking wheels exceeds the distance I want to travel, the task stops. Same goes for reverse, it just has to be negative because technically the value is getting smaller and smaller the further I go in reverse.
Let me know if a further explanation is needed on a specific part or if you find anything wrong with my logic.