2019-11-23 11:55:20 -05:00
|
|
|
package com.chameleonvision.config;
|
2019-11-19 12:43:38 -05:00
|
|
|
|
2019-12-09 03:32:22 -05:00
|
|
|
import com.chameleonvision.util.*;
|
2019-11-23 19:39:24 +02:00
|
|
|
import com.chameleonvision.vision.pipeline.CVPipelineSettings;
|
2019-11-19 12:06:37 -08:00
|
|
|
|
2019-11-25 05:34:04 -05:00
|
|
|
import java.io.File;
|
2019-11-19 12:43:38 -05:00
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.nio.file.Files;
|
|
|
|
|
import java.nio.file.Path;
|
|
|
|
|
import java.nio.file.Paths;
|
|
|
|
|
import java.util.ArrayList;
|
2019-11-26 17:57:51 -05:00
|
|
|
import java.util.LinkedHashMap;
|
2019-11-19 12:43:38 -05:00
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
public class ConfigManager {
|
|
|
|
|
private ConfigManager() {}
|
|
|
|
|
|
2019-12-09 03:10:43 -05:00
|
|
|
public static final Path SettingsPath = Paths.get(ProgramDirectoryUtilities.getProgramDirectory(), "settings");
|
2019-11-23 12:23:21 -05:00
|
|
|
private static final Path settingsFilePath = Paths.get(SettingsPath.toString(), "settings.json");
|
2019-11-19 12:43:38 -05:00
|
|
|
|
2019-11-26 17:57:51 -05:00
|
|
|
private static final LinkedHashMap<String, CameraConfig> cameraConfigs = new LinkedHashMap<>();
|
|
|
|
|
|
2019-11-19 12:43:38 -05:00
|
|
|
public static GeneralSettings settings = new GeneralSettings();
|
|
|
|
|
|
2019-11-23 12:23:21 -05:00
|
|
|
private static boolean settingsFolderExists() { return Files.exists(SettingsPath); }
|
|
|
|
|
private static boolean settingsFileExists() { return settingsFolderExists() && Files.exists(settingsFilePath); }
|
|
|
|
|
|
|
|
|
|
private static void checkSettingsFolder() {
|
|
|
|
|
if (!settingsFolderExists()) {
|
2019-11-19 12:43:38 -05:00
|
|
|
try {
|
2019-11-27 14:59:36 -05:00
|
|
|
if( !(new File(SettingsPath.toUri()).mkdirs()) ) {
|
|
|
|
|
System.err.println("Failed to create settings folder: " + SettingsPath.toString());
|
|
|
|
|
}
|
2019-11-19 12:43:38 -05:00
|
|
|
Files.createDirectory(SettingsPath);
|
2019-12-09 03:32:22 -05:00
|
|
|
if (!Platform.CurrentPlatform.isWindows()) {
|
2019-12-09 03:10:43 -05:00
|
|
|
new ShellExec().executeBashCommand("sudo chmod -R 0777 " + SettingsPath.toString());
|
|
|
|
|
}
|
2019-11-19 12:43:38 -05:00
|
|
|
} catch (IOException e) {
|
2019-11-27 14:59:36 -05:00
|
|
|
if(!(e instanceof java.nio.file.FileAlreadyExistsException))
|
2019-11-27 08:58:20 -08:00
|
|
|
e.printStackTrace();
|
2019-11-19 12:43:38 -05:00
|
|
|
}
|
|
|
|
|
}
|
2019-11-23 12:23:21 -05:00
|
|
|
}
|
2019-11-19 12:43:38 -05:00
|
|
|
|
2019-11-23 12:23:21 -05:00
|
|
|
private static void checkSettingsFile() {
|
2019-11-25 05:34:04 -05:00
|
|
|
boolean settingsFileEmpty = settingsFileExists() && new File(settingsFilePath.toString()).length() == 0;
|
|
|
|
|
if (settingsFileEmpty || !settingsFileExists()) {
|
2019-11-19 12:43:38 -05:00
|
|
|
try {
|
2019-11-26 17:57:51 -05:00
|
|
|
JacksonHelper.serializer(settingsFilePath, settings);
|
2019-12-09 03:32:22 -05:00
|
|
|
FileHelper.setFilePerms(settingsFilePath);
|
2019-11-19 12:43:38 -05:00
|
|
|
} catch (IOException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
try {
|
2020-01-20 21:05:43 +02:00
|
|
|
settings = JacksonHelper.deserialize(settingsFilePath, GeneralSettings.class);
|
2019-11-19 12:43:38 -05:00
|
|
|
} catch (IOException e) {
|
|
|
|
|
System.err.println("Failed to load settings.json, using defaults.");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-23 12:23:21 -05:00
|
|
|
public static void initializeSettings() {
|
2019-11-26 17:57:51 -05:00
|
|
|
System.out.println("Settings folder: " + SettingsPath.toString());
|
2019-11-23 12:23:21 -05:00
|
|
|
checkSettingsFolder();
|
|
|
|
|
checkSettingsFile();
|
Add solvePNP, 3d tab on the UI, and some other misc bug fixes (#35)
* Rebase solvePNP on master
* added 3D tab minimap and csv reader
* More solvePNP
* Create draw pipe for pnp data
* SolvePNP piping work
* Move sorting into solvepnppipe
* Create calibration pipeline
* Update CalibrateSolvePNPPipeline.java
* add camera tilt angle
* Add calibration slider and snapshot button to 3D view
* Mirror updates in the socket handler
* add 3d calibration mode to the pipeline manager
* created calibration functions in ui and backend
* Start plumbing calibration
* Add snapshot and other handling to the RequestHandler
* added select resolution before starting calibration
* Rename solvePNPPipe to bounding box solve pnp pipe
* Update BoundingBoxSolvePNPPipe.java
* Add Mat serializer and CameraCalibrationConfig
* Begun calibration saving, fixed UI/Backend snapshot count mismatch
* Add (unplumbed) option to set checkerboard size
This will allow users to change the units their calibration is in
* Create chessboard.png
* Fix calibration NPE
* changed string serialization to a json send
* bug fixed cancellation button
* Fix spelling of snapshot in 3d.vue
* Plumb resolution change
* Set resolution during config, start on config serialization
* Update .gitignore
* Config fixes
* Start transition away from cvpipeline3d
* fix NPE on uncalibrated cameras
* clear list on fail
* Fix video mode index error
* ignore getters in camera calibration config
* Create json constructor for jsonmat
* get solvePNP mostly returning sane values
* Fix solvePNP bug and add unit test
* FIx calibration mat truncation
* added capture amount model upload and minimap data
* Standardize on meters in calibration and bounding box
* fix json out of bounds and handle null calibration more gracefully
* don't put text on calibrate image, go back to inches
* convert distance to meters
this means calibration will need to be in inches
* Actually save raw contor
* Update GroupContoursPipe.java
* Add all calibration return to camera capture
* hard code 2019 target
* bugfixed draw2d added fail calib popup, merge end and cancel
added the res index to the calib start
* Clarify error message and draw more fancy rectangles
* Cleanup memory in solvepnp
* re did minimap component
* fix npe if left/right is null
* remove references to 2d
* try-catch running the current pipeline
* Add method to find corners using the harris corner detector
* Possibly fix left/right missmatch
* Fix 3D Tab error
* FIx file permissions, mat serializer adjustments
* fixed mini map for field coordinates
* mini map changes fov
* Update SolvePNPPipe.java
* get rid of target corners
* some memory leak fixes
* fixed mini map location
* added position under minimap
* changed player fov look
* put all targets in the web send
* re did target send to ui added target tables, bugfix calibration
* fixed y position
* Add tilt angle to capture properties
* maybe fix y axis in minimap
* Add square size to onCalibrationEnding
* Possibly add square size to UI
* fix NPE with pitch
* Fix bug with sending multiple targets
* Only instantiate 3d stuff if we are in 3d mode
* Fix array list exceptions
* Fix bug in sort contors
list was truncated too early
* added download chess, tilt setting and ordinal tilt,
* added square size connection
* removed unused code
* Update pom version to 2.1-RELEASE
* Send camera calibrations to UI
* Stream pose list to a LIst
* Only stream necessary parts of the aux list entry
* Make broadcastMessage synchronized to prevent ConcurrentModificationExceptions
* added fps counter changed squaresize steps bug fixes in tables
* bugfix camera settings cam wont change
Authored-by: oriagranat9 <oriagranat9@gmail.com>
2019-12-31 04:53:20 -08:00
|
|
|
FileHelper.setAllPerms(SettingsPath);
|
2019-11-23 12:23:21 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void saveSettingsFile() {
|
|
|
|
|
try {
|
2019-11-26 17:57:51 -05:00
|
|
|
JacksonHelper.serializer(settingsFilePath, settings);
|
2019-12-09 03:32:22 -05:00
|
|
|
FileHelper.setFilePerms(settingsFilePath);
|
2019-11-23 12:23:21 -05:00
|
|
|
} catch (IOException e) {
|
|
|
|
|
System.err.println("Failed to save settings.json!");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-26 23:03:07 -05:00
|
|
|
public static void saveGeneralSettings() {
|
2019-11-23 12:23:21 -05:00
|
|
|
checkSettingsFolder();
|
|
|
|
|
saveSettingsFile();
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-26 17:57:51 -05:00
|
|
|
public static List<FullCameraConfiguration> initializeCameras(List<CameraJsonConfig> preliminaryConfigs) {
|
|
|
|
|
List<FullCameraConfiguration> configList = new ArrayList<>();
|
2019-11-23 12:23:21 -05:00
|
|
|
|
2019-11-26 17:57:51 -05:00
|
|
|
checkSettingsFolder();
|
2019-11-23 12:23:21 -05:00
|
|
|
|
2019-11-26 17:57:51 -05:00
|
|
|
// loop over all the camera names and try to create settings folders for it
|
|
|
|
|
for (CameraJsonConfig preliminaryConfig : preliminaryConfigs) {
|
|
|
|
|
CameraConfig cameraConfiguration = new CameraConfig(preliminaryConfig);
|
|
|
|
|
cameraConfigs.put(preliminaryConfig.name, cameraConfiguration);
|
2019-11-23 12:23:21 -05:00
|
|
|
|
2019-11-27 19:51:49 -08:00
|
|
|
FullCameraConfiguration camJsonConfig = cameraConfiguration.load();
|
2019-11-23 12:23:21 -05:00
|
|
|
|
2019-11-27 19:51:49 -08:00
|
|
|
configList.add(camJsonConfig);
|
2019-11-26 17:57:51 -05:00
|
|
|
}
|
2019-11-23 12:23:21 -05:00
|
|
|
|
2019-11-26 17:57:51 -05:00
|
|
|
return configList;
|
2019-11-23 12:23:21 -05:00
|
|
|
}
|
|
|
|
|
|
2019-11-26 17:57:51 -05:00
|
|
|
public static void saveCameraConfig(String cameraName, CameraJsonConfig config) {
|
2019-11-27 14:59:36 -05:00
|
|
|
var camConf = cameraConfigs.get(cameraName);
|
|
|
|
|
camConf.saveConfig(config);
|
2019-11-23 12:23:21 -05:00
|
|
|
}
|
|
|
|
|
|
2019-11-26 17:57:51 -05:00
|
|
|
public static void saveCameraPipelines(String cameraName, List<CVPipelineSettings> pipelines) {
|
2019-11-27 14:59:36 -05:00
|
|
|
var camConf = cameraConfigs.get(cameraName);
|
|
|
|
|
camConf.savePipelines(pipelines);
|
2019-11-23 12:23:21 -05:00
|
|
|
}
|
|
|
|
|
|
2019-11-26 17:57:51 -05:00
|
|
|
public static void saveCameraDriverMode(String cameraName, CVPipelineSettings driverMode) {
|
2019-11-27 14:59:36 -05:00
|
|
|
var camConf = cameraConfigs.get(cameraName);
|
|
|
|
|
camConf.saveDriverMode(driverMode);
|
2019-11-23 19:39:24 +02:00
|
|
|
}
|
2019-11-19 12:43:38 -05:00
|
|
|
}
|