which sensor to use

we want to be able to get the angle of a sensor mounted onto the robot, and aren’t sure which sensor to use. We tried the gyro but there are some flaws (such as it infinitly going up after we turn in circles). What should we use?

This sounds more like a software error than a sensor error. Have you verified you’re getting the correct voltage from the gyro? How does the sensor output feed back into your control loop? Are you trying to measure absolute angle, or angular rate of change? The rotary magnetic encoder will measure absolute angle. The gyro is only good for rate of change. If you’re trying to measure the angle of a mechanism on the robot, like arm tilt or turret pan, a multi-turn potentiometer might be good for this.

we want to measure the absolute angle of the robot itself. so a potentiometer would be good?

The angle of the robot relative to what? The field? I don’t know of a way to do this, except maybe to use a potentiometer or the rotary magnetic encoder on a follower wheel - but that will have issues depending on your drivetrain.

What our team usually does is to assume the robot starts aligned with the field at power-up and integrate all the rate-of-change inputs from the gyro over time to get an absolute rotation. Note that the gyro will tend to drift a bit over time, and you’ll probably want a driver station button to reset the baseline gyro output (that is, the voltage reading from the gyro which the software interprets as zero rate of change).

we want to be able to read the angle of the robot relative to horizontal so when we go on the bridge, it will balance itself. we got it to work, but we have to reset it before and i didn’t know if there was a better way

Ah, you want to measure tilt angle. The accelerometer (on the same board as the gyro, but with a separate digital interface) will work well for that. Keep in mind that the vector magnitude will be higher than 1G while the robot is moving, so you may need to compensate for that.

so there really is no “perfect” sensor to use?

For measuring tilt? A multi-axis accelerometer is the only reasonable choice. But no single sensor is “perfect”. If you want the best possible information about the robot and its environment, you have to use many different sensors and a good algorithm for combining imprecise, noisy, and sometimes contradictory signals.