Welcome to Muto RS Robot repository
10)Read data
10.Read data
10.Read data1. Experimental goals2. Experiment preparation3. Experiment procedure4. Experiment summary
1. Experimental goals
This course mainly learns how to read the robot's battery power, servo angle, IMU data and other parameters.
2. Experiment preparation
The functions of the Muto robot Python library involved in this course are as follows:
read_version():Read the underlying firmware version number. If the read is successful, the version number will be returned. If the read fails, None will be returned.
read_battery(voltage=True):Read the battery power. The optional parameter voltage=True returns the voltage value, and voltage=False returns the battery percentage.
read_motor():Read eighteen servo angle values. An array is returned if the read is successful, and None is returned if the read fails.
read_leg(leg_id): Read the angle of the servo on a certain leg. The value range of the parameter leg_id is [1-6], which means leg1~leg6. An array is returned if the read is successful, and None is returned if the read fails.
read_IMU(): Read the angle after IMU fusion. If the reading is successful, an array [roll, pitch, yaw, temp] will be returned. If the reading fails, None will be returned.
read_IMU_Raw(): Read the original data of the IMU. If the reading is successful, an array [accX, accY, accZ, gyroX, gyroY, gyroZ, magX, magY, magZ] will be returned. If the reading fails, None will be returned.
3. Experiment procedure
Open the jupyterLab client and find the code path:
xmuto/Samples/Control/10.read_data.ipynb
Read and print the version number:
xxxxxxxxxxversion = g_bot.read_version()print("version:", version)
Read and print battery voltage:
xxxxxxxxxxbattery = g_bot.read_battery()print("battery:%.1fV" % battery)
Read and print 18 servo angle values. Since the servo is subject to factors such as pressure and conversion accuracy, there may be a certain error between the read angle and the actual angle. A deviation of ±3° from the actual angle is normal.
xxxxxxxxxxangle = g_bot.read_motor()print("angle:", angle)
Read and print the three servo angles on leg 1. Since the servo will be subject to factors such as pressure and conversion accuracy, there may be a certain error between the read angle and the actual angle. A deviation of ±3° from the actual angle is normal.
xxxxxxxxxxleg_id = 1leg_angle = g_bot.read_leg(leg_id)print("leg_angle:", leg_angle)
Read and print the IMU fused data:
xxxxxxxxxximu = g_bot.read_IMU()print("imu:", imu)
Read and print IMU raw data:
xxxxxxxxxximu_raw = g_bot.read_IMU_Raw()print("imu_raw:", imu_raw)
4. Experiment summary
Example of reading the battery voltage value. If you need to read the battery percentage, you can pass the parameter False.

Example of reading the angle values of 18 servos:
Example of reading the angle after IMU fusion:
