Greetings from Team 34’s rookie programmer. We could never get our vision code to fully work. We tried to use GRIP, but couldn’t get our values fast enough to auto-align, and had too much trouble to try to run it on a raspberry pi, I read that you should convert your vision values to gyro and use a PID, but I don’t know the first thing about how to effectively use a PID. How did you guys do your vision code? We also use LabVIEW.
Turning the robot with a PID doesn’t have to be that mysterious.
You need a gyro, wired and opened in the SW to give you a decent electronic compass. Go ahead and put a chart or a gauge on the panel to show the value from the gyro. This will work on either teleOp or Periodic tasks.
With your vision algorithm, identify what you want your robot’s new heading should be in order to point at the target. Note that you can also isolate this from the vision by making a button on the panel just add a fixed amount, like 10 degrees, to the desired heading.
When you want the robot the robot to turn, it might be nice to drive it by hand and watch the joystick values to identify some things. Most likely, if you put the robot in teleOp and use the joystick to turn, you will find that a small joystick value will not move the robot, it will only make a whine or groan sound. You may have to push the joystick 30% or more in order for the robot to start turning. Also identify a maximum joystick value that you would ever want to send to the motors.
Next, in your loop where you are measuring the gyro, drop a PID VI to the code and wire the measured gyro value into the PID’s Process Variable. Connect the desired heading to the Setpoint input of PID. Create a constant for Output Range and set it to the positive and negative maximum value you identified in the interactive step above.
Finally, create a control for the PID gains input. They will default to (1, 0, 0) which is likely an OK place to start.
The next part is the fun/challenging part. Put the robot into a safe location that resembles the field. Meaning you probably want it on carpet similar to the field. Then push your button to update the set point. If the robot doesn’t receive enough power to turn, disable the robot, double the P coefficient, and test again.
If the robot drives too quickly and overshoots wildly, disable it and lower P. Once you have a value too high and too low, average them and try that value. Keep testing safely until the robot turns predictably to the angle.
If the robot happens to turn the wrong way, change the sign of both output range values.
Most likely, you will fiddle with P a bit and find a value that “tunes” the turn, but sometimes it is a bit trickier. Sometimes it is useful to ensure that the output value has a minimum value. The attached image shows how to preserve the sign, but make sure the value is at least 0.2.
The final step, probably not necessary for turning the robot, is to an I parameter to help get rid of small residual errors. This is the more traditional alternative to the minimum value approach above. And a D value would help to turn the robot faster without overshooting. These last two coefficients are needed on some control problems, but often not needed.
There are many good tutorials on how to do this on youtube and other web pages.
As for the vision issue. If you have issues with GRIP, you might want to look at the vision tutorial for LV. You only need to use either one of them to read and calculate the angle one time. Then turn with the gyro.
Greg McKaskle