How do I use a Drivetrain in a PID Loop?

I’m new to C++, and I’m following a video tutorial on making a PID Loop. In the video, he utilizes the MOTOR.position() code and this is where I get stuck. While I believe he uses a left and right motor individually in the video, I am using a 4-motor drivetrain in my robot. I wish to implement the PID loop but I’m not sure if it is possible with a drivetrain.

This is my code so far; it’s barebones as I just started following the video.

For the first error make sure that you are using the same name that you are using for the motor when your configuring it. For the motor position if you motor name was LeftMotor the code would be LeftMotor.position(degrees);

C++ VEXCode V5 Text Tutorials - Autonomous PID and Multitasking - YouTube this is a good video to watch

Sorry - I forgot to add the video I was watching. The video you posted is the one I was already following, and it’s around 11:30 into the tutorial where he mentions using individual motors, whereas I’m using the built-in drivetrain feature of VEXcode V5. Therefore, I can’t really find a way to use the position feature as he does in the video as there’s no command to do it ( not that I know of anyway).

For the first error, that was actually me trying to troubleshoot the issue; I had found another forum discussing the same issue I had and one of the mentioned solutions was to use extern motor LeftDriveSmart and extern motor RightDriveSmart. However, both of these commands lead me to an error [clang] Unknown type name 'motor'.

Instead of using the built in drive train function you can use.
const int wheelTravel = 320;

const int trackWidth = 320;

const int wheelBase = 130;

motor_group driveL(leftMotorF, leftMotorB);

motor_group driveR(rightMotorF, rightMotorB);

drivetrain myDrivetrain(driveL, driveR, wheelTravel, trackWidth, wheelBase, mm);

Then if you do this you would be able to then you would be able to call the motor position and the left and right drive trains.

If, in fact, you are using 2 motor groups you might want to declare them as


and not like this:

Thanks guys!! Now I have a couple more questions; I finished the YouTube video tutorial and I’m unsure if this will work with driver control or if it’s strictly meant for autonomous driving. My robot doesn’t seem to drive straight and veers off to the right so I was wondering if the PID loop could aid with that in both programmed driving and in-person driver control.

If your robot is drifting it is mostly likely a build problem and should be fixed instead of trying to compensate for it in your code