using the pid module

good evening

I’m a mentor of a rookie team and everything is going well by now.
But we’re trying to use a PID to self-balance the robot in the ramp using a Gyro to do so with no luck.

Can somebody give me an advise for it??

Thanks in advance.

Because I could not tell from your post, I am assuming that you have no prior knowledge of PID.

First of all, I would suggest using the accelerometer and not the gyro to balance your robot. Search Chief Delphi or the NI FRC examples to determine how that works, there is plenty of material available.

As far as PID goes, there are several inputs to that you must provide in order to get an output. Fist is the process variable, this is the sensor reading (filterer, scaled or unfiltered. You just have to experiment to figure out which gives you the cleanest results). Then you have the setpoint which is the value that you want your process variable to go to. Make sure that any scaling that you do to the PV (process variable), you also do to to setpoint. Then you have something along the lines out output range which is generally -1,1] or [0,1], depending if you want your motor to run backwards to slow itself down. (You would probably want [0,1].

Then the most interesting part, the PID gains. You need to create a cluster control or constant which then has 3 inputs. The P, I and D coefficients. Changing these coefficents is known as tuning the PID loop. Search Chief Delphi on how to do this, there is a lot of good advice out there.

Finally, you can use the output of the PID function to control your motor speed.

Honestly the hardest parts of this is A) getting a clean enough input and B) getting the PID gains set correctly. If you find that the gains are at the very bottom of the accepted input values (ex. P=.001 is still unstable), try dividing both the PV and setpoint by 10 or 100. Then you can change P to .01 or .1 respectively. Then go from there.

Hope this helps

We are going to try this but have not gotten around to it yet. Is the gyro working by itself? Note that it needs to be mounted vertically (in the X-Z plane) to accomplish your task. Are you using LabView or C++ or Java?

The basic approach is to use the gyro as the feedback (with the level setting as the setpoint) and your wheels as the actuator. Set the proportional gain very low - make sure the robot is moving in the correct direction. Then slowly raise the gain till you get a good rate of closure on the setpoint. Use the D gain for dampening any oscillation you get around the setpoint and the I gain for fine tuning the final position (where the servo settles). I suspect you might need no D gain since weight of the robot itself dampens the servo.