Attempt to fix roll correction
This commit is contained in:
22
web/app.js
22
web/app.js
@@ -488,7 +488,7 @@ function onDisconnected() {
|
||||
|
||||
// ── IMU Stream + Visualiser ──────────────────────────────────────────────────
|
||||
// ImuPacket (14 bytes LE):
|
||||
// int16 gyroY_mDPS [0], int16 gyroZ_mDPS [2]
|
||||
// int16 gyroX_mDPS [0], int16 gyroZ_mDPS [2]
|
||||
// int16 accelX_mg [4], int16 accelY_mg [6], int16 accelZ_mg [8]
|
||||
// int8 moveX [10], int8 moveY [11], uint8 flags [12], uint8 pad [13]
|
||||
const canvas = document.getElementById('vizCanvas');
|
||||
@@ -593,10 +593,10 @@ function parseImuStream(dv) {
|
||||
return;
|
||||
}
|
||||
|
||||
let gyroY, gyroZ, accelX, accelY, accelZ, moveX, moveY, flags;
|
||||
let gyroX, gyroZ, accelX, accelY, accelZ, moveX, moveY, flags;
|
||||
try {
|
||||
gyroY = view.getInt16(0, true);
|
||||
gyroZ = view.getInt16(2, true);
|
||||
gyroX = view.getInt16(0, true); // GX = pitch axis (nod → cursor Y)
|
||||
gyroZ = view.getInt16(2, true); // GZ = yaw axis (pan → cursor X)
|
||||
accelX = view.getInt16(4, true);
|
||||
accelY = view.getInt16(6, true);
|
||||
accelZ = view.getInt16(8, true);
|
||||
@@ -608,9 +608,9 @@ function parseImuStream(dv) {
|
||||
const single = !!(flags & 0x02);
|
||||
const dbl = !!(flags & 0x04);
|
||||
|
||||
// Axis bars: show raw gyro (firmware convention: Z→screen-X, Y→screen-Y)
|
||||
// Axis bars: show raw gyro (firmware convention: Z→screen-X, X→screen-Y)
|
||||
updateAxisBar('gy', -gyroZ, 30000);
|
||||
updateAxisBar('gz', -gyroY, 30000);
|
||||
updateAxisBar('gz', -gyroX, 30000);
|
||||
|
||||
if (!idle) {
|
||||
// moveX/moveY are already roll-corrected by firmware — use them directly
|
||||
@@ -626,7 +626,7 @@ function parseImuStream(dv) {
|
||||
if (dbl) flashTap('Right');
|
||||
drawViz(idle);
|
||||
|
||||
orientFeedIMU(accelX, accelY, accelZ, gyroY, gyroZ);
|
||||
orientFeedIMU(accelX, accelY, accelZ, gyroX, gyroZ);
|
||||
}
|
||||
|
||||
function updateAxisBar(axis, val, max) {
|
||||
@@ -743,7 +743,7 @@ function orientUpdateColors() {
|
||||
if (orientEdges) orientEdges.material.color.setHex(c);
|
||||
}
|
||||
|
||||
function orientFeedIMU(ax, ay, az, gyY_mDPS, gyZ_mDPS) {
|
||||
function orientFeedIMU(ax, ay, az, gyX_mDPS, gyZ_mDPS) {
|
||||
if (!orientRenderer) return;
|
||||
const now = Date.now();
|
||||
const dt = orientLastT ? Math.min((now - orientLastT) / 1000, 0.1) : 0.05;
|
||||
@@ -769,9 +769,9 @@ function orientFeedIMU(ax, ay, az, gyY_mDPS, gyZ_mDPS) {
|
||||
qAccel.copy(orientQ);
|
||||
}
|
||||
|
||||
// Gyro integration — firmware sends gyroY (pitch) and gyroZ (yaw), mDPS
|
||||
// Map to Three.js axes: gyroZ→world Y, gyroY→world X
|
||||
const gyRad = gyY_mDPS * (Math.PI / 180) / 1000;
|
||||
// Gyro integration — firmware sends gyroX (pitch) and gyroZ (yaw), mDPS
|
||||
// Map to Three.js axes: gyroZ→world Y, gyroX→world X
|
||||
const gyRad = gyX_mDPS * (Math.PI / 180) / 1000;
|
||||
const gzRad = gyZ_mDPS * (Math.PI / 180) / 1000;
|
||||
const dq = new THREE.Quaternion(
|
||||
gyRad * dt * 0.5, // x
|
||||
|
||||
Reference in New Issue
Block a user