Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix acceleration adjustement and add to visualizer #804

Merged
merged 4 commits into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 33 additions & 3 deletions gui/src/components/widgets/IMUVisualizerWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ import { Typography } from '../commons/Typography';
import { formatVector3 } from '../../utils/formatting';
import { Canvas, useLoader } from '@react-three/fiber';
import * as THREE from 'three';
import { PerspectiveCamera } from 'three';
import { PerspectiveCamera, Vector3 } from 'three';
import { Button } from '../commons/Button';
import { QuatObject } from '../../maths/quaternion';
import { useLocalization } from '@fluent/react';
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader';
import { Vector3Object } from '../../maths/vector3';

const groundColor = '#4444aa';

Expand All @@ -25,10 +26,12 @@ export function TrackerModel({ model }: { model: string }) {
}

function SceneRenderer({
quat: { x, y, z, w },
quat,
vec,
model,
}: {
quat: QuatObject;
vec: Vector3Object;
model: string;
}) {
return (
Expand All @@ -41,11 +44,33 @@ function SceneRenderer({
>
<ambientLight intensity={0.5} />
<spotLight position={[20, 20, 20]} angle={0.09} penumbra={1} />
<group quaternion={new THREE.Quaternion(x, y, z, w)}>
<group quaternion={new THREE.Quaternion(quat.x, quat.y, quat.z, quat.w)}>
<TrackerModel model={model}></TrackerModel>
<axesHelper args={[10]} />
</group>

<arrowHelper
args={[
new Vector3(-Math.sign(vec.x), 0, 0),
new Vector3(0, 0, 0),
Math.sqrt(Math.abs(vec.x)) * 2,
]}
/>
<arrowHelper
args={[
new Vector3(0, Math.sign(vec.y), 0),
new Vector3(0, 0, 0),
Math.sqrt(Math.abs(vec.y)) * 2,
]}
/>
<arrowHelper
args={[
new Vector3(0, 0, -Math.sign(vec.z)),
new Vector3(0, 0, 0),
Math.sqrt(Math.abs(vec.z)) * 2,
]}
/>

<mesh position={[0, -3, 0]} rotation={[-Math.PI / 2, 0, 0]}>
<planeGeometry args={[50, 50, 10, 10]} />
<meshBasicMaterial
Expand Down Expand Up @@ -82,6 +107,10 @@ export function IMUVisualizerWidget({ tracker }: { tracker: TrackerDataT }) {
tracker?.rotationIdentityAdjusted ||
tracker?.rotation ||
new THREE.Quaternion();
const vec =
tracker?.linearAcceleration ||
tracker?.rawAcceleration ||
new THREE.Vector3();

return (
<div className="bg-background-70 flex flex-col p-3 rounded-lg gap-2">
Expand Down Expand Up @@ -127,6 +156,7 @@ export function IMUVisualizerWidget({ tracker }: { tracker: TrackerDataT }) {
</Button>
<SceneRenderer
quat={{ ...quat }}
vec={{ ...vec }}
model={
isExtension ? '/models/extension.gltf' : '/models/tracker.gltf'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,15 +292,14 @@ class Tracker @JvmOverloads constructor(
}

/**
* Gets the adjusted tracker acceleration after mounting corrections.
* Gets the world-adjusted acceleration
*/
fun getAcceleration(): Vector3 {
var vec = acceleration
if (needsReset) {
vec = resetsHandler.getMountingAdjustedRotationFrom(rotation).sandwich(vec)
return if (needsReset) {
resetsHandler.getReferenceAdjustedAccel(rotation, acceleration)
} else {
acceleration
}

return vec
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,10 @@ class TrackerResetsHandler(val tracker: Tracker) {
}

/**
* Takes a rotation and adjusts it to mounting
* Get the adjusted accel from yawFixZeroReference
*/
fun getMountingAdjustedRotationFrom(rotation: Quaternion): Quaternion {
return rotation * mountingOrientation * mountRotFix
fun getReferenceAdjustedAccel(rawRot: Quaternion, accel: Vector3): Vector3 {
return (adjustToReference(rawRot) / yawFix).sandwich(accel)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import io.eiren.util.Util
import io.eiren.util.collections.FastList
import io.eiren.util.logging.LogManager
import io.github.axisangles.ktmath.Quaternion.Companion.fromRotationVector
import io.github.axisangles.ktmath.Vector3
import org.apache.commons.lang3.ArrayUtils
import solarxr_protocol.rpc.ResetType
import java.net.DatagramPacket
Expand Down Expand Up @@ -276,7 +277,7 @@ class TrackersUDPServer(private val port: Int, name: String, private val tracker
tracker = connection?.getTracker(packet.sensorId)
if (tracker == null) return
var rot17 = packet.rotation
rot17 = AXES_OFFSET.times(rot17)
rot17 = AXES_OFFSET * rot17
when (packet.dataType) {
UDPPacket17RotationData.DATA_TYPE_NORMAL -> {
tracker.setRotation(rot17)
Expand All @@ -297,7 +298,8 @@ class TrackersUDPServer(private val port: Int, name: String, private val tracker
is UDPPacket4Acceleration -> {
tracker = connection?.getTracker(packet.sensorId)
if (tracker == null) return
tracker.setAcceleration(packet.acceleration)
// Switch x and y around to adjust for different axes
tracker.setAcceleration(Vector3(packet.acceleration.y, packet.acceleration.x, packet.acceleration.z))
}
is UDPPacket10PingPong -> {
if (connection == null) return
Expand Down