# PID for aiming automatically

I was playing with PID for aiming the robot at the target, but since I can’t test it (robots bagged and tagged) I wanted to check if I did this somewhat right. I programmed in two ways to do it in a case structure with a constant input, so if one doesn’t work I can switch to the other.

the first way: I looked up camera specs and found the axis 206 has 48 degrees of vision. The targets get plotted with x and y position on our image, so I took the xpos and figured if its 48* total, I could say when x=0 that would be 0 degrees, -1=-24, 1=24, ect. Basically multiplied the xpos of the target by 24. This would tell me the degrees to turn. I then converted that into rotations of my wheels by finding how far from center of the robot my wheels were, and the arc length that would turn me that many degrees. From there I did arc length divided by pi6 (circumference of the wheels) to give me number of rotations of the wheels, and then divided that by (6/13) (gearing from wheel sprocket to motors where the encoder is). Then I converted the number of rotations into degrees (divide by 360).

Then for the measured variable, I plugged in our encoders after running that through the formulas to convert it into degrees.

This plugs into two PID blocks, one for the left wheels and one for the right. The set point is divide by two and negated on one of the PID blocks, so one side will move forward and one will move backwards.

The second way:
I thought of this after doing all of the above, and thought it would even give better results. I set the setpoint to 0, and simply just plugged in the xpos from the camera. In my logic, it will just try to center the target on the image, thus aiming the robot.

If screenshots would be helpful, let me know. Would these work?

Either way would work okay if you have quick enough information from the camera. I think the simple way is likely to have problems due to delays in the vision processing, with the feedback lagging the actual robot position.

there wont be a problem with the first one? The way its set up, as the targets get closer to center on the image it changes the set point (which is really the xposition run through formulas to convert into wheel rotations). I thought the setpoint should be static, but I’m not sure.