Self-Balancing Robot
User Guide
20
www.terasic.com
July 12, 2018
The data register of the MPU-6500 is a 16-bit register, as the MSB is sign bit, the output range of
the data register is -7FFF~7FFF, same as -32767~32767 in decimal format: See the diagram as
below, if the full-scale range of ±2000 degrees/sec is selected, that means -32767 corresponding to
-2000(°/s)
and 32767 is corresponding to 2000(°/s). While reading out the value of gyroscope as
1000, the corresponding angular rate can be computed as below: 32767/2000 =1000/x; As x =
16.4
(
°/s
),
The corresponding Sensitivity Scale Factor is 16.4 LSB/(°/s) in the manual. It is able to
compute the angular rate as the same way if selecting the other ranges.
Figure 1- 15 MPU-6500 datasheet-Gyroscope Specifications
Finally, send the Angle value obtained from the accelerometer and gyroscope the kalman filter
function, to obtain the Angle of the car body with a smaller error.
Angle_Balance=kalman.getAngle(x_angle,-gy);
When dealing with the turning of the body, the system needs to refer to the angular speed of the z
axis.
Gyro_Turn=gz;
The parameters above will be provided to system for balance PID(Proportional–Integral–Derivative)
controlling to feed back the actual condition of the body to achieve a balanced state.