How to write a PID function for chassis using PROS and V5 motors


i dont fully quite understand how to structure a pid function for the chassis. what would i put in the while loop of the function

void pidDrive(int target, std::string dir){


   // pid code 



would a task be a better choice, if so how would i go about structuring that


For the V5 system you do not need to write custom PID loops. You can use the motorName.move_relative(position, speed) function or the motorName.move_absolute(position, speed) function. This will tell the motor’s onboard controllers to run a PID loop for that motor for whatever your target is.See more here on the PROS site and here for a little bit on the V5 architecture.

If you want, you can write a custom one though. And for where to put the loop of the function, it depends on what you want to do. If you want to run it while running other things in auto, use a task (task should be a while loop with a delay). If not, a while loop works. For tasks, just make a normal task following the instruction here. During teleop, you can use a task too. Same way as in auto. In teleop you can just run a function within the main teleop loop too.

Hope this was helpful.


so far i have written this function but the motors go at a constant speed and does not stop at the target

the raw value does not change

void pidDrive(int target){

newDriveTarget = true;

int proportion;
int derivative;
int error;
int prevError;
int raw;

//pd constants
const float encoderKp = 0.20;
const float encoderKd = 0.1;


error = driveTarget - LeftF.get_encoder_units();

proportion = encoderKp * error;

derivative = encoderKd * (error - prevError);
prevError = error;
if (newDriveTarget) derivative = 0;

raw = proportion + derivative;

std::cout << "raw:" << raw;


newDriveTarget = false;




Doesn’t get encoder units get the units not the encoder value?