Merge pull request 'fix: Yaw inversion in web UI (P0 #38)' (#40) from sl-firmware/yaw-fix into main

This commit is contained in:
seb 2026-02-28 21:57:54 -05:00
commit c6b7d5cadd

View File

@ -195,11 +195,10 @@ window.updateIMU = function(data) {
// pitch → rotation.x positive = nose up (Three.js +x rotates -Z end upward ✓)
// roll → -rotation.z positive = right bank (Three.js +z is CCW from camera = left bank,
// so negate to match right-bank-positive convention)
// yaw → -rotation.y positive = CW from above (Three.js +y is CCW, sensor Z points down
// so gz+ = CW physical; negate so model spins correctly)
// yaw → +rotation.y positive = CW from above (Three.js +y = CCW but gz sign matches)
targetPitch = pitch * Math.PI / 180;
targetRoll = -roll * Math.PI / 180; // negate: Three.js +z = left bank, we want right bank+
targetYaw = -yaw * Math.PI / 180; // negate: Three.js +y = CCW, sensor gz+ = CW
targetYaw = yaw * Math.PI / 180; // no negate: measured yaw matches Three.js rotation.y
document.getElementById('v-pitch').textContent = pitch.toFixed(1);
document.getElementById('v-roll').textContent = roll.toFixed(1);
@ -274,9 +273,9 @@ function animate() {
animate();
window.resetYaw = function() {
// Capture current raw firmware yaw (before negate) as new zero reference.
// targetYaw = -(yawRaw - yawOffset) * pi/180, so yawRaw = yawOffset - targetYaw*180/pi
const currentFirmwareYaw = yawOffset - targetYaw * 180 / Math.PI;
// Capture current raw firmware yaw as new zero reference.
// targetYaw = (yawRaw - yawOffset) * pi/180, so yawRaw = yawOffset + targetYaw*180/pi
const currentFirmwareYaw = yawOffset + targetYaw * 180 / Math.PI;
yawOffset = currentFirmwareYaw;
targetYaw = 0;
};