![]() |
Turning Robot with PID Feedback from Gyro
Hello Chief Delphi.
For our planned off season events, our team would like to be able to use a gyroscope to turn our robot via a PID loop. We have got the gyro to work, but we cannot get the PID loop to work. The robot continuously turns, not stopping at the desired setpoint. We confirmed the gyro works to our standard by making a command that prints the robots heading to the SmartDashboard. The code that we are using for the PID Loop was mostly auto generated by Robot builder with a few exceptions, which are: -The "setAbsoluteTolerance" is given a value of 3.0, -The "returnPIDInput" function returns the getAngle() method instead of the pidGet() method. (I'm not exactly sure what the pidGet() method does). -The "usePIDOutput" function controls all six of our drive motors. Please see the code posted below: DriveTrain.java (The PID subsystem file). Code:
package org.usfirst.frc1325.DrivetrainWithPIDControl.subsystems;Code:
Thanks, |
Re: Turning Robot with PID Feedback from Gyro
You posted the subsystem in both sets of code instead of the command in the second one.
|
Re: Turning Robot with PID Feedback from Gyro
I fixed the problem. Thanks notmattlythgoe.
|
Re: Turning Robot with PID Feedback from Gyro
Have you tried printing the angle from the returnPIDInput() method?
Could you be turning the opposite direction that you want to be? If you turn right and that causes the angle to count up you'll never get to -90. You'll probably also want to set your setpoint to something like Code:
Robot.driveTrain.setSetpoint(-90.0 + Robot.driveTrain.getGyroAngle()); |
Re: Turning Robot with PID Feedback from Gyro
It's been a while since I've done a PID loop for a drivetrain, but I think with a P of 1.0 your drive will always be turning at full power. That is because the drive accepts an input from -1 to 1, and the PID loop starts by multiplying the error by the P, which will make the output be greater then 1 whenever you are more then 1 degree off. Also, you do need to limit the PID output to be between -1 and 1 because thats the range motor outputs want.
Most likely the robot is turning the wrong way compared to the Gyro, just like notmattlythgoe said. To fix this you could return the negative gyro output, or reverse the PID output. |
Re: Turning Robot with PID Feedback from Gyro
Inside the DriveTrain class, you should probably set "continuous" to "true". This indicates that when the PID input goes below its minimum, it rolls over to the maximum value.
|
Re: Turning Robot with PID Feedback from Gyro
Quote:
Quote:
|
Re: Turning Robot with PID Feedback from Gyro
Quote:
Consider a simple P controller. It has the form: Code:
output = Kp * errorCode:
Kp = output / errorCommanding an output of -1 or +1 is like commanding a full speed turn with your joysticks during teleop. For most robots, that's probably pretty fast. Probably way, way too fast to accurately turn only 1 degree. I would start with a really tiny gain and then move up from there. Try (1/90) or so. This would give full power when you are 90 degrees (or more) off of your goal, half power at 45 degrees off, etc. What you will likely see is that your robot moves in the general direction of your goal, but stops a little short or overshoots a bit. At this point, you can try upping your P gain, or adding Ki or Kd gains (and by the way, the same principle applies: These gains also have units, and their units involve time as well). You may also find that limiting the maximum output of your PID controller is necessary to prevent overshoots (for example, no matter what, never go more than 50% of top speed). |
| All times are GMT -5. The time now is 10:44. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi