# Turret Relative Position

Hi,
We built a turret this year and I want to have our turret turn to a home position after being used. We have a Pigeon on the turret and a NavX on the robot they are on the front side of the robot and turret is on the left and the Rio is on the right. I was planning to just subtract robotAngle from turretAngle. Trying this resulted in a very high value around 40-90 degrees. Could this be because of different gyros having different angles per a full rotation. Do you guys have any ideas?

1 Like

Both gyros report angles relative to where they were when they turned on. If your turret is at different angles relative to the base each time you start, that would explain the difference.

You should also make sure that both gyros report positive rotation the same direction.

Not a solution, but a general problem solving strategy:

1. Identify (or create) two variables in your code. One will represent â€śrobot angle relative to fieldâ€ť, and the other will represent â€śturret angle relative to fieldâ€ť
2. What units will each have? What will â€ś0â€ť mean for each? What will positive values mean for each? There are multiple possible correct answers, but you have to pick just one. I like â€śdegreesâ€ť and â€ś0 = straight toward opposing alliance stationâ€ť.
3. Print out the value of the units. SmartDashboard, `System.out.println()`, Shuffleboard, debugger, etc. Get it so you can inspect the value of each variable at runtime.
4. Set the robot on the field, in a certain orientation. Decide, before looking at the values, what you think they should be.
5. Check if the values match your exceptions
6. If yes, pick another orientation, and repeat.
7. If no, start debugging. Which number is wrong? How is it wrong? Just units? Always zero? Correct magnitude, but wrong sign? Random and noisy? Each of these could suggest different root causes.

Once both numbers are behaving as you expect, then and only then do I agree that your general strategy will likely work.

Note that most folks Iâ€™ve talked to used encoders to determine turret orientation, not a gyro. However, i suspect for lots of cases, your solution will be sufficient.

2 Likes

They report both zero when the robot starts. I will check with the orientation and report again.

Also make sure that you know if clockwise is positive or counter clockwise is positive. If you like math, youâ€™d make everything in your code use counter clockwise (CCW) as positive. If you donâ€™t want to create a custom Gyro interface, then clockwise is fine. You just have to make sure when you add/subtract the angles you actually know what they represent.

If you posted code/logic, we may be able to help debug it.

This isnâ€™t really a solution to OPâ€™s current problem, but I see this as an opportunity to discuss the thought process behind sensor selection on robot subsystems (as brought up by @gerthworm).

In the case described, the desired measurement is the angle of the turret relative to a fixed angle on the robot base. Since rotation of the robot base should not change the relative angle, using a gyro on the turret seems like a bit of overkill. I would recommend exploring an encoder or potentiometer-based solution in the future as it will give you stable relative location information.

You may have noticed gyros have a tendency to drift over time so â€śzeroâ€ť will not remain in the same location for very long. Various factors can make the drift better or worse, and all sensors will have different properties. This could lead to the robot IMU and the turret IMU disagreeing over the course of a match.

4 Likes

As @Joe_Ross mentioned, check how the values change as you rotate the robot. The navX and Pigeon are opposite. From the Pigeon docs

Moving counter-clockwise is interpreted as a positive change.

From experience, the navX is the opposite.

1 Like

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.