Thread: Speed PID loop
View Single Post
  #2   Spotlight this post!  
Unread 06-02-2012, 04:48
TravSatEE's Avatar
TravSatEE TravSatEE is offline
Spacecraft Engineer and more
FRC #2035 (Robo Rockin' Bots)
Team Role: Engineer
 
Join Date: Jan 2012
Rookie Year: 2002
Location: Monterey, CA
Posts: 26
TravSatEE is infamous around these partsTravSatEE is infamous around these parts
Re: Speed PID loop

First, read some background material: this year's discussion [1], past year's [2] and PID tuning [3]. You can ask other questions here if you need help understanding.

The general formula for PID velocity control is in [2] under the Jared341 post. In WPILIB, you need to copy PIDController.java as PIDVelocityController.java, and make some changes to the calculate() method (lines 141-171). You can rebuild this into your WPILIB or add it into your robot code, whichever you are more comfortable with. WPILIB comes with a Netbeans project to open/change/build your updated classes.jar used to link with your robot code.

Your output will become a sum of the previous output and the new calculated change. This isn't too difficult of a change, so would be good programming practice for you.

Modifying the PIDController/PIDVelocityController to use two motor outputs is also not too difficult of a code change. Need another constructor to accept 2 motor inputs, add a new internal variable for it, and then you have an additional pidOutput.pidWrite() call near line 171 in PIDController.java. You may need to set the output as -1 * result if your motors are not physically oriented in the same direction to avoid the motors rotating in the opposite direction one another.

[1] http://www.chiefdelphi.com/forums/sh...d.php?t=101244

[2] http://www.chiefdelphi.com/forums/sh...ad.php?t=62888

[3] http://www.chiefdelphi.com/forums/sh...80#post1107680
Reply With Quote