Gyroscopes and Accelerometers
The XRP has a built-in Inertial Measurement Unit, often abbreviated as an IMU. The IMU has a built-in gyroscope and a built-in accelerometer.
You might be wondering, what is an accelerometer? And what is a gyroscope?
Accelerometers
An accelerometer is a device that tracks an objects' acceleration. It does this by measuring a tiny block inside the device, attached onto a spring. Using some complex math with these devices, it determines the acceleration by how much the block lags behind when moving.
The syntax to access the accelerometer is this. Notice how there is no parameter needed.
private BuiltInAccelerometer accelerometer = new BuiltInAccelerometer();The accelerometer has three methods, getX(), getY() and getZ(). All three of these methods return the robot's acceleration on the X, Y, and Z axis respectively. However- the unit is in G-Forces, which is the Earth's gravity on its surface, or 9.81 meters/sec.
You might be wondering why are the units in G-Forces? This is because the accelerometer is incredibly sensitive, and always takes in account the Earth's gravitational pull.
Gyroscopes
A gyroscope is a device that detects an object's current orientation, on all axis of rotation. Similarly to the accelerometer, the robot has a built-in gyroscope. The three axis of rotation the gyroscope is watching for are roll, pitch and yaw- essentially the rotations around the X axis, the Y axis, and Z axis respectively.
If you look at the graph, you might notice that revolving around the x-axis is roll, revolving around the y-axis is yaw and revolving around the z-axis is pitch. We will use this later.
private XRPGyro gyro = new XRPGyro();When referencing the gyroscope for the first time, make sure to reset the gyroscope using gyro.reset(). This tells the gyroscope that the current direction it is facing is zero.
Like the accelerometer, the gyroscope has three methods, getAngleX(), getAngleY() and getAngleZ(). These work the same way as tbe methods from the accelerometer, except that they give you the degrees of roll, yaw and pitch respectively. These are in degrees, from 0 to 360.
Last updated