mirror of
https://github.com/SlimeVR/SlimeVR-Server.git
synced 2026-11-24 02:51:20 -08:00
Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9a891a0323 | ||
|
|
d3b57048e9 | ||
|
|
c8a6e2fc0b | ||
|
|
db68d808dd |
No files matched your search
@@ -46,3 +46,4 @@ local.properties
|
|||||||
|
|
||||||
# Ignore temporary config
|
# Ignore temporary config
|
||||||
vrconfig.yml.tmp
|
vrconfig.yml.tmp
|
||||||
|
*.DS_Store
|
||||||
@@ -110,14 +110,14 @@ export function IMUVisualizerWidget({ tracker }: { tracker: TrackerDataT }) {
|
|||||||
|
|
||||||
const rotationRaw = useRawRotationEulerDegrees();
|
const rotationRaw = useRawRotationEulerDegrees();
|
||||||
const rotationIdent = useIdentAdjRotationEulerDegrees() || rotationRaw;
|
const rotationIdent = useIdentAdjRotationEulerDegrees() || rotationRaw;
|
||||||
const quat =
|
const quat = useMemo(() => {
|
||||||
tracker?.rotationIdentityAdjusted ||
|
return tracker?.rotationIdentityAdjusted || tracker?.rotation || new THREE.Quaternion()
|
||||||
tracker?.rotation ||
|
}, [tracker])
|
||||||
new THREE.Quaternion();
|
|
||||||
const vec =
|
const vec = useMemo(() => {
|
||||||
tracker?.linearAcceleration ||
|
return new Vector3().copy(tracker?.linearAcceleration || tracker?.rawAcceleration || {x: 0, y: 0, z: 0}) // .applyQuaternion(new THREE.Quaternion().copy(quat))
|
||||||
tracker?.rawAcceleration ||
|
}, [tracker, quat])
|
||||||
new THREE.Vector3();
|
|
||||||
const mag =
|
const mag =
|
||||||
tracker?.rawMagneticVector ||
|
tracker?.rawMagneticVector ||
|
||||||
new THREE.Vector3();
|
new THREE.Vector3();
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import dev.slimevr.tracking.trackers.TrackerPosition.Companion.getByDesignation
|
|||||||
import dev.slimevr.tracking.trackers.udp.IMUType
|
import dev.slimevr.tracking.trackers.udp.IMUType
|
||||||
import dev.slimevr.tracking.trackers.udp.MagnetometerStatus
|
import dev.slimevr.tracking.trackers.udp.MagnetometerStatus
|
||||||
import dev.slimevr.tracking.trackers.udp.TrackerDataType
|
import dev.slimevr.tracking.trackers.udp.TrackerDataType
|
||||||
|
import io.eiren.math.FloatMath.INV_SQRT_TWO
|
||||||
import io.eiren.util.BufferedTimer
|
import io.eiren.util.BufferedTimer
|
||||||
import io.github.axisangles.ktmath.Quaternion
|
import io.github.axisangles.ktmath.Quaternion
|
||||||
import io.github.axisangles.ktmath.Vector3
|
import io.github.axisangles.ktmath.Vector3
|
||||||
@@ -383,6 +384,8 @@ class Tracker @JvmOverloads constructor(
|
|||||||
* Gets the world-adjusted acceleration
|
* Gets the world-adjusted acceleration
|
||||||
*/
|
*/
|
||||||
fun getAcceleration(): Vector3 = if (needsReset) {
|
fun getAcceleration(): Vector3 = if (needsReset) {
|
||||||
|
//_acceleration
|
||||||
|
//getAdjustedRotation().sandwich(_acceleration)
|
||||||
resetsHandler.getReferenceAdjustedAccel(_rotation, _acceleration)
|
resetsHandler.getReferenceAdjustedAccel(_rotation, _acceleration)
|
||||||
} else {
|
} else {
|
||||||
_acceleration
|
_acceleration
|
||||||
@@ -453,4 +456,15 @@ class Tracker @JvmOverloads constructor(
|
|||||||
fun resetFilteringQuats(reference: Quaternion) {
|
fun resetFilteringQuats(reference: Quaternion) {
|
||||||
filteringHandler.resetMovingAverage(getAdjustedRotation(), reference)
|
filteringHandler.resetMovingAverage(getAdjustedRotation(), reference)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
/**
|
||||||
|
* Turn 90 degrees around LEFT axis to make the base position of the tracker standing upwards
|
||||||
|
* instead of laying on the back
|
||||||
|
*/
|
||||||
|
private val rotationOffset = Quaternion(INV_SQRT_TWO, -INV_SQRT_TWO, 0f, 0f)
|
||||||
|
fun axisRemap(v: Vector3): Vector3 = Vector3(v.x, -v.y, -v.z)
|
||||||
|
fun axisOffset(v: Vector3): Vector3 = axisRemap(v) //rotationOffset.sandwich(rotationOffset.sandwich(v))
|
||||||
|
fun axisOffset(q: Quaternion): Quaternion = rotationOffset * q
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,16 +1,14 @@
|
|||||||
package dev.slimevr.tracking.trackers.udp
|
package dev.slimevr.tracking.trackers.udp
|
||||||
|
|
||||||
import com.jme3.math.FastMath
|
|
||||||
import dev.slimevr.NetworkProtocol
|
import dev.slimevr.NetworkProtocol
|
||||||
import dev.slimevr.VRServer
|
import dev.slimevr.VRServer
|
||||||
import dev.slimevr.config.config
|
import dev.slimevr.config.config
|
||||||
import dev.slimevr.protocol.rpc.MAG_TIMEOUT
|
import dev.slimevr.protocol.rpc.MAG_TIMEOUT
|
||||||
import dev.slimevr.tracking.trackers.*
|
import dev.slimevr.tracking.trackers.*
|
||||||
|
import dev.slimevr.tracking.trackers.Tracker.Companion.axisOffset
|
||||||
import io.eiren.util.Util
|
import io.eiren.util.Util
|
||||||
import io.eiren.util.collections.FastList
|
import io.eiren.util.collections.FastList
|
||||||
import io.eiren.util.logging.LogManager
|
import io.eiren.util.logging.LogManager
|
||||||
import io.github.axisangles.ktmath.Quaternion.Companion.fromRotationVector
|
|
||||||
import io.github.axisangles.ktmath.Vector3
|
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.*
|
||||||
import solarxr_protocol.rpc.ResetType
|
import solarxr_protocol.rpc.ResetType
|
||||||
import java.net.DatagramPacket
|
import java.net.DatagramPacket
|
||||||
@@ -389,13 +387,12 @@ class TrackersUDPServer(private val port: Int, name: String, private val tracker
|
|||||||
|
|
||||||
is RotationPacket -> {
|
is RotationPacket -> {
|
||||||
var rot = packet.rotation
|
var rot = packet.rotation
|
||||||
rot = AXES_OFFSET.times(rot)
|
rot = axisOffset(rot)
|
||||||
tracker = connection?.getTracker(packet.sensorId)
|
tracker = connection?.getTracker(packet.sensorId)
|
||||||
if (tracker == null) return
|
if (tracker == null) return
|
||||||
tracker.setRotation(rot)
|
tracker.setRotation(rot)
|
||||||
if (packet is UDPPacket23RotationAndAcceleration) {
|
if (packet is UDPPacket23RotationAndAcceleration) {
|
||||||
// Switch x and y around to adjust for different axes
|
tracker.setAcceleration(axisOffset(packet.acceleration))
|
||||||
tracker.setAcceleration(Vector3(packet.acceleration.y, packet.acceleration.x, packet.acceleration.z))
|
|
||||||
}
|
}
|
||||||
tracker.dataTick()
|
tracker.dataTick()
|
||||||
}
|
}
|
||||||
@@ -404,7 +401,7 @@ class TrackersUDPServer(private val port: Int, name: String, private val tracker
|
|||||||
tracker = connection?.getTracker(packet.sensorId)
|
tracker = connection?.getTracker(packet.sensorId)
|
||||||
if (tracker == null) return
|
if (tracker == null) return
|
||||||
var rot17 = packet.rotation
|
var rot17 = packet.rotation
|
||||||
rot17 = AXES_OFFSET * rot17
|
rot17 = axisOffset(rot17)
|
||||||
when (packet.dataType) {
|
when (packet.dataType) {
|
||||||
UDPPacket17RotationData.DATA_TYPE_NORMAL -> {
|
UDPPacket17RotationData.DATA_TYPE_NORMAL -> {
|
||||||
tracker.setRotation(rot17)
|
tracker.setRotation(rot17)
|
||||||
@@ -427,8 +424,7 @@ class TrackersUDPServer(private val port: Int, name: String, private val tracker
|
|||||||
is UDPPacket4Acceleration -> {
|
is UDPPacket4Acceleration -> {
|
||||||
tracker = connection?.getTracker(packet.sensorId)
|
tracker = connection?.getTracker(packet.sensorId)
|
||||||
if (tracker == null) return
|
if (tracker == null) return
|
||||||
// Switch x and y around to adjust for different axes
|
tracker.setAcceleration(axisOffset(packet.acceleration))
|
||||||
tracker.setAcceleration(Vector3(packet.acceleration.y, packet.acceleration.x, packet.acceleration.z))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
is UDPPacket10PingPong -> {
|
is UDPPacket10PingPong -> {
|
||||||
@@ -602,10 +598,6 @@ class TrackersUDPServer(private val port: Int, name: String, private val tracker
|
|||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
/**
|
|
||||||
* Change between IMU axes and OpenGL/SteamVR axes
|
|
||||||
*/
|
|
||||||
private val AXES_OFFSET = fromRotationVector(-FastMath.HALF_PI, 0f, 0f)
|
|
||||||
private const val RESET_SOURCE_NAME = "TrackerServer"
|
private const val RESET_SOURCE_NAME = "TrackerServer"
|
||||||
private fun packetToString(packet: DatagramPacket?): String {
|
private fun packetToString(packet: DatagramPacket?): String {
|
||||||
val sb = StringBuilder()
|
val sb = StringBuilder()
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ object FloatMath {
|
|||||||
const val ZERO_TOLERANCE_D: Double = 0.0001
|
const val ZERO_TOLERANCE_D: Double = 0.0001
|
||||||
|
|
||||||
val SQRT_TWO: Float = kotlin.math.sqrt(2.0).toFloat()
|
val SQRT_TWO: Float = kotlin.math.sqrt(2.0).toFloat()
|
||||||
val INV_SQRT_TWO: Float = 1f / SQRT_TWO
|
val INV_SQRT_TWO: Float = (1.0 / kotlin.math.sqrt(2.0)).toFloat()
|
||||||
val SQRT_THREE: Float = kotlin.math.sqrt(3.0).toFloat()
|
val SQRT_THREE: Float = kotlin.math.sqrt(3.0).toFloat()
|
||||||
val INV_SQRT_THREE: Float = 1f / SQRT_THREE
|
val INV_SQRT_THREE: Float = 1f / SQRT_THREE
|
||||||
const val TWO_FPI: Float = PI * 2
|
const val TWO_FPI: Float = PI * 2
|
||||||
|
|||||||
+4
-8
@@ -1,9 +1,9 @@
|
|||||||
package dev.slimevr.desktop.tracking.trackers.hid
|
package dev.slimevr.desktop.tracking.trackers.hid
|
||||||
|
|
||||||
import com.jme3.math.FastMath
|
|
||||||
import dev.slimevr.VRServer
|
import dev.slimevr.VRServer
|
||||||
import dev.slimevr.tracking.trackers.Device
|
import dev.slimevr.tracking.trackers.Device
|
||||||
import dev.slimevr.tracking.trackers.Tracker
|
import dev.slimevr.tracking.trackers.Tracker
|
||||||
|
import dev.slimevr.tracking.trackers.Tracker.Companion.axisOffset
|
||||||
import dev.slimevr.tracking.trackers.TrackerStatus
|
import dev.slimevr.tracking.trackers.TrackerStatus
|
||||||
import dev.slimevr.tracking.trackers.udp.BoardType
|
import dev.slimevr.tracking.trackers.udp.BoardType
|
||||||
import dev.slimevr.tracking.trackers.udp.IMUType
|
import dev.slimevr.tracking.trackers.udp.IMUType
|
||||||
@@ -11,7 +11,6 @@ import dev.slimevr.tracking.trackers.udp.MCUType
|
|||||||
import dev.slimevr.tracking.trackers.udp.MagnetometerStatus
|
import dev.slimevr.tracking.trackers.udp.MagnetometerStatus
|
||||||
import io.eiren.util.logging.LogManager
|
import io.eiren.util.logging.LogManager
|
||||||
import io.github.axisangles.ktmath.Quaternion
|
import io.github.axisangles.ktmath.Quaternion
|
||||||
import io.github.axisangles.ktmath.Quaternion.Companion.fromRotationVector
|
|
||||||
import io.github.axisangles.ktmath.Vector3
|
import io.github.axisangles.ktmath.Vector3
|
||||||
import org.hid4java.HidDevice
|
import org.hid4java.HidDevice
|
||||||
import org.hid4java.HidException
|
import org.hid4java.HidException
|
||||||
@@ -412,7 +411,7 @@ class TrackersHID(name: String, private val trackersConsumer: Consumer<Tracker>)
|
|||||||
// x y z w -> w x y z
|
// x y z w -> w x y z
|
||||||
var rot = Quaternion(q[3].toFloat(), q[0].toFloat(), q[1].toFloat(), q[2].toFloat())
|
var rot = Quaternion(q[3].toFloat(), q[0].toFloat(), q[1].toFloat(), q[2].toFloat())
|
||||||
val scaleRot = 1 / (1 shl 15).toFloat() // compile time evaluation
|
val scaleRot = 1 / (1 shl 15).toFloat() // compile time evaluation
|
||||||
rot = AXES_OFFSET.times(scaleRot).times(rot) // no division
|
rot = axisOffset(rot * scaleRot) // no division
|
||||||
tracker.setRotation(rot)
|
tracker.setRotation(rot)
|
||||||
}
|
}
|
||||||
if (packetType == 2) {
|
if (packetType == 2) {
|
||||||
@@ -431,7 +430,7 @@ class TrackersHID(name: String, private val trackersConsumer: Consumer<Tracker>)
|
|||||||
val s = sin(a)
|
val s = sin(a)
|
||||||
val k = s * invSqrtD
|
val k = s * invSqrtD
|
||||||
var rot = Quaternion(cos(a), k * v[0], k * v[1], k * v[2])
|
var rot = Quaternion(cos(a), k * v[0], k * v[1], k * v[2])
|
||||||
rot = AXES_OFFSET.times(rot) // no division
|
rot = axisOffset(rot) // no division
|
||||||
tracker.setRotation(rot)
|
tracker.setRotation(rot)
|
||||||
}
|
}
|
||||||
if (packetType == 1 || packetType == 2) {
|
if (packetType == 1 || packetType == 2) {
|
||||||
@@ -444,6 +443,7 @@ class TrackersHID(name: String, private val trackersConsumer: Consumer<Tracker>)
|
|||||||
// Front side (facing out) is +Z
|
// Front side (facing out) is +Z
|
||||||
val scaleAccel = 1 / (1 shl 7).toFloat() // compile time evaluation
|
val scaleAccel = 1 / (1 shl 7).toFloat() // compile time evaluation
|
||||||
var acceleration = Vector3(a[0].toFloat(), a[1].toFloat(), a[2].toFloat()).times(scaleAccel) // no division
|
var acceleration = Vector3(a[0].toFloat(), a[1].toFloat(), a[2].toFloat()).times(scaleAccel) // no division
|
||||||
|
acceleration = axisOffset(acceleration)
|
||||||
tracker.setAcceleration(acceleration)
|
tracker.setAcceleration(acceleration)
|
||||||
}
|
}
|
||||||
if (packetType == 4) {
|
if (packetType == 4) {
|
||||||
@@ -528,10 +528,6 @@ class TrackersHID(name: String, private val trackersConsumer: Consumer<Tracker>)
|
|||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
/**
|
|
||||||
* Change between IMU axes and OpenGL/SteamVR axes
|
|
||||||
*/
|
|
||||||
private val AXES_OFFSET = fromRotationVector(-FastMath.HALF_PI, 0f, 0f)
|
|
||||||
private const val resetSourceName = "TrackerServer"
|
private const val resetSourceName = "TrackerServer"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user