Display data from new protocol and firmware version, including calibration statis and magentometer correction

This commit is contained in:
Eiren Rain committed 2021-08-09 17:46:00 +03:00
1 parent 6a45e5d32c
commit 52932d63d3
6 files changed
+155 -107

No files matched your search

@@ -64,7 +64,7 @@ public class SkeletonConfig extends EJBag {
}}, s(c(0, row, 1), 3, 1));
row++;
/*
add(new JCheckBox("Extended knee model") {{
addItemListener(new ItemListener() {
@Override
+68 -36
View File
@@ -102,6 +102,9 @@ public class TrackersList extends EJBox {
JLabel bat;
JLabel ping;
JLabel raw;
JLabel rawMag;
JLabel calibration;
JLabel magAccuracy;
JLabel adj;
JLabel adjYaw;
@@ -114,12 +117,19 @@ public class TrackersList extends EJBox {
@SuppressWarnings("unchecked")
@AWTThread
public TrackerRow build() {
int row = 0;
Tracker realTracker = t;
if(t instanceof ReferenceAdjustedTracker)
realTracker = ((ReferenceAdjustedTracker<? extends Tracker>) t).getTracker();
removeAll();
add(new JLabel(t.getName()), s(c(0, 0, 0, GridBagConstraints.FIRST_LINE_START), 4, 1));
add(new JLabel(t.getName()), s(c(0, row, 0, GridBagConstraints.FIRST_LINE_START), 4, 1));
row++;
if(t.userEditable()) {
TrackerConfig cfg = server.getTrackerConfig(t);
JComboBox<String> desSelect;
add(desSelect = new JComboBox<>(), s(c(0, 1, 0, GridBagConstraints.FIRST_LINE_START), 2, 1));
add(desSelect = new JComboBox<>(), s(c(0, row, 0, GridBagConstraints.FIRST_LINE_START), 2, 1));
for(TrackerBodyPosition p : TrackerBodyPosition.values) {
desSelect.addItem(p.name());
}
@@ -136,14 +146,11 @@ public class TrackersList extends EJBox {
server.trackerUpdated(t);
}
});
Tracker realTracker = t;
if(t instanceof ReferenceAdjustedTracker<?>)
realTracker = ((ReferenceAdjustedTracker<? extends Tracker>) t).getTracker();
if(realTracker instanceof IMUTracker) {
IMUTracker imu = (IMUTracker) realTracker;
TrackerMountingRotation tr = imu.getMountingRotation();
JComboBox<String> mountSelect;
add(mountSelect = new JComboBox<>(), s(c(2, 1, 0, GridBagConstraints.FIRST_LINE_START), 2, 1));
add(mountSelect = new JComboBox<>(), s(c(2, row, 0, GridBagConstraints.FIRST_LINE_START), 2, 1));
for(TrackerMountingRotation p : TrackerMountingRotation.values) {
mountSelect.addItem(p.name());
}
@@ -161,31 +168,46 @@ public class TrackersList extends EJBox {
}
});
}
row++;
}
add(new JLabel("Rotation"), c(0, 2, 0, GridBagConstraints.FIRST_LINE_START));
add(new JLabel("Postion"), c(1, 2, 0, GridBagConstraints.FIRST_LINE_START));
add(new JLabel("Ping"), c(2, 2, 0, GridBagConstraints.FIRST_LINE_START));
add(new JLabel("TPS"), c(3, 2, 0, GridBagConstraints.FIRST_LINE_START));
add(rotation = new JLabel("0 0 0"), c(0, 3, 0, GridBagConstraints.FIRST_LINE_START));
add(position = new JLabel("0 0 0"), c(1, 3, 0, GridBagConstraints.FIRST_LINE_START));
add(ping = new JLabel(""), c(2, 3, 0, GridBagConstraints.FIRST_LINE_START));
if(t instanceof TrackerWithTPS) {
add(tps = new JLabel("0"), c(3, 3, 0, GridBagConstraints.FIRST_LINE_START));
add(new JLabel("Rotation"), c(0, row, 0, GridBagConstraints.FIRST_LINE_START));
add(new JLabel("Postion"), c(1, row, 0, GridBagConstraints.FIRST_LINE_START));
add(new JLabel("Ping"), c(2, row, 0, GridBagConstraints.FIRST_LINE_START));
add(new JLabel("TPS"), c(3, row, 0, GridBagConstraints.FIRST_LINE_START));
row++;
add(rotation = new JLabel("0 0 0"), c(0, row, 0, GridBagConstraints.FIRST_LINE_START));
add(position = new JLabel("0 0 0"), c(1, row, 0, GridBagConstraints.FIRST_LINE_START));
add(ping = new JLabel(""), c(2, row, 0, GridBagConstraints.FIRST_LINE_START));
if(realTracker instanceof TrackerWithTPS) {
add(tps = new JLabel("0"), c(3, row, 0, GridBagConstraints.FIRST_LINE_START));
} else {
add(new JLabel(""), c(3, 3, 0, GridBagConstraints.FIRST_LINE_START));
add(new JLabel(""), c(3, row, 0, GridBagConstraints.FIRST_LINE_START));
}
row++;
add(new JLabel("Status:"), c(0, row, 0, GridBagConstraints.FIRST_LINE_START));
add(status = new JLabel(t.getStatus().toString().toLowerCase()), c(1, row, 0, GridBagConstraints.FIRST_LINE_START));
add(new JLabel("Battery:"), c(2, row, 0, GridBagConstraints.FIRST_LINE_START));
add(bat = new JLabel("0"), c(3, row, 0, GridBagConstraints.FIRST_LINE_START));
row++;
add(new JLabel("Raw:"), c(0, row, 0, GridBagConstraints.FIRST_LINE_START));
add(raw = new JLabel("0 0 0"), s(c(1, row, 0, GridBagConstraints.FIRST_LINE_START), 3, 1));
row++;
if(realTracker instanceof IMUTracker) {
add(new JLabel("Raw mag:"), c(0, row, 0, GridBagConstraints.FIRST_LINE_START));
add(rawMag = new JLabel("0 0 0"), s(c(1, row, 0, GridBagConstraints.FIRST_LINE_START), 3, 1));
row++;
add(new JLabel("Cal:"), c(0, row, 0, GridBagConstraints.FIRST_LINE_START));
add(calibration = new JLabel("0"), c(1, row, 0, GridBagConstraints.FIRST_LINE_START));
add(new JLabel("Mag acc:"), c(2, row, 0, GridBagConstraints.FIRST_LINE_START));
add(magAccuracy = new JLabel("0°"), c(3, row, 0, GridBagConstraints.FIRST_LINE_START));
row++;
}
add(new JLabel("Status:"), c(0, 4, 0, GridBagConstraints.FIRST_LINE_START));
add(status = new JLabel(t.getStatus().toString().toLowerCase()), c(1, 4, 0, GridBagConstraints.FIRST_LINE_START));
add(new JLabel("Battery:"), c(2, 4, 0, GridBagConstraints.FIRST_LINE_START));
add(bat = new JLabel("0"), c(3, 4, 0, GridBagConstraints.FIRST_LINE_START));
add(new JLabel("Raw:"), c(0, 5, 0, GridBagConstraints.FIRST_LINE_START));
add(raw = new JLabel("0 0 0"), s(c(1, 5, 0, GridBagConstraints.FIRST_LINE_START), 3, 1));
if(t instanceof ReferenceAdjustedTracker) {
add(new JLabel("Adj:"), c(0, 6, 0, GridBagConstraints.FIRST_LINE_START));
add(adj = new JLabel("0 0 0 0"), c(1, 6, 0, GridBagConstraints.FIRST_LINE_START));
add(new JLabel("AdjY:"), c(2, 6, 0, GridBagConstraints.FIRST_LINE_START));
add(adjYaw = new JLabel("0 0 0 0"), c(3, 6, 0, GridBagConstraints.FIRST_LINE_START));
if(t instanceof ReferenceAdjustedTracker) {
add(new JLabel("Adj:"), c(0, row, 0, GridBagConstraints.FIRST_LINE_START));
add(adj = new JLabel("0 0 0 0"), c(1, row, 0, GridBagConstraints.FIRST_LINE_START));
add(new JLabel("AdjY:"), c(2, row, 0, GridBagConstraints.FIRST_LINE_START));
add(adjYaw = new JLabel("0 0 0 0"), c(3, row, 0, GridBagConstraints.FIRST_LINE_START));
}
setBorder(BorderFactory.createLineBorder(new Color(0x663399), 4, true));
@@ -198,6 +220,9 @@ public class TrackersList extends EJBox {
public void update() {
if(position == null)
return;
Tracker realTracker = t;
if(t instanceof ReferenceAdjustedTracker)
realTracker = ((ReferenceAdjustedTracker<? extends Tracker>) t).getTracker();
t.getRotation(q);
t.getPosition(v);
q.toAngles(angles);
@@ -210,14 +235,12 @@ public class TrackersList extends EJBox {
+ " " + StringUtils.prettyNumber(angles[2] * FastMath.RAD_TO_DEG, 0));
status.setText(t.getStatus().toString().toLowerCase());
if(t instanceof TrackerWithTPS) {
tps.setText(StringUtils.prettyNumber(((TrackerWithTPS) t).getTPS(), 1));
if(realTracker instanceof TrackerWithTPS) {
tps.setText(StringUtils.prettyNumber(((TrackerWithTPS) realTracker).getTPS(), 1));
}
if(t instanceof TrackerWithBattery)
bat.setText(StringUtils.prettyNumber(((TrackerWithBattery) t).getBatteryVoltage(), 1));
Tracker t2 = t;
if(realTracker instanceof TrackerWithBattery)
bat.setText(StringUtils.prettyNumber(((TrackerWithBattery) realTracker).getBatteryVoltage(), 1));
if(t instanceof ReferenceAdjustedTracker) {
t2 = ((ReferenceAdjustedTracker<Tracker>) t).getTracker();
((ReferenceAdjustedTracker<Tracker>) t).attachmentFix.toAngles(angles);
adj.setText(StringUtils.prettyNumber(angles[0] * FastMath.RAD_TO_DEG, 0)
+ " " + StringUtils.prettyNumber(angles[1] * FastMath.RAD_TO_DEG, 0)
@@ -227,13 +250,22 @@ public class TrackersList extends EJBox {
+ " " + StringUtils.prettyNumber(angles[1] * FastMath.RAD_TO_DEG, 0)
+ " " + StringUtils.prettyNumber(angles[2] * FastMath.RAD_TO_DEG, 0));
}
if(t2 instanceof IMUTracker)
ping.setText(String.valueOf(((IMUTracker) t2).ping));
t2.getRotation(q);
if(realTracker instanceof IMUTracker) {
ping.setText(String.valueOf(((IMUTracker) realTracker).ping));
}
realTracker.getRotation(q);
q.toAngles(angles);
raw.setText(StringUtils.prettyNumber(angles[0] * FastMath.RAD_TO_DEG, 0)
+ " " + StringUtils.prettyNumber(angles[1] * FastMath.RAD_TO_DEG, 0)
+ " " + StringUtils.prettyNumber(angles[2] * FastMath.RAD_TO_DEG, 0));
if(realTracker instanceof IMUTracker) {
((IMUTracker) realTracker).rotMagQuaternion.toAngles(angles);
rawMag.setText(StringUtils.prettyNumber(angles[0] * FastMath.RAD_TO_DEG, 0)
+ " " + StringUtils.prettyNumber(angles[1] * FastMath.RAD_TO_DEG, 0)
+ " " + StringUtils.prettyNumber(angles[2] * FastMath.RAD_TO_DEG, 0));
calibration.setText(String.valueOf(((IMUTracker) realTracker).calibrationStatus));
magAccuracy.setText(StringUtils.prettyNumber(((IMUTracker) realTracker).magnetometerAccuracy * FastMath.RAD_TO_DEG, 1) + "°");
}
}
}
+1 -1
View File
@@ -7,7 +7,7 @@ import io.eiren.util.logging.LogManager;
public class Main {
public static String VERSION = "0.0.13 Test 9";
public static String VERSION = "0.0.13 Test 11";
public static VRServer vrServer;
@@ -1,29 +0,0 @@
package io.eiren.vr.trackers;
public class IMUReferenceAdjustedTracker<T extends IMUTracker & TrackerWithTPS & TrackerWithBattery> extends ReferenceAdjustedTracker<T> implements TrackerWithTPS, TrackerWithBattery {
public IMUReferenceAdjustedTracker(T tracker) {
super(tracker);
}
@Override
public float getBatteryLevel() {
return tracker.getBatteryLevel();
}
@Override
public float getBatteryVoltage() {
return tracker.getBatteryVoltage();
}
@Override
public float getTPS() {
return tracker.getTPS();
}
@Override
public void dataTick() {
tracker.dataTick();
}
}
@@ -13,6 +13,7 @@ public class IMUTracker implements Tracker, TrackerWithTPS, TrackerWithBattery {
public final Vector3f accelVector = new Vector3f();
public final Vector3f magVector = new Vector3f();
public final Quaternion rotQuaternion = new Quaternion();
public final Quaternion rotMagQuaternion = new Quaternion();
protected final Quaternion rotAdjust = new Quaternion();
protected TrackerMountingRotation mounting = null;
protected TrackerStatus status = TrackerStatus.OK;
@@ -21,6 +22,8 @@ public class IMUTracker implements Tracker, TrackerWithTPS, TrackerWithBattery {
protected final TrackersUDPServer server;
protected float confidence = 0;
protected float batteryVoltage = 0;
public int calibrationStatus = 0;
public float magnetometerAccuracy = 0;
protected BufferedTimer timer = new BufferedTimer(1f);
public int ping = -1;
@@ -90,7 +90,7 @@ public class TrackersUDPServer extends Thread {
if(sb.length() == 0)
sb.append("owoTrack");
IMUTracker imu = new IMUTracker("udp:/" + handshakePacket.getAddress().toString(), this);
IMUReferenceAdjustedTracker<IMUTracker> adjustedTracker = new IMUReferenceAdjustedTracker<>(imu);
ReferenceAdjustedTracker<IMUTracker> adjustedTracker = new ReferenceAdjustedTracker<>(imu);
trackersConsumer.accept(adjustedTracker);
sensor = new TrackerConnection(imu, addr);
int i = 0;
@@ -109,7 +109,7 @@ public class TrackersUDPServer extends Thread {
System.out.println("[TrackerServer] Setting up auxilary sensor for " + connection.tracker.getName());
IMUTracker imu = new IMUTracker(connection.tracker.getName() + "/1", this);
connection.secondTracker = imu;
IMUReferenceAdjustedTracker<IMUTracker> adjustedTracker = new IMUReferenceAdjustedTracker<>(imu);
ReferenceAdjustedTracker<IMUTracker> adjustedTracker = new ReferenceAdjustedTracker<>(imu);
trackersConsumer.accept(adjustedTracker);
System.out.println("[TrackerServer] Sensor added with address " + imu.getName());
}
@@ -129,12 +129,13 @@ public class TrackersUDPServer extends Thread {
socket.receive(recieve);
bb.rewind();
TrackerConnection sensor;
TrackerConnection connection;
IMUTracker tracker = null;
synchronized(trackers) {
sensor = trackersMap.get(recieve.getSocketAddress());
connection = trackersMap.get(recieve.getSocketAddress());
}
if(sensor != null)
sensor.lastPacket = System.currentTimeMillis();
if(connection != null)
connection.lastPacket = System.currentTimeMillis();
int packetId;
switch(packetId = bb.getInt()) {
case 0:
@@ -144,90 +145,131 @@ public class TrackersUDPServer extends Thread {
break;
case 1: // PACKET_ROTATION
case 16: // PACKET_ROTATION_2
if(sensor == null)
if(connection == null)
break;
bb.getLong();
buf.set(bb.getFloat(), bb.getFloat(), bb.getFloat(), bb.getFloat());
offset.mult(buf, buf);
IMUTracker tracker;
if(packetId == 1) {
tracker = sensor.tracker;
tracker = connection.tracker;
} else {
tracker = sensor.secondTracker;
tracker = connection.secondTracker;
}
if(tracker == null)
break;
tracker.rotQuaternion.set(buf);
tracker.dataTick();
break;
case 17: // PACKET_ROTATION_DATA
bb.getLong();
int sensorId = bb.get() & 0xFF;
if(sensorId == 0) {
tracker = connection.tracker;
} else if(sensorId == 1) {
tracker = connection.secondTracker;
}
if(tracker == null)
break;
int dataType = bb.get() & 0xFF;
buf.set(bb.getFloat(), bb.getFloat(), bb.getFloat(), bb.getFloat());
offset.mult(buf, buf);
int calibrationInfo = bb.get() & 0xFF;
switch(dataType) {
case 1: // DATA_TYPE_NORMAL
tracker.rotQuaternion.set(buf);
tracker.calibrationStatus = calibrationInfo;
tracker.dataTick();
break;
case 2: // DATA_TYPE_CORRECTION
tracker.rotMagQuaternion.set(buf);
tracker.dataTick();
break;
}
break;
case 18: // PACKET_MAGENTOMETER_ACCURACY
bb.getLong();
sensorId = bb.get() & 0xFF;
if(sensorId == 0) {
tracker = connection.tracker;
} else if(sensorId == 1) {
tracker = connection.secondTracker;
}
if(tracker == null)
break;
float accuracyInfo = bb.getFloat();
tracker.magnetometerAccuracy = accuracyInfo;
// TODO
break;
case 2:
if(sensor == null)
if(connection == null)
break;
bb.getLong();
sensor.tracker.gyroVector.set(bb.getFloat(), bb.getFloat(), bb.getFloat());
connection.tracker.gyroVector.set(bb.getFloat(), bb.getFloat(), bb.getFloat());
break;
case 4:
if(sensor == null)
if(connection == null)
break;
bb.getLong();
float x = bb.getFloat();
float z = bb.getFloat();
float y = bb.getFloat();
sensor.tracker.accelVector.set(x, y, z);
connection.tracker.accelVector.set(x, y, z);
break;
case 5:
if(sensor == null)
if(connection == null)
break;
bb.getLong();
x = bb.getFloat();
z = bb.getFloat();
y = bb.getFloat();
sensor.tracker.magVector.set(x, y, z);
connection.tracker.magVector.set(x, y, z);
break;
case 6: // PACKET_RAW_CALIBRATION_DATA
if(sensor == null)
if(connection == null)
break;
bb.getLong();
//sensor.rawCalibrationData.add(new double[] {bb.getInt(), bb.getInt(), bb.getInt(), bb.getInt(), bb.getInt(), bb.getInt()});
break;
case 7: // PACKET_GYRO_CALIBRATION_DATA
if(sensor == null)
if(connection == null)
break;
bb.getLong();
//sensor.gyroCalibrationData = new double[] {bb.getFloat(), bb.getFloat(), bb.getFloat()};
break;
case 8: // PACKET_CONFIG
if(sensor == null)
if(connection == null)
break;
bb.getLong();
MPUTracker.ConfigurationData data = new MPUTracker.ConfigurationData(bb);
Consumer<String> dataConsumer = calibrationDataRequests.remove(sensor.tracker);
Consumer<String> dataConsumer = calibrationDataRequests.remove(connection.tracker);
if(dataConsumer != null) {
dataConsumer.accept(data.toTextMatrix());
}
break;
case 9: // PACKET_RAW_MAGENTOMETER
if(sensor == null)
if(connection == null)
break;
bb.getLong();
float mx = bb.getFloat();
float my = bb.getFloat();
float mz = bb.getFloat();
sensor.tracker.confidence = (float) Math.sqrt(mx * mx + my * my + mz * mz);
connection.tracker.confidence = (float) Math.sqrt(mx * mx + my * my + mz * mz);
break;
case 10: // PACKET_PING_PONG:
if(sensor == null)
if(connection == null)
break;
int pingId = bb.getInt();
if(sensor.lastPingPacketId == pingId) {
tracker = sensor.tracker;
tracker.ping = (int) (System.currentTimeMillis() - sensor.lastPingPacketTime) / 2;
if(connection.lastPingPacketId == pingId) {
tracker = connection.tracker;
tracker.ping = (int) (System.currentTimeMillis() - connection.lastPingPacketTime) / 2;
}
break;
case 11: // PACKET_SERIAL
if(sensor == null)
if(connection == null)
break;
tracker = sensor.tracker;
tracker = connection.tracker;
bb.getLong();
int length = bb.getInt();
for(int i = 0; i < length; ++i) {
@@ -243,16 +285,16 @@ public class TrackersUDPServer extends Thread {
}
break;
case 12: // PACKET_BATTERY_VOLTAGE
if(sensor == null)
if(connection == null)
break;
tracker = sensor.tracker;
tracker = connection.tracker;
bb.getLong();
tracker.setBatteryVoltage(bb.getFloat());
break;
case 13: // PACKET_TAP
if(sensor == null)
if(connection == null)
break;
tracker = sensor.tracker;
tracker = connection.tracker;
bb.getLong();
byte tap = bb.get();
System.out.println("[TrackerServer] Tap packet received from " + tracker.getName() + ": b" + Integer.toBinaryString(tap));
@@ -261,26 +303,26 @@ public class TrackersUDPServer extends Thread {
bb.getLong();
byte reason = bb.get();
System.out.println("[TrackerServer] Reset recieved from " + recieve.getSocketAddress() + ": " + reason);
if(sensor == null)
if(connection == null)
break;
tracker = sensor.tracker;
tracker = connection.tracker;
tracker.setStatus(TrackerStatus.ERROR);
break;
case 15: // PACKET_SENSOR_INFO
if(sensor == null)
if(connection == null)
break;
bb.getLong();
int sensorId = bb.get() & 0xFF;
sensorId = bb.get() & 0xFF;
int sensorStatus = bb.get() & 0xFF;
if(sensorId == 1 && sensorStatus == 1 && sensor.secondTracker == null) {
setUpAuxialrySensor(sensor);
if(sensorId == 1 && sensorStatus == 1 && connection.secondTracker == null) {
setUpAuxialrySensor(connection);
}
bb.rewind();
bb.putInt(15);
bb.put((byte) sensorId);
bb.put((byte) sensorStatus);
socket.send(new DatagramPacket(rcvBuffer, bb.position(), sensor.address));
System.out.println("[TrackerServer] Sensor info for " + sensor.tracker.getName() + "/" + sensorId + ": " + sensorStatus);
socket.send(new DatagramPacket(rcvBuffer, bb.position(), connection.address));
System.out.println("[TrackerServer] Sensor info for " + connection.tracker.getName() + "/" + sensorId + ": " + sensorStatus);
break;
default:
System.out.println("[TrackerServer] Unknown data received: " + packetId + " from " + recieve.getSocketAddress());