Learning Simple PID

Hello CD,

Can anyone please post tutorials or working sample Java code for someone learning PID loops and gyro programming. Iterative or Command Based Java is good! Thank you so much. :]

I know this is silly, replying to a member of my own team, but here are a few links:


Also check out http://wpilib.screenstepslive.com. There is a bunch of documentation that was posted yesterday and more coming as fast as we can write it.


Thank you for the helpful links!
The main goal I want to accomplish with these resources is to implement a drive straight system with our tank drive code. I am having trouble figuring it out. Essentially I want to use the gyroscope to run and check if the robot is zeroed, (when in a “drivestraight” command), so that if it comes out of alignment, then it will “re-zero” itself, and continue driving straight.

Has anyone produced a java method for doing this yet, that they would like to share?

Thank you.

This might give you some ideas:



I should have mentioned: If your vehicle is not driving straight when so commanded, check the hardware first before trying to correct it in software. Check drivetrain alignment and friction on left & right sides. Check your wiring to make sure you don’t have asymmetric voltage drops left vs right. Check the left & right motors to make sure they have similar performance curves.

What’s the general opinion on using PID through the Jaguars vs using it through WPILib?

And what’s the correct procedure for PID (either distance or speed) when you have one encoder on each side of the drivetrain? Average the two together, or command them both separately?

It depends on what you are trying to achieve.

Generally, you pick one parameter to control and then control it. Trying to control two parameters will lead to conflicts.

Using the built-in PID in the Jaguar allows you to control that Jaguars output. If you want to control the outputs from multiple Jaguars quasi-independently, such as in the drivetrain, you would need to do it at a higher level such as in your cRio.