XRP Gyro Inconsistent/Wrong Axis Directions Between MicroPython and FRC WPILib

List of References and Links

Google doc of referenced links and images

Note: I had to put all images and links in a Google doc since I couldn’t make a post with more than one image and link as a new member.

1) XRP Gyro Directions in WPILib inconsistent with WPILib NWU Axis Convention

My XRP’s gyroscope seems to have incorrect and inconsistent axes directions for its X, Y, and Z angle values. If the front of the XRP is defined as the direction which the ultrasonic sensor is facing, then when measuring the axis angles using Java in the WPILib Simulation

  • The x-axis on my XRP is pointing to the right of the robot
  • The y-axis is pointing towards the front of the robot
  • The z-axis is pointing up from the robot

The described axes directions is consistent with the axes directions displayed on the axis image on the microcontroller itself (see image below). However, these axes directions are inconsistent with the NWU axis convention used by the WPILib (See Figure 1 in attached Google Doc).

2) Angle Values Have Strange Values

When using WPILib to simulate code on the XRP, something else my robot does that is strange is that the initial z-axis value after boot-up and calibration is reported as 180 degrees. As in, the gyroscope is reporting that the back of the robot is 0 degrees (another interpretation is that the gyroscope has a 180 degree offset in the z-direction). However, the important bit is that it is strange that the gyroscope is reporting any sort of nonzero value for the z-angle at all, since it really should be measuring an angle of 0 right after boot-up and calibration.

(As a technicality, the offset is actually a 90 degree offset since angles are conventionally measured from the +x-axis with counterclockwise positive, and we had previously established that the +x-axis was to the right of the robot, with the positive y-axis running towards the front of the robot.)

With the robot facing you, rotating it with a positive roll makes the y-axis angle values also go from 0 to 90 degrees, but back to 0 degrees again (when the robot is flipped upside down so that the battery case is facing upwards). Continuing to flip the robot in the same direction results in angles going from 0 to negative 90, and then back to 0 again when the robot is facing up again. See Figure 2 in attached Google doc.

3) Differences when Using MicroPython

The inconsistencies don’t stop there though. When using the XRP Micropython IDE, when printing the roll, pitch, and yaw values of the IMU, I found that the axes convention when using Micropython was only consistent with the image included in Figure 3 of the Google doc. I’m guessing this is just one convention for pitch/roll/yaw, but it is one I have never seen before as the axis orientation (taking counter clockwise rotation as positive angle) would make the axes inconsistent with the right-hand-rule for coordinate systems (Figure 4 in Google doc). This is inconsistent with both the WPILib’s NWU convention as well as the printed axes convention on the microcontroller (image above). In other words,

  • The roll (assumed x-direction) indicates the axis is pointing towards the front of the robot
  • The pitch (assumed y-direction) indicates the axis is pointing to the right of the robot
  • The yaw (assumed z-direction) indicates the axis is pointing upwards from the robot (again, violating the right-hand-rule for coordinate systems)

4) Questions

Do I have a fundamental misunderstanding about gyro angles, axis orientation, etc.? Is there something I’m missing here? Or is the gyro in the XRP actually just that bad/inconsistent when using WPILib vs MicroPython?

Has anyone else run into this? Or is anyone else able to replicate this?

At the time of this post, the software used was

  • Java in WPILib version 2024.3.2 - See Link 2 in Google Doc
  • XRP WPILib firmware version 1.0.1 - See Link 3 in Google Doc
  • XRP Vendordep Version 1.0.0 - See link 4 in Google Doc
  • MicroPython for RPI Pico W version 1.23.0 - See Link 5 in Google Doc

5) Code Samples

Link to GitHub repo for sample XRP Gyro code in WPILib Java
https://github.com/ktvuwhs/xrp-timed-sandbox-java

MicroPython Code

from XRPLib.defaults import *
import time

imu.calibrate()
while 1:
    print(f'Roll: {imu.get_roll():.2f}      Pitch: {imu.get_pitch():.2f}     Yaw: {imu.get_yaw():.2f}')
    time.sleep_ms(20)