fix: IMU axis mapping for CW270 orientation (#15) #20

Merged
seb merged 1 commits from sl-firmware/fix-axis-orientation into main 2026-02-28 17:28:57 -05:00
Collaborator

Summary

The MAMBA F722S mounts the MPU6000 at CW270 (clockwise 270°). This applies rotation matrix R = [[0,1,0],[-1,0,0],[0,0,1]] (Betaflight convention) to transform sensor axes to board axes.

Firmware (mpu6000.c)

Before (wrong) After (correct) Reason
accel_pitch atan2(ax, az) atan2(ay, az) board_forward = sensor_Y after CW270
accel_roll atan2(ay, az) atan2(-ax, az) board_right = -sensor_X after CW270
gyro_pitch_rate +raw.gx -raw.gx board_gy = -sensor_gx (R[1,·]·ω_sensor)
gyro_roll_rate raw.gy raw.gy board_gx = sensor_gy ✓ unchanged
gyro_yaw_rate raw.gz raw.gz unchanged ✓

UI (index.html) rotation sign fixes

  • pitch → +rotation.x: correct — Three.js +x tilts nose up ✓
  • roll → -rotation.z: Three.js +z = CCW from camera = left bank; right-bank-positive convention requires negation
  • yaw → -rotation.y: Three.js +y = CCW from above; sensor_Z points down on MAMBA (az ≈ +1g when level), so gz+ = CW physical rotation; negate so model spins correctly

Test plan

  • Level FC: pitch=0°, roll=0°, yaw=0° in HUD
  • Tilt nose forward: PITCH goes positive, model tips forward
  • Tilt right side down: ROLL goes positive, model banks right
  • Rotate CW from above: YAW increases, model spins CW
  • YAW RESET zeroes the display

Closes #15.

## Summary The MAMBA F722S mounts the MPU6000 at CW270 (clockwise 270°). This applies rotation matrix `R = [[0,1,0],[-1,0,0],[0,0,1]]` (Betaflight convention) to transform sensor axes to board axes. ## Firmware (`mpu6000.c`) | | Before (wrong) | After (correct) | Reason | |---|---|---|---| | `accel_pitch` | `atan2(ax, az)` | `atan2(ay, az)` | board_forward = sensor_Y after CW270 | | `accel_roll` | `atan2(ay, az)` | `atan2(-ax, az)` | board_right = -sensor_X after CW270 | | `gyro_pitch_rate` | `+raw.gx` | `-raw.gx` | board_gy = -sensor_gx (R[1,·]·ω_sensor) | | `gyro_roll_rate` | `raw.gy` | `raw.gy` | board_gx = sensor_gy ✓ unchanged | | `gyro_yaw_rate` | `raw.gz` | `raw.gz` | unchanged ✓ | ## UI (`index.html`) rotation sign fixes - **pitch → `+rotation.x`**: correct — Three.js `+x` tilts nose up ✓ - **roll → `-rotation.z`**: Three.js `+z` = CCW from camera = left bank; right-bank-positive convention requires negation - **yaw → `-rotation.y`**: Three.js `+y` = CCW from above; sensor_Z points down on MAMBA (`az ≈ +1g` when level), so `gz+` = CW physical rotation; negate so model spins correctly ## Test plan - [ ] Level FC: pitch=0°, roll=0°, yaw=0° in HUD - [ ] Tilt nose forward: PITCH goes positive, model tips forward - [ ] Tilt right side down: ROLL goes positive, model banks right - [ ] Rotate CW from above: YAW increases, model spins CW - [ ] YAW RESET zeroes the display Closes #15.
sl-firmware added 1 commit 2026-02-28 17:23:20 -05:00
The MAMBA F722S mounts MPU6000 at CW270 (clockwise 270°) which applies
rotation matrix R = [[0,1,0],[-1,0,0],[0,0,1]] to transform sensor axes
to board axes (Betaflight convention).

Firmware (mpu6000.c):
- accel_pitch: was atan2(ax, az) → now atan2(ay, az)
  board_forward = sensor_Y, so ay drives pitch not ax
- accel_roll: was atan2(ay, az) → now atan2(-ax, az)
  board_right = -sensor_X, so -ax drives roll not ay
- gyro_pitch_rate: was +raw.gx → now -raw.gx
  board_gy (pitch) = -sensor_gx after R_CW270 transform
- gyro_roll_rate: raw.gy unchanged (board_gx = sensor_gy ✓)
- gyro_yaw_rate: raw.gz unchanged ✓

UI (index.html) rotation sign fixes:
- roll  → -rotation.z: Three.js +z = CCW from camera = left bank;
  our convention is right-bank-positive so negate
- yaw   → -rotation.y: Three.js +y = CCW from above; sensor_Z points
  down on MAMBA (az ≈ +1g when level) so gz+ = CW physical; negate
- pitch → +rotation.x: correct as-is (Three.js +x tilts nose up ✓)

Closes #15.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
seb approved these changes 2026-02-28 17:28:56 -05:00
seb left a comment
Owner

Flash-tested, all axes streaming correctly.

Flash-tested, all axes streaming correctly.
seb merged commit c882467e1b into main 2026-02-28 17:28:57 -05:00
Sign in to join this conversation.
No Reviewers
No Label
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: seb/saltylab-firmware#20
No description provided.