From e195cce026de671dd4fd35ee40cb2664e1ec3f6d Mon Sep 17 00:00:00 2001 From: ori agranat Date: Wed, 27 Nov 2019 21:46:07 +0200 Subject: [PATCH] bug fixes in ui and bug fixes in sever handler -- updated pom --- Main/pom.xml | 6 --- .../chameleonvision/vision/VisionProcess.java | 15 +++--- .../chameleonvision/web/ServerHandler.java | 50 ++----------------- chameleon-client/src/store.js | 2 +- .../src/views/CameraViewes/InputTab.vue | 2 +- 5 files changed, 16 insertions(+), 59 deletions(-) diff --git a/Main/pom.xml b/Main/pom.xml index 7af954887..be09c112a 100644 --- a/Main/pom.xml +++ b/Main/pom.xml @@ -85,12 +85,6 @@ commons-math3 3.6.1 - - - com.google.code.gson - gson - 2.8.5 - org.msgpack msgpack-core diff --git a/Main/src/main/java/com/chameleonvision/vision/VisionProcess.java b/Main/src/main/java/com/chameleonvision/vision/VisionProcess.java index 0e8f19419..d8ccd5aa4 100644 --- a/Main/src/main/java/com/chameleonvision/vision/VisionProcess.java +++ b/Main/src/main/java/com/chameleonvision/vision/VisionProcess.java @@ -6,8 +6,8 @@ import com.chameleonvision.vision.camera.CameraCapture; import com.chameleonvision.vision.camera.CameraStreamer; import com.chameleonvision.vision.pipeline.*; import com.chameleonvision.web.ServerHandler; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; import edu.wpi.cscore.VideoMode; import edu.wpi.first.networktables.*; import edu.wpi.first.wpiutil.CircularBuffer; @@ -20,7 +20,6 @@ import java.util.List; import java.util.concurrent.BlockingQueue; import java.util.concurrent.LinkedBlockingDeque; -import static java.lang.Math.min; public class VisionProcess { @@ -51,7 +50,7 @@ public class VisionProcess { private NetworkTableEntry ntAreaEntry; private NetworkTableEntry ntTimeStampEntry; private NetworkTableEntry ntValidEntry; - private Gson gson = new GsonBuilder().setPrettyPrinting().create(); + private ObjectMapper objectMapper; VisionProcess(CameraCapture cameraCapture, String name) { this.cameraCapture = cameraCapture; @@ -172,6 +171,7 @@ public class VisionProcess { center.add(bestTarget.rawPoint.center.y); calculated.put("pitch", bestTarget.pitch); calculated.put("yaw", bestTarget.yaw); + calculated.put("area", bestTarget.area); } else if (data instanceof CVPipeline3d.CVPipeline3dResult) { // TODO: (2.1) 3d stuff in UI } else { @@ -205,8 +205,11 @@ public class VisionProcess { ntPitchEntry.setDouble(targets.get(0).pitch); ntYawEntry.setDouble(targets.get(0).yaw); ntAreaEntry.setDouble(targets.get(0).area); - ntAuxListEntry.setString(gson.toJson(targets.subList(0, min(targets.size(), 5)))); - + try { + ntAreaEntry.setString(objectMapper.writeValueAsString(targets)); + } catch (JsonProcessingException e) { + e.printStackTrace(); + } } else if (data instanceof CVPipeline3d.CVPipeline3dResult) { // TODO: (2.1) 3d stuff... } diff --git a/Main/src/main/java/com/chameleonvision/web/ServerHandler.java b/Main/src/main/java/com/chameleonvision/web/ServerHandler.java index ee4e984e5..71aea9519 100644 --- a/Main/src/main/java/com/chameleonvision/web/ServerHandler.java +++ b/Main/src/main/java/com/chameleonvision/web/ServerHandler.java @@ -214,9 +214,9 @@ public class ServerHandler { broadcastMessage(obj, null);//Broadcasts the message to every user } - private static HashMap getOrdinalPipeline() throws IllegalAccessException { + private static HashMap getOrdinalPipeline(Class cvClass) throws IllegalAccessException { HashMap tmp = new HashMap<>(); - for (Field field : CVPipelineSettings.class.getFields()) { // iterate over every field in CVPipelineSettings + for (Field field :cvClass.getFields()) { // iterate over every field in CVPipelineSettings try { if (!field.getType().isEnum()) { // if the field is not an enum, get it based on the current pipeline tmp.put(field.getName(), field.get(VisionManager.getCurrentUIVisionProcess().getCurrentPipeline().settings)); @@ -263,45 +263,6 @@ public class ServerHandler { return tmp; } - private static Map settingsToMap(GeneralSettings settings) { - Map map = new HashMap<>(); - map.put("team_number", settings.teamNumber); - map.put("connection_type", settings.connectionType); - map.put("ip", settings.ip); - map.put("gateway", settings.gateway); - map.put("netmask", settings.netmask); - map.put("hostname", settings.hostname); - map.put("curr_camera", settings.currentCamera); - map.put("curr_pipeline", settings.currentPipeline); - - return map; - } - - private static Map pipelineToMap(CVPipelineSettings s) { - Map map = new HashMap<>(); - map.put("exposure", s.exposure); - map.put("brightness", s.brightness); - if(s instanceof CVPipeline2dSettings) { - var s_ = (CVPipeline2dSettings) s; - map.put("orientation", s.flipMode.name()); - map.put("hue", s_.hue); - map.put("saturation", s_.saturation); - map.put("value", s_.value); - map.put("erode", s_.erode); - map.put("dilate", s_.dilate); - map.put("area", s_.area); - map.put("ratio", s_.ratio); - map.put("extent", s_.extent); - map.put("is_binary", s_.isBinary); - map.put("sort_mode", s_.sortMode.name()); - map.put("target_group", s_.targetGroup.name()); - map.put("target_intersection", s_.targetIntersection.name()); - map.put("M", s_.dualTargetCalibrationM); - map.put("B", s_.dualTargetCalibrationB); - map.put("is_calibrated", !s_.calibrationMode.equals(CalibrationMode.None)); - } - return map; - } public static void sendFullSettings() { //General settings Map fullSettings = new HashMap<>(); @@ -311,16 +272,15 @@ public class ServerHandler { CVPipeline currentPipeline = currentProcess.getCurrentPipeline(); try { - fullSettings.putAll(settingsToMap(ConfigManager.settings)); - fullSettings.putAll(pipelineToMap(currentPipeline.settings)); +// fullSettings.putAll(settingsToMap(ConfigManager.settings)); +// fullSettings.putAll(pipelineToMap(currentPipeline.settings)); fullSettings.put("settings", getOrdinalSettings()); fullSettings.put("cameraSettings", getOrdinalCameraSettings()); fullSettings.put("cameraList", VisionManager.getAllCameraNicknames()); - fullSettings.put("pipeline", getOrdinalPipeline()); + fullSettings.put("pipeline", getOrdinalPipeline(currentPipeline.settings.getClass())); fullSettings.put("driverMode", getOrdinalDriver()); fullSettings.put("pipelineList", VisionManager.getCurrentCameraPipelineNicknames()); fullSettings.put("resolutionList", VisionManager.getCurrentCameraResolutionList()); - fullSettings.put("FOV", currentCamera.getProperties().FOV); fullSettings.put("port", currentProcess.cameraStreamer.getStreamPort()); fullSettings.put("currentPipelineIndex", VisionManager.getCurrentUIVisionProcess().getCurrentPipelineIndex()); fullSettings.put("currentCameraIndex", VisionManager.getCurrentUIVisionProcessIndex()); diff --git a/chameleon-client/src/store.js b/chameleon-client/src/store.js index b0c9fbd2d..c4353706b 100644 --- a/chameleon-client/src/store.js +++ b/chameleon-client/src/store.js @@ -20,7 +20,7 @@ export default new Vuex.Store({ pipeline: { exposure: 0, brightness: 0, - orientation: 0, + flipMode: 0, hue: [0, 15], saturation: [0, 15], value: [0, 25], diff --git a/chameleon-client/src/views/CameraViewes/InputTab.vue b/chameleon-client/src/views/CameraViewes/InputTab.vue index 4f1681739..c872e0109 100644 --- a/chameleon-client/src/views/CameraViewes/InputTab.vue +++ b/chameleon-client/src/views/CameraViewes/InputTab.vue @@ -2,7 +2,7 @@
-