fix: correct yaw inversion in web UI (P0 #38)

Remove erroneous negate on targetYaw — yaw was spinning opposite to
physical rotation. Update resetYaw() formula to match (+ instead of -).
Pitch and roll were unaffected.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
sl-firmware 2026-02-28 21:51:29 -05:00
parent f867956b43
commit 36abbde93a

View File

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