Product Introduction
Steering with the Modern Robotics gyro – an introduction
v4 dated 1/22/16, clarified heading directions
v3 dated 1/20/16, added new signed heading
v2 dated 12/11/15
This article is a low-tech introduction to steering a robot autonomously using the new
Modern Robotics Integrating Gyro sensor. The focus here is learning, rather than simply
providing copy-and-paste code. Examples are given mostly in pseudocode which can be
adapted for languages such as Java, RobotC, C++, etc.
The MR gyro sensor gives rate of rotation about X, Y and Z axes. It also performs an on-
board calculation (integration) to give the current heading about the vertical Z axis. This
article discusses only the heading value, for steering. It’s an integer value in degrees,
initialized to zero at calibration, where zero is straight ahead (I2C cable at the back).
For simplicity, this tutorial has heading values increase with clockwise (CW) sensor
rotation, looking down from above. This is true only when using basic headings obtained
with the default/generic gyro command. See the end of Section 11 for actual directions.
The sensor should be placed horizontal (parallel to the ground), close to the robot’s center
of rotation, and as low as possible. Convenient access is not required, although it helps to
see its glowing LED to indicate the sensor is connected.
1. Heading Values
The sensor can give two types of heading value. The basic heading type ranges only
from 0 to 359 degrees, never a negative number. So, continuous CW rotation from zero
gives positive values that increase to 359 degrees, then jump back to zero.
Counterclockwise (CCW) rotation from zero immediately jumps to 359 degrees, then 358,
and so on.
The other type is a signed heading that can be positive or negative, and extends without
limit. So, counterclockwise (CCW) rotation from zero gives negative values such as -1
degree, then -2 degrees, and so on. And there’s no rollover at 360 degrees, so two full
CW rotations would result in a heading of +720 degrees.
For both types of headings, turning actions accumulate, unless the sensor is purposely
reset to zero. If the sensor rotates CW 30 degrees from zero, then rotates CCW 10
degrees, the heading value will now read +20 degrees. But when the sensor rotates
through zero, you must be aware of the adding and subtracting process. If the sensor
rotates CW 10 degrees, then rotates CCW 30 degrees, the two heading types will give
different results. The basic heading will be 340 degrees, while the signed heading will be
-20 degrees.
Just choose the type of heading that you prefer, become familiar with its math, and stick
with it. They have different characteristics for autonomous driving, as you will see below.
In general the basic heading needs more managing, covered by Sections 3 and 5.