Added ping stat

Minor cleanup
This commit is contained in:
Eiren Rain
2021-04-05 09:22:55 +03:00
parent 86e98ca143
commit 48cfeec677
5 changed files with 41 additions and 7 deletions

View File

@@ -65,6 +65,7 @@ public class TrackersList extends EJBag {
add(new JLabel("Status"), c(8, 0, 2));
add(new JLabel("TPS"), c(9, 0, 2));
add(new JLabel("Bat"), c(10, 0, 2));
add(new JLabel("Ping"), c(11, 0, 2));
trackers.sort((tr1, tr2) -> getTrackerSort(tr1.t) - getTrackerSort(tr2.t));
@@ -95,7 +96,7 @@ public class TrackersList extends EJBag {
new CalibrationWindow(t);
}
});
}}, c(11, n, 2));
}}, c(12, n, 2));
}
n += tr.getSize();
}
@@ -133,6 +134,7 @@ public class TrackersList extends EJBag {
JLabel status;
JLabel tps;
JLabel bat;
JLabel ping;
@AWTThread
public TrackerRow(Tracker t) {
@@ -155,6 +157,7 @@ public class TrackersList extends EJBag {
add(new JLabel(""), c(9, n, 2, GridBagConstraints.FIRST_LINE_START));
}
add(bat = new JLabel("0"), c(10, n, 2, GridBagConstraints.FIRST_LINE_START));
add(ping = new JLabel(""), c(11, n, 2, GridBagConstraints.FIRST_LINE_START));
return this;
}
@@ -179,6 +182,8 @@ public class TrackersList extends EJBag {
}
if(t instanceof TrackerWithBattery)
bat.setText(StringUtils.prettyNumber(((TrackerWithBattery) t).getBatteryVoltage(), 1));
if(t instanceof IMUTracker)
ping.setText(String.valueOf(((IMUTracker) t).ping));
}
public int getSize() {

View File

@@ -42,7 +42,7 @@ public class HumanSekeletonWithLegs extends HumanSkeleonWithWaist {
/**
* Distance from waist to ankle
*/
protected float ankleLength = 0.4f;
protected float ankleLength = 0.5f;
protected float minKneePitch = 0f * FastMath.DEG_TO_RAD;
protected float maxKneePitch = 90f * FastMath.DEG_TO_RAD;

View File

@@ -145,10 +145,10 @@ public class HumanSkeleonWithWaist extends HumanSkeleton {
// Pelvic bone doesn't tilt when humans tilt, unless they really try.
// Can't calculate tilt without additional sensors, so just remove it
// completely.
qBuf.toAngles(waistAngles);
waistAngles[0] = 0;
waistAngles[2] *= 0.2f; // Keep some roll
qBuf.fromAngles(waistAngles);
//qBuf.toAngles(waistAngles);
//waistAngles[0] = 0;
//waistAngles[2] *= 0.2f; // Keep some roll
//qBuf.fromAngles(waistAngles);
waistNode.localTransform.setRotation(qBuf);
}

View File

@@ -26,6 +26,7 @@ public class IMUTracker implements Tracker, CalibratingTracker, TrackerWithTPS,
protected BufferedTimer timer = new BufferedTimer(1f);
public ConfigurationData newCalibrationData;
public int ping = -1;
public StringBuilder serialBuffer = new StringBuilder();
long lastSerialUpdate = 0;

View File

@@ -11,6 +11,7 @@ import java.nio.ByteOrder;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.function.Consumer;
import com.jme3.math.FastMath;
@@ -38,7 +39,7 @@ public class TrackersUDPServer extends Thread {
private static final byte[] CALIBRATION_REQUEST_BUFFER = new byte[64];
private final Quaternion buf = new Quaternion();
private final Random random = new Random();
private final List<TrackerConnection> trackers = new FastList<>();
private final Map<SocketAddress, TrackerConnection> trackersMap = new HashMap<>();
private final Map<Tracker, Consumer<String>> calibrationDataRequests = new HashMap<>();
@@ -322,6 +323,15 @@ public class TrackersUDPServer extends Thread {
float mz = bb.getFloat();
sensor.tracker.confidence = (float) Math.sqrt(mx * mx + my * my + mz * mz);
break;
case 10: // PACKET_PING_PONG:
if(sensor == null)
break;
int pingId = bb.getInt();
if(sensor.lastPingPacketId == pingId) {
IMUTracker tracker = sensor.tracker;
tracker.ping = (int) (System.currentTimeMillis() - sensor.lastPingPacketTime) / 2;
}
break;
case 11: // PACKET_SERIAL
if(sensor == null)
break;
@@ -347,6 +357,14 @@ public class TrackersUDPServer extends Thread {
bb.getLong();
tracker.setBatteryVoltage(bb.getFloat());
break;
case 13: // PACKET_TAP
if(sensor == null)
break;
tracker = sensor.tracker;
bb.getLong();
byte tap = bb.get();
System.out.println("[TrackerServer] Tap packet received from " + tracker.getName() + ": b" + Integer.toBinaryString(tap));
break;
default:
System.out.println("[TrackerServer] Unknown data received: " + packetId + " from " + recieve.getSocketAddress());
break;
@@ -374,6 +392,14 @@ public class TrackersUDPServer extends Thread {
tracker.serialBuffer.setLength(0);
}
}
if(conn.lastPingPacketTime + 500 < System.currentTimeMillis()) {
conn.lastPingPacketId = random.nextInt();
conn.lastPingPacketTime = System.currentTimeMillis();
bb.rewind();
bb.putInt(10);
bb.putInt(conn.lastPingPacketId);
socket.send(new DatagramPacket(rcvBuffer, bb.position(), conn.address));
}
}
}
}
@@ -393,6 +419,8 @@ public class TrackersUDPServer extends Thread {
private List<double[]> rawCalibrationData = new FastList<>();
private double[] gyroCalibrationData;
public long lastPacket = System.currentTimeMillis();
public int lastPingPacketId = -1;
public long lastPingPacketTime = 0;
public TrackerConnection(IMUTracker tracker, SocketAddress address) {
this.tracker = tracker;