Determine robot orientation with a compass

A compass uses the earth’s magnetic field to determine the heading of the robot.

Placement Notes

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.

HiTechnic Compass

HiTechnic Compass

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.

Code Example

Code Example

The compass is constructed by passing in the Digital Module number that it is connected to. The current heading of the compass can then be retrieved by calling getAngle() in Java or GetAngle() in C++.