![]() |
Gyro PID Programming
Hello,
I am attempting to use a PID loop to force the robot into the 0 degrees starting position at a click of a button. [+] At first, I created a PIDController and initialized it with the Gyro object as the PIDSource, and my own object with a custom PIDWrite routine which consists of: Code:
void PIDWrite(float Output)[+] I then decided to write my own PIDGet() too. All the routine does is get the raw angle, scale it to a value from -1.0 to 1.0 and return it. (I am under the impression that the Output and Source variables should be scaled to the same range, please tell me if this is wrong.) After scaling both the Output and Source vars, setting the setpoint to 0.0 (the starting position at which the gyro was reset) and enabling the PID Controller, nothing happens :confused: Please tell me if you can find anything wrong with what I did, and thanks in advance. |
Re: Gyro PID Programming
Quote:
|
Re: Gyro PID Programming
Alright, I don't currently have the code with me so this is an approximation:
Code:
#define GYRO_SCALE(x) ((x) / 360) |
Re: Gyro PID Programming
Quote:
Also, you could probably use the unmodified version of the PIDContoller by just setting up two controllers. They would both use the gyro as an input, but the output would be different (the two drive motors). The gains for one side will be the inverse of the other side in order to invert the output. I don't think you can do this with Robot Builder, but you could create them by hand in the RobotMap class. |
Re: Gyro PID Programming
Quote:
You want your robot to always take the shortest angle to get back to the zero position. For example, if your gyro angle is reading 359 degrees, you don't want to rotate the robot back 359 degrees to get to zero. You want to rotate it forward 1 degree to get back to zero. So you want the corrected gyro angle in the range -180 to +180, with zero being your starting position. |
Re: Gyro PID Programming
Quote:
Code:
double corrected_angle(double Angle){ |
Re: Gyro PID Programming
What are your PID gains?
|
Re: Gyro PID Programming
Quote:
|
Re: Gyro PID Programming
Quote:
|
Re: Gyro PID Programming
True, but if the setpoint is ever anything but zero, it may not take the shortest route.
|
Re: Gyro PID Programming
Quote:
But if it were, just correct the angle_error instead and use setpoint = angle_error; process_variable = 0; or setpoint = 0; process_variable = - angle_error; |
Re: Gyro PID Programming
Thank you very much for your comments!
[+] About the PID Gains, I'm totally clueless as to what to set them to, so I just set the P variable to 0.1 and zeroed out the others. (Perhaps this was causing the unexpected results when I directly used the Gyro as input, because the output was always @ 100% all the time); Could I set them to something more appropriate? [+] Should my current method work when I fix the Angle correction routine? or should I use the 2-PIDControllers method? It sounds odd to me that two PIDControllers could 'collaborate' together, when running independently. |
Re: Gyro PID Programming
Quote:
|
Re: Gyro PID Programming
OK. I would still like to know about tuning the PID Gains.
|
Re: Gyro PID Programming
Quote:
As Ether suggested, -180 to 180 range, that may be a little high. It would only take an error of 10 degrees to create full motor output. So, get the input corrected to match the suggested range. This isn't just scaling or constraining, btw. You will need to add or subtract the extra turns if they are in there (fmod). Make sure your setpoint is in the same terms as the input, degrees. And then start tuning your p gain. Don't worry about the others for now. |
| All times are GMT -5. The time now is 12:43. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi