Determine robot orientation with a compass
A compass uses the earth’s magnetic field to determine the heading of the robot.
This field is relatively weak causing the compass to be susceptible to interference from other magnetic fields such as those generated by the motors and electronics on your robot. If you decide to use a compass, be sure to mount it far away from interfering electronics and verify its accuracy.
WPILib directly supports one compass, the HiTechnic Compass. This part connects to the I2C port on the Digital Sidecar. It is important to note that there is only one I2C port on each of these modules.