Compass and orientation sensor