Tracker filters GUI and config

I am now master at GUI.
(never again).
Might have done some dumb things like giving IMUTracker VRServer idk, tell me if there's something to fix <3
This commit is contained in:
Louka committed 2022-03-19 03:02:06 -04:00
1 parent 4263e86189
commit 256e5079cf
6 files changed
+202 -10

No files matched your search

@@ -0,0 +1,142 @@
package dev.slimevr.gui;
import java.awt.event.MouseEvent;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;
import javax.swing.Box;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.event.MouseInputAdapter;
import com.jme3.math.FastMath;
import dev.slimevr.VRServer;
import dev.slimevr.gui.swing.EJBagNoStretch;
import dev.slimevr.vr.trackers.IMUTracker;
import dev.slimevr.vr.trackers.ReferenceAdjustedTracker;
import dev.slimevr.vr.trackers.Tracker;
import dev.slimevr.vr.trackers.TrackerFilters;
import io.eiren.util.StringUtils;
import io.eiren.util.collections.FastList;
public class TrackersFiltersGUI extends EJBagNoStretch {
private final VRServer server;
String filterType;
float filterAmount;
int filterFrames;
private List<Tracker> allTrackers = new FastList<>();
private JLabel amountLabel, framesLabel;
public TrackersFiltersGUI(VRServer server, VRServerGUI gui) {
super(false, true);
this.server = server;
int row = 0;
setAlignmentY(TOP_ALIGNMENT);
add(Box.createVerticalStrut(10));
filterType = server.config.getString("filters.type");
if(filterType == null){
filterType = "NONE";
}
JComboBox<String> filterSelect;
add(filterSelect = new JComboBox<>(), s(c(0, row, 2), 4, 1));
for(TrackerFilters f : TrackerFilters.values()) {
filterSelect.addItem(f.name());
}
if(filterType != null) {
filterSelect.setSelectedItem(filterType);
} else {
filterSelect.setSelectedItem(TrackerFilters.NONE);
}
filterSelect.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
filterType = filterSelect.getSelectedItem().toString();
server.config.setProperty("filters.type", filterType);
server.saveConfig();
updateTrackersFilters();
}
});
add(Box.createVerticalStrut(40));
row++;
filterAmount = (Float) FastMath.clamp(server.config.getFloat("filters.amount", 0.5f), 0, 1);
add(new JLabel("Intensity"), c(0, row, 2));
add(new AdjButton("+", 0, false), c(1, row, 2));
add(amountLabel = new JLabel(StringUtils.prettyNumber(filterAmount * 100f) + "%"), c(2, row, 2));
add(new AdjButton("-", 0, true), c(3, row, 2));
row++;
filterFrames = (int) FastMath.clamp(server.config.getInt("filters.frameCount", 3), 0, 80);
add(new JLabel("Frames"), c(0, row, 2));
add(new AdjButton("+", 1, false), c(1, row, 2));
add(framesLabel = new JLabel(StringUtils.prettyNumber(filterFrames)), c(2, row, 2));
add(new AdjButton("-", 1, true), c(3, row, 2));
}
void updateTrackersFilters(){
allTrackers = server.getAllTrackers();
IMUTracker imu;
for (Tracker t : allTrackers) {
Tracker realTracker = t;
if(t instanceof ReferenceAdjustedTracker)
realTracker = ((ReferenceAdjustedTracker<? extends Tracker>) t).getTracker();
if(realTracker instanceof IMUTracker){
imu = (IMUTracker)realTracker;
imu.setFilter(filterType, filterAmount, filterFrames);
}
}
}
void adjustValues(int cat, boolean neg){
if(cat == 0){
if(neg){
filterAmount = (Float) FastMath.clamp(filterAmount - 0.1f, 0, 1);
}
else{
filterAmount = (Float) FastMath.clamp(filterAmount + 0.1f, 0, 1);
}
amountLabel.setText((StringUtils.prettyNumber(filterAmount * 100f)) + "%");
server.config.setProperty("filters.amount", filterAmount);
}
else if(cat == 1){
if(neg){
filterFrames = (int) FastMath.clamp(filterFrames - 1, 0, 80);
}
else{
filterFrames = (int) FastMath.clamp(filterFrames + 1, 0, 80);
}
framesLabel.setText((StringUtils.prettyNumber(filterFrames)));
server.config.setProperty("filters.frameCount", filterFrames);
}
server.saveConfig();
updateTrackersFilters();
}
private class AdjButton extends JButton {
public AdjButton(String text, int category, boolean neg) {
super(text);
addMouseListener(new MouseInputAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
adjustValues(category, neg);
}
});
}
}
}
@@ -47,6 +47,7 @@ public class VRServerGUI extends JFrame {
public final VRServer server;
private final TrackersList trackersList;
private final TrackersFiltersGUI trackersFiltersGUI;
private final SkeletonList skeletonList;
private JButton resetButton;
private EJBox pane;
@@ -95,6 +96,7 @@ public class VRServerGUI extends JFrame {
getContentPane().setLayout(new BoxLayout(getContentPane(), PAGE_AXIS));
this.trackersList = new TrackersList(server, this);
trackersFiltersGUI = new TrackersFiltersGUI(server, this);
this.skeletonList = new SkeletonList(server, this);
this.poseStreamer = new ServerPoseStreamer(server);
@@ -353,6 +355,14 @@ public class VRServerGUI extends JFrame {
add(Box.createVerticalStrut(10));
}
add(l = new JLabel("Trackers filtering"));
l.setFont(l.getFont().deriveFont(Font.BOLD));
l.setAlignmentX(0.5f);
add(trackersFiltersGUI);
add(Box.createVerticalStrut(10));
add(new JLabel("Skeleton data"));
add(skeletonList);
add(Box.createVerticalGlue());
@@ -5,6 +5,7 @@ import com.jme3.math.FastMath;
import com.jme3.math.Quaternion;
import com.jme3.math.Vector3f;
import dev.slimevr.VRServer;
import dev.slimevr.vr.trackers.udp.TrackersUDPServer;
import io.eiren.util.BufferedTimer;
@@ -20,6 +21,8 @@ public class IMUTracker implements Tracker, TrackerWithTPS, TrackerWithBattery {
public final Quaternion rotAdjust = new Quaternion();
protected final Quaternion correction = new Quaternion();
protected LinkedList<Quaternion> previousRots = new LinkedList<Quaternion>();
public float movementFilterFrameCount = 0;
public float movementFilterAmount = 1f;
protected TrackerMountingRotation mounting = null;
protected TrackerStatus status = TrackerStatus.OK;
protected final int trackerId;
@@ -27,6 +30,7 @@ public class IMUTracker implements Tracker, TrackerWithTPS, TrackerWithBattery {
protected final String name;
protected final String descriptiveName;
protected final TrackersUDPServer server;
protected final VRServer vrserver;
protected float confidence = 0;
protected float batteryVoltage = 0;
protected float batteryLevel = 0;
@@ -43,11 +47,12 @@ public class IMUTracker implements Tracker, TrackerWithTPS, TrackerWithBattery {
public TrackerPosition bodyPosition = null;
public IMUTracker(int trackerId, String name, String descriptiveName, TrackersUDPServer server) {
public IMUTracker(int trackerId, String name, String descriptiveName, TrackersUDPServer server, VRServer vrserver) {
this.name = name;
this.server = server;
this.trackerId = trackerId;
this.descriptiveName = descriptiveName;
this.vrserver = vrserver;
}
@Override
@@ -77,9 +82,29 @@ public class IMUTracker implements Tracker, TrackerWithTPS, TrackerWithBattery {
rotAdjust.loadIdentity();
}
bodyPosition = TrackerPosition.getByDesignation(config.designation);
setFilter(vrserver.config.getString("filters.type"), vrserver.config.getFloat("filters.amount", 0.5f), vrserver.config.getInt("filters.frameCount", 3));
}
}
public void setFilter(String type, float amount, int frames){
amount = FastMath.clamp(amount, 0, 1f);
frames = (int) FastMath.clamp(frames, 0, 80);
switch(type){
case "INTERPOLATION":
movementFilterAmount = 1f - (amount / 2f);
movementFilterFrameCount = frames;
break;
case "EXTRAPOLATION":
movementFilterAmount = amount + 1;
movementFilterFrameCount = frames;
break;
case "NONE":
default:
movementFilterAmount = 1f;
movementFilterFrameCount = 0;
break;
}
}
public TrackerMountingRotation getMountingRotation() {
return mounting;
}
@@ -103,9 +128,11 @@ public class IMUTracker implements Tracker, TrackerWithTPS, TrackerWithBattery {
calculateLiveMagnetometerCorrection();
}
}
previousRots.addLast(new Quaternion(rotQuaternion));
if(previousRots.size() > 2){ // How far back in will getFilteredRotation go to get oldRot
previousRots.removeFirst();
if(movementFilterFrameCount != 0){
previousRots.addLast(new Quaternion(rotQuaternion));
if(previousRots.size() > movementFilterFrameCount){
previousRots.removeFirst();
}
}
}
@@ -122,8 +149,12 @@ public class IMUTracker implements Tracker, TrackerWithTPS, TrackerWithBattery {
@Override
public boolean getRotation(Quaternion store) {
float filterFactor = 1f; // 1 = do nothing, >0<1 = interpolation, >1 = exterpolation
store.set(getFilteredRotation(rotQuaternion, previousRots.getFirst(), filterFactor));
if(movementFilterFrameCount > 0 && movementFilterAmount != 1){
store.set(getFilteredRotation(rotQuaternion, previousRots.getFirst(), movementFilterAmount));
}
else{
store.set(rotQuaternion);
}
//correction.mult(store, store); // Correction is not used now to prevent accidental errors while debugging other things
store.multLocal(rotAdjust);
return true;
@@ -2,14 +2,15 @@ package dev.slimevr.vr.trackers;
import java.nio.ByteBuffer;
import dev.slimevr.VRServer;
import dev.slimevr.vr.trackers.udp.TrackersUDPServer;
public class MPUTracker extends IMUTracker {
public ConfigurationData newCalibrationData;
public MPUTracker(int trackerId, String name, String descriptiveName, TrackersUDPServer server) {
super(trackerId, name, descriptiveName, server);
public MPUTracker(int trackerId, String name, String descriptiveName, TrackersUDPServer server, VRServer vrserver) {
super(trackerId, name, descriptiveName, server, vrserver);
}
public static class ConfigurationData {
@@ -0,0 +1,7 @@
package dev.slimevr.vr.trackers;
public enum TrackerFilters {
NONE,
INTERPOLATION,
EXTRAPOLATION;
}
@@ -27,6 +27,7 @@ import com.jme3.math.FastMath;
import com.jme3.math.Quaternion;
import com.jme3.math.Vector3f;
import dev.slimevr.Main;
import dev.slimevr.NetworkProtocol;
import dev.slimevr.vr.trackers.IMUTracker;
import dev.slimevr.vr.trackers.ReferenceAdjustedTracker;
@@ -146,7 +147,7 @@ public class TrackersUDPServer extends Thread {
LogManager.log.info("[TrackerServer] Sensor " + trackerId + " for " + connection.name + " status: " + sensorStatus);
IMUTracker imu = connection.sensors.get(trackerId);
if(imu == null) {
imu = new IMUTracker(Tracker.getNextLocalTrackerId(), connection.name + "/" + trackerId, connection.descriptiveName + "/" + trackerId, this);
imu = new IMUTracker(Tracker.getNextLocalTrackerId(), connection.name + "/" + trackerId, connection.descriptiveName + "/" + trackerId, this, Main.vrServer);
connection.sensors.put(trackerId, imu);
ReferenceAdjustedTracker<IMUTracker> adjustedTracker = new ReferenceAdjustedTracker<>(imu);
trackersConsumer.accept(adjustedTracker);