There is more than one axis that you can use to measure rotational speed. The axis you will be most concerned with is yaw, or measuring turns to the left and right. You can also measure if Zumi is tilting forward and backward or tilting left and right. These three axes are called roll, pitch, and yaw.
There are three codes below reading all three axes: X, Y, and Z. Run each one and check Zumi’s screen to see how the angles are affected. Can you match X, Y, and Z with roll, pitch, and yaw? Make sure you start the code with Zumi flat on the ground before picking her up.
X-angle
In [ ]:
zumi.reset_gyro()
for i in range(0,50):
current_angle = int(zumi.read_x_angle())
message = " X-Angle reading "
message = message + str(current_angle)
screen.draw_text(message)
time.sleep(0.05)
print("Done")
screen.draw_text_center("Done")
Y-angle
zumi.reset_gyro()
for i in range(0,50):
current_angle = int(zumi.read_y_angle())
message = " Y-Angle reading "
message = message + str(current_angle)
screen.draw_text(message)
time.sleep(0.05)
print("Done")
screen.draw_text_center("Done")
Z-angle
zumi.reset_gyro()
for i in range(0,50):
current_angle = int(zumi.read_z_angle())
message = " Z-Angle reading "
message = message + str(current_angle)
screen.draw_text(message)
time.sleep(0.05)
print("Done")
screen.draw_text_center("Done")
Based on the data, could you figure out which directions correspond to X, Y, and Z?
For the purposes of driving, you will care the most about the Z-axis, or yaw, of Zumi’s gyroscope. Calling zumi.read_z_angle() will return the number of degrees you have turned from when you started your code. You will be using this in later programs.