Skip to content

Commit

Permalink
Add compact IMU frame (rot+acc) (#1001)
Browse files Browse the repository at this point in the history
  • Loading branch information
9il committed Apr 21, 2024
1 parent be76cd1 commit ae4391b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,9 @@ class TrackersUDPServer(private val port: Int, name: String, private val tracker
tracker = connection?.getTracker(packet.sensorId)
if (tracker == null) return
tracker.setRotation(rot)
if (packet is UDPPacket23RotationAndAcceleration) {
tracker.setAcceleration(packet.acceleration)
}
tracker.dataTick()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,27 @@ class UDPPacket22FeatureFlags(
}
}

data class UDPPacket23RotationAndAcceleration(
override var rotation: Quaternion = Quaternion.IDENTITY,
var acceleration: Vector3 = Vector3.NULL,
) : UDPPacket(23),
RotationPacket {
override var sensorId: Int = 0
override fun readData(buf: ByteBuffer) {
// s16 s16 s16 s16 s16 s16 s16
// qX qY qZ qW aX aY aZ
sensorId = buf.get().toInt() and 0xFF
val scaleR = 1 / (1 shl 15).toFloat() // Q15: 1 is represented as 0x7FFF and -1 as 0x8000
val x = buf.short * scaleR
val y = buf.short * scaleR
val z = buf.short * scaleR
val w = buf.short * scaleR
rotation = Quaternion(w, x, y, z).unit()
val scaleA = 1 / (1 shl 7).toFloat() // The same as the HID scale
acceleration = Vector3(buf.short * scaleA, buf.short * scaleA, buf.short * scaleA)
}
}

data class UDPPacket200ProtocolChange(
var targetProtocol: Int = 0,
var targetProtocolVersion: Int = 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ class UDPProtocolParser {
const val PACKET_TEMPERATURE = 20
const val PACKET_USER_ACTION = 21
const val PACKET_FEATURE_FLAGS = 22
const val PACKET_ROTATION_AND_ACCELERATION = 23
const val PACKET_BUNDLE = 100
const val PACKET_PROTOCOL_CHANGE = 200
private val HANDSHAKE_BUFFER = ByteArray(64)
Expand Down

0 comments on commit ae4391b

Please sign in to comment.