![]() |
Questions about Encoders and PIDControllers
I'm attempting to implement a PID loop using Encoders and Jaguars by using the PIDController class. We've set up the Encoders to report the rate when PIDGet(); is called. (We currently don't have CAN set up, so that's not an option).
What units should the reported rate be in? Should they be calibrated using 'SetDistancePerPulse()' so they return a range from -1.0 to 1.0 (the same range the Jaguars use)? Or should I not calibrate them at all and leave the encoders alone? If I use 'SetSetpoint(1.0)', does that mean the PIDController class will try and output some number to the Jaguars so that the encoders eventually report '1.0'? |
Re: Questions about Encoders and PIDControllers
The simple answer is that if you do what you've described, the pid loop will try, but fail to reach you speed setpoint. I'm not sure if you're trying to do speed or position, but if you're doing speed it isn't as easy. The problem is that the pid loop won't work if you're trying to control speed. With a positional PID loop, when the setpoint is reached, the pid loop will output a zero command to the motor. This makes sense because the motor has reached where it wants to be, and should stop. If you're trying to control speed, you don't want the pid loop to set the motor speed to zero once you've reached the right speed, but instead, you should keep the motor output it is at now. What you have to do is add the error calculated from the pid loop to the current motor output. To do this, you need a class which implements pidoutput. Here's an example in java.
Code:
public class VelocityControl extends Subsystem implements PIDOutput{ |
Re: Questions about Encoders and PIDControllers
Quote:
Controlling speed and position aren't really different, once you get your units of measurement and conversion factors (converting motor input to desired output) right. Position seems different because when the system reaches the setpoint, typically the output should go to zero. If you think of controlling position on an incline, then you still need a non-zero output when the system reaches the setpoint, so it's about the same. Here are some good threads on PID control: Robodox Guide to velocity control using PID 2012: Tuning the Jaguar's Speed Control PID Loop Alternative to PID speed control |
Re: Questions about Encoders and PIDControllers
Quote:
Quote:
http://www.chiefdelphi.com/forums/sh...90&postcount=5 |
Re: Questions about Encoders and PIDControllers
Quote:
Quote:
|
Re: Questions about Encoders and PIDControllers
Quote:
Unless you integrate the output of the PID controller, P, I, and D behave differently when tuning for speed instead of position. In that sense, it is not the same. |
Re: Questions about Encoders and PIDControllers
You can make a simple velocity control by integrating the output of the pid loop. As Ether has said before, if you have JUST an I gain, the pid loop will be able to maintain the right speed. But with the Java implementation of PID, the whole output is multiplied by P. So, when you make p 0, the output will be zero and without modifying the code, you'll never get just an I gain. So, if you just add the error to the current speed, it will integrate the output. On our robot, our shooter wheel will not work with a normal pid control. In order to make the pid loop work with velocity, you must integrate the output. Other software I've used has separate functions for positional/velocity pid.
|
Re: Questions about Encoders and PIDControllers
We achieved reasonably good velocity control using PID, but it required making a custom PIDOutput sink. Basically, what we did is - instead of treating the output to the PID loop as a value to send to the motor, we treated it as a difference to apply to the current value being sent to the motor, and limited this change to +/- .25 in order to keep it from changing too erratically.
As a rough sketch: Code:
//global variables just for demonstration purposes |
Re: Questions about Encoders and PIDControllers
As has been pointed out the problem with PID controlling velocity directly is that as the motor speed reaches the setpoint, the motor speed goes to zero.
New for 2013 is the addition of a feedforward term (4th parameter on the constructors) that is a baseline value that is added to the output value. This term is multiplied by the setpoint so that it scales with differing speeds. The feedforward term will prevent the motor speed oscillation as the motor speed approaches the setpoint. Here's the code that actually computes the final value in the PID controller class: Code:
m_result = m_P * m_errorBrad |
Re: Questions about Encoders and PIDControllers
Quote:
|
Re: Questions about Encoders and PIDControllers
Quote:
I meant that as the actual speed reaches the setpoint speed, the error term goes to zero. Suppose there was only a proportional term, then the output value from the PID controller would go towards zero (proportional constant times zero is zero, similar for the other terms). That's what the feedforward term attempts to fix. |
Re: Questions about Encoders and PIDControllers
Quote:
Quote:
Quote:
Another is to use the I term, when controlling speed, like you would use the P term when controlling position. Yet another is to integrate the output of the PID. |
Re: Questions about Encoders and PIDControllers
Quote:
|
Re: Questions about Encoders and PIDControllers
Does the Java implementation of PID multiply the whole loop output by Kp, or does it just multiply the first term?
|
Re: Questions about Encoders and PIDControllers
Quote:
m_result = m_P * m_error + m_I * m_totalError + m_D * (m_error - m_prevError); |
| All times are GMT -5. The time now is 13:37. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi