mirror of
https://github.com/PhotonVision/photonvision
synced 2026-07-05 03:21:40 +00:00
Logging additions 2 (#55)
* Add overload to logger.error() for Throwable to print stack trace * Replaced all e.printStackTrace() with logger.error() * Log level dependent on dev or release
This commit is contained in:
@@ -40,11 +40,12 @@ public class Main {
|
|||||||
public static final int DEFAULT_WEBPORT = 5800;
|
public static final int DEFAULT_WEBPORT = 5800;
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
Logger.setLevel(LogGroup.Camera, LogLevel.TRACE);
|
var logLevel = PhotonVersion.isRelease ? LogLevel.ERROR : LogLevel.TRACE;
|
||||||
Logger.setLevel(LogGroup.WebServer, LogLevel.TRACE);
|
Logger.setLevel(LogGroup.Camera, logLevel);
|
||||||
Logger.setLevel(LogGroup.VisionModule, LogLevel.TRACE);
|
Logger.setLevel(LogGroup.WebServer, logLevel);
|
||||||
Logger.setLevel(LogGroup.Data, LogLevel.TRACE);
|
Logger.setLevel(LogGroup.VisionModule, logLevel);
|
||||||
Logger.setLevel(LogGroup.General, LogLevel.TRACE);
|
Logger.setLevel(LogGroup.Data, logLevel);
|
||||||
|
Logger.setLevel(LogGroup.General, logLevel);
|
||||||
|
|
||||||
logger.info("Logging initialized!");
|
logger.info("Logging initialized!");
|
||||||
|
|
||||||
@@ -57,8 +58,7 @@ public class Main {
|
|||||||
logger.info("Loading native libraries...");
|
logger.info("Loading native libraries...");
|
||||||
CameraServerCvJNI.forceLoad();
|
CameraServerCvJNI.forceLoad();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("Failed to load native libraries!");
|
logger.error("Failed to load native libraries!", e);
|
||||||
e.printStackTrace(); // TODO: redirect stacktrace to Logger stream somehow
|
|
||||||
}
|
}
|
||||||
logger.info("Native libaries loaded.");
|
logger.info("Native libaries loaded.");
|
||||||
|
|
||||||
|
|||||||
@@ -132,14 +132,12 @@ public class ConfigManager {
|
|||||||
try {
|
try {
|
||||||
JacksonUtils.serializer(hardwareConfigFile.toPath(), config.getHardwareConfig());
|
JacksonUtils.serializer(hardwareConfigFile.toPath(), config.getHardwareConfig());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
logger.error("Could not save hardware config!");
|
logger.error("Could not save hardware config!", e);
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
JacksonUtils.serializer(networkConfigFile.toPath(), config.getNetworkConfig());
|
JacksonUtils.serializer(networkConfigFile.toPath(), config.getNetworkConfig());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
logger.error("Could not save network config!");
|
logger.error("Could not save network config!", e);
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// save all of our cameras
|
// save all of our cameras
|
||||||
@@ -172,8 +170,7 @@ public class ConfigManager {
|
|||||||
if (pipelineFolder.toFile().exists())
|
if (pipelineFolder.toFile().exists())
|
||||||
Files.list(pipelineFolder).map(Path::toFile).filter(File::exists).forEach(File::delete);
|
Files.list(pipelineFolder).map(Path::toFile).filter(File::exists).forEach(File::delete);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
logger.error("Exception while deleting old configs!");
|
logger.error("Exception while deleting old configs!", e);
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var pipe : camConfig.pipelineSettings) {
|
for (var pipe : camConfig.pipelineSettings) {
|
||||||
@@ -187,7 +184,7 @@ public class ConfigManager {
|
|||||||
try {
|
try {
|
||||||
JacksonUtils.serializer(pipePath, pipe);
|
JacksonUtils.serializer(pipePath, pipe);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
logger.error("Could not save " + pipe.pipelineNickname + ".json!");
|
logger.error("Could not save " + pipe.pipelineNickname + ".json!", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -209,7 +206,7 @@ public class ConfigManager {
|
|||||||
JacksonUtils.deserialize(
|
JacksonUtils.deserialize(
|
||||||
cameraConfigPath.toAbsolutePath(), CameraConfiguration.class);
|
cameraConfigPath.toAbsolutePath(), CameraConfiguration.class);
|
||||||
} catch (JsonProcessingException e) {
|
} catch (JsonProcessingException e) {
|
||||||
e.printStackTrace();
|
logger.error("Camera config deserialization failed!", e);
|
||||||
}
|
}
|
||||||
if (loadedConfig == null) { // If the file could not be deserialized
|
if (loadedConfig == null) { // If the file could not be deserialized
|
||||||
logger.warn("Could not load camera " + subdir + "'s config.json! Loading " + "default");
|
logger.warn("Could not load camera " + subdir + "'s config.json! Loading " + "default");
|
||||||
@@ -250,8 +247,7 @@ public class ConfigManager {
|
|||||||
try {
|
try {
|
||||||
return JacksonUtils.deserialize(p, CVPipelineSettings.class);
|
return JacksonUtils.deserialize(p, CVPipelineSettings.class);
|
||||||
} catch (JsonProcessingException e) {
|
} catch (JsonProcessingException e) {
|
||||||
logger.error("Exception while deserializing " + relativizedFilePath);
|
logger.error("Exception while deserializing " + relativizedFilePath, e);
|
||||||
e.printStackTrace();
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
logger.warn(
|
logger.warn(
|
||||||
"Could not load pipeline at "
|
"Could not load pipeline at "
|
||||||
@@ -270,7 +266,7 @@ public class ConfigManager {
|
|||||||
loadedConfigurations.put(subdir.toFile().getName(), loadedConfig);
|
loadedConfigurations.put(subdir.toFile().getName(), loadedConfig);
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
logger.error("Error loading camera configs!", e);
|
||||||
}
|
}
|
||||||
return loadedConfigurations;
|
return loadedConfigurations;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,8 +67,7 @@ public class DataChangeService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("Exception when dispatching event!");
|
logger.error("Exception when dispatching event!", e);
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,8 @@
|
|||||||
package org.photonvision.common.logging;
|
package org.photonvision.common.logging;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.PrintWriter;
|
||||||
|
import java.io.StringWriter;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.channels.AsynchronousFileChannel;
|
import java.nio.channels.AsynchronousFileChannel;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
@@ -33,6 +35,7 @@ import org.photonvision.common.dataflow.events.OutgoingUIEvent;
|
|||||||
import org.photonvision.server.SocketHandler;
|
import org.photonvision.server.SocketHandler;
|
||||||
import org.photonvision.server.UIUpdateType;
|
import org.photonvision.server.UIUpdateType;
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
public class Logger {
|
public class Logger {
|
||||||
|
|
||||||
public static final String ANSI_RESET = "\u001B[0m";
|
public static final String ANSI_RESET = "\u001B[0m";
|
||||||
@@ -85,8 +88,8 @@ public class Logger {
|
|||||||
return builder.toString();
|
return builder.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static HashMap<LogGroup, LogLevel> levelMap = new HashMap<>();
|
private static final HashMap<LogGroup, LogLevel> levelMap = new HashMap<>();
|
||||||
private static List<LogAppender> currentAppenders = new ArrayList<>();
|
private static final List<LogAppender> currentAppenders = new ArrayList<>();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
levelMap.put(LogGroup.Camera, LogLevel.INFO);
|
levelMap.put(LogGroup.Camera, LogLevel.INFO);
|
||||||
@@ -101,6 +104,7 @@ public class Logger {
|
|||||||
currentAppenders.add(new UILogAppender());
|
currentAppenders.add(new UILogAppender());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("ResultOfMethodCallIgnored")
|
||||||
public static void addFileAppender(Path logFilePath) {
|
public static void addFileAppender(Path logFilePath) {
|
||||||
var file = logFilePath.toFile();
|
var file = logFilePath.toFile();
|
||||||
if (!file.exists()) {
|
if (!file.exists()) {
|
||||||
@@ -151,6 +155,11 @@ public class Logger {
|
|||||||
log(message, LogLevel.ERROR);
|
log(message, LogLevel.ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void error(String message, Throwable t) {
|
||||||
|
log(message, LogLevel.ERROR);
|
||||||
|
log(convertStackTraceToString(t), LogLevel.ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
public void warn(Supplier<String> messageSupplier) {
|
public void warn(Supplier<String> messageSupplier) {
|
||||||
log(messageSupplier, LogLevel.WARN);
|
log(messageSupplier, LogLevel.WARN);
|
||||||
}
|
}
|
||||||
@@ -183,6 +192,16 @@ public class Logger {
|
|||||||
log(message, LogLevel.TRACE);
|
log(message, LogLevel.TRACE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String convertStackTraceToString(Throwable throwable) {
|
||||||
|
try (StringWriter sw = new StringWriter();
|
||||||
|
PrintWriter pw = new PrintWriter(sw)) {
|
||||||
|
throwable.printStackTrace(pw);
|
||||||
|
return sw.toString();
|
||||||
|
} catch (IOException ioe) {
|
||||||
|
throw new IllegalStateException(ioe);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private interface LogAppender {
|
private interface LogAppender {
|
||||||
void log(String message, LogLevel level);
|
void log(String message, LogLevel level);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ public class LinuxNetworking extends SysNetworking {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
logger.error("Failed to set DHCP!", e);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,7 +78,7 @@ public class LinuxNetworking extends SysNetworking {
|
|||||||
var setHostnameRetCode = shell.execute("hostnamectl", "set-hostname", newHostname);
|
var setHostnameRetCode = shell.execute("hostnamectl", "set-hostname", newHostname);
|
||||||
return setHostnameRetCode == 0;
|
return setHostnameRetCode == 0;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
logger.error("Failed to set hostname!", e);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -97,7 +97,7 @@ public class LinuxNetworking extends SysNetworking {
|
|||||||
FileUtils.writeLines(dhcpConf, lines);
|
FileUtils.writeLines(dhcpConf, lines);
|
||||||
return true;
|
return true;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
logger.error("Failed to set Static IP!", e);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,9 +18,13 @@
|
|||||||
package org.photonvision.common.networking;
|
package org.photonvision.common.networking;
|
||||||
|
|
||||||
import java.net.InterfaceAddress;
|
import java.net.InterfaceAddress;
|
||||||
|
import org.photonvision.common.logging.LogGroup;
|
||||||
|
import org.photonvision.common.logging.Logger;
|
||||||
|
|
||||||
@SuppressWarnings("WeakerAccess")
|
@SuppressWarnings("WeakerAccess")
|
||||||
public class NetworkInterface {
|
public class NetworkInterface {
|
||||||
|
private static final Logger logger = new Logger(NetworkInterface.class, LogGroup.General);
|
||||||
|
|
||||||
public final String name;
|
public final String name;
|
||||||
public final String displayName;
|
public final String displayName;
|
||||||
public final String IPAddress;
|
public final String IPAddress;
|
||||||
@@ -68,7 +72,7 @@ public class NetworkInterface {
|
|||||||
+ (shiftby & 255);
|
+ (shiftby & 255);
|
||||||
// return InetAddress.getByName(maskString);
|
// return InetAddress.getByName(maskString);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
logger.error("Failed to get netmask!", e);
|
||||||
}
|
}
|
||||||
// Something went wrong here...
|
// Something went wrong here...
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ public class ScriptEvent {
|
|||||||
String error = executor.getError();
|
String error = executor.getError();
|
||||||
|
|
||||||
if (!error.isEmpty()) {
|
if (!error.isEmpty()) {
|
||||||
System.err.printf("Error when running \"%s\" script: %s\n", config.eventType.name(), error);
|
logger.error("Error when running \"" + config.eventType.name() + "\" script: " + error);
|
||||||
} else if (!output.isEmpty()) {
|
} else if (!output.isEmpty()) {
|
||||||
logger.info(
|
logger.info(
|
||||||
String.format("Output from \"%s\" script: %s\n", config.eventType.name(), output));
|
String.format("Output from \"%s\" script: %s\n", config.eventType.name(), output));
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ public class ScriptManager {
|
|||||||
TimedTaskManager.getInstance().addTask("ScriptRunner", new ScriptRunner(), 10);
|
TimedTaskManager.getInstance().addTask("ScriptRunner", new ScriptRunner(), 10);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
System.err.println("Something went wrong initializing scripts! Events will not run.");
|
logger.error("Something went wrong initializing scripts! Events will not run.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,7 +61,7 @@ public class ScriptManager {
|
|||||||
try {
|
try {
|
||||||
handleEvent(queuedEvents.takeFirst());
|
handleEvent(queuedEvents.takeFirst());
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
e.printStackTrace();
|
logger.error("ScriptRunner queue interrupted!", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,9 +76,7 @@ public class ScriptManager {
|
|||||||
try {
|
try {
|
||||||
toRun.run();
|
toRun.run();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
System.err.printf(
|
logger.error("Failed to run script for event \"" + eventType.name() + "\"", e);
|
||||||
"Failed to run script for event: %s, exception below.\n%s\n",
|
|
||||||
eventType.name(), e.getMessage());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -107,7 +105,7 @@ public class ScriptManager {
|
|||||||
JacksonUtils.serializer(
|
JacksonUtils.serializer(
|
||||||
scriptConfigPath, eventsConfig.toArray(new ScriptConfig[0]), true);
|
scriptConfigPath, eventsConfig.toArray(new ScriptConfig[0]), true);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
logger.error("Failed to initialize!", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -119,7 +117,7 @@ public class ScriptManager {
|
|||||||
return List.of(raw);
|
return List.of(raw);
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
logger.error("Failed to load scripting config!", e);
|
||||||
}
|
}
|
||||||
return new ArrayList<>();
|
return new ArrayList<>();
|
||||||
}
|
}
|
||||||
@@ -139,7 +137,7 @@ public class ScriptManager {
|
|||||||
queuedEvents.putLast(eventType);
|
queuedEvents.putLast(eventType);
|
||||||
logger.info("Queued event: " + eventType.name());
|
logger.info("Queued event: " + eventType.name());
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
System.err.println("Failed to add event to queue: " + eventType.name());
|
logger.error("Failed to add event to queue: " + eventType.name(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,8 @@ package org.photonvision.common.util;
|
|||||||
import edu.wpi.first.wpiutil.RuntimeDetector;
|
import edu.wpi.first.wpiutil.RuntimeDetector;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import org.apache.commons.lang3.SystemUtils;
|
import org.apache.commons.lang3.SystemUtils;
|
||||||
|
import org.photonvision.common.logging.LogGroup;
|
||||||
|
import org.photonvision.common.logging.Logger;
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public enum Platform {
|
public enum Platform {
|
||||||
@@ -42,6 +44,8 @@ public enum Platform {
|
|||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static final Logger logger = new Logger(Platform.class, LogGroup.General);
|
||||||
|
|
||||||
public static final Platform CurrentPlatform = getCurrentPlatform();
|
public static final Platform CurrentPlatform = getCurrentPlatform();
|
||||||
|
|
||||||
public static boolean isWindows() {
|
public static boolean isWindows() {
|
||||||
@@ -64,7 +68,7 @@ public enum Platform {
|
|||||||
try {
|
try {
|
||||||
shell.execute("id", null, true, "-u");
|
shell.execute("id", null, true, "-u");
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
logger.error("Failed to perform root check!", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
while (!shell.isOutputCompleted()) {
|
while (!shell.isOutputCompleted()) {
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ import org.photonvision.common.logging.LogGroup;
|
|||||||
import org.photonvision.common.logging.Logger;
|
import org.photonvision.common.logging.Logger;
|
||||||
|
|
||||||
public final class SerializationUtils {
|
public final class SerializationUtils {
|
||||||
private static final Logger LOGGER = new Logger(SerializationUtils.class, LogGroup.General);
|
private static final Logger logger = new Logger(SerializationUtils.class, LogGroup.General);
|
||||||
|
|
||||||
public static HashMap<String, Object> objectToHashMap(Object src) {
|
public static HashMap<String, Object> objectToHashMap(Object src) {
|
||||||
var ret = new HashMap<String, Object>();
|
var ret = new HashMap<String, Object>();
|
||||||
@@ -37,8 +37,7 @@ public final class SerializationUtils {
|
|||||||
ret.put(field.getName(), ordinal.ordinal());
|
ret.put(field.getName(), ordinal.ordinal());
|
||||||
}
|
}
|
||||||
} catch (IllegalArgumentException | IllegalAccessException e) {
|
} catch (IllegalArgumentException | IllegalAccessException e) {
|
||||||
LOGGER.error("Could not serialize " + src.getClass().getSimpleName());
|
logger.error("Could not serialize " + src.getClass().getSimpleName(), e);
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ public class FileUtils {
|
|||||||
p.waitFor();
|
p.waitFor();
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
logger.error("Setting perms failed!", e);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
logger.info("Cannot set directory permissions on Windows!");
|
logger.info("Cannot set directory permissions on Windows!");
|
||||||
|
|||||||
@@ -272,14 +272,12 @@ public class SocketHandler {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception ex) {
|
} catch (Exception e) {
|
||||||
logger.error("unknown booboo");
|
logger.error("Failed to parse message!", e);
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
// TODO: log
|
logger.error("Failed to deserialize message!", e);
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -71,8 +71,7 @@ class UIOutboundSubscriber extends DataChangeSubscriber {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (JsonProcessingException e) {
|
} catch (JsonProcessingException e) {
|
||||||
// TODO: Log
|
logger.error("Failed to process outgoing message!", e);
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -135,8 +135,7 @@ public class USBCameraSource implements VisionSource {
|
|||||||
videoModesList.add(videoMode);
|
videoModesList.add(videoMode);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("Exception while enumerating video modes!");
|
logger.error("Exception while enumerating video modes!", e);
|
||||||
e.printStackTrace();
|
|
||||||
videoModesList = List.of();
|
videoModesList = List.of();
|
||||||
}
|
}
|
||||||
for (VideoMode videoMode : videoModesList) {
|
for (VideoMode videoMode : videoModesList) {
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ public class Calibrate3dPipe
|
|||||||
stdDeviationsExtrinsics,
|
stdDeviationsExtrinsics,
|
||||||
perViewErrors);
|
perViewErrors);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
logger.error("Calibration failed!", e);
|
||||||
}
|
}
|
||||||
JsonMat cameraMatrixMat = JsonMat.fromMat(cameraMatrix);
|
JsonMat cameraMatrixMat = JsonMat.fromMat(cameraMatrix);
|
||||||
JsonMat distortionCoefficientsMat = JsonMat.fromMat(distortionCoefficients);
|
JsonMat distortionCoefficientsMat = JsonMat.fromMat(distortionCoefficients);
|
||||||
|
|||||||
@@ -27,6 +27,8 @@ import org.opencv.core.Core;
|
|||||||
import org.opencv.core.Mat;
|
import org.opencv.core.Mat;
|
||||||
import org.opencv.core.MatOfPoint2f;
|
import org.opencv.core.MatOfPoint2f;
|
||||||
import org.opencv.core.Scalar;
|
import org.opencv.core.Scalar;
|
||||||
|
import org.photonvision.common.logging.LogGroup;
|
||||||
|
import org.photonvision.common.logging.Logger;
|
||||||
import org.photonvision.vision.calibration.CameraCalibrationCoefficients;
|
import org.photonvision.vision.calibration.CameraCalibrationCoefficients;
|
||||||
import org.photonvision.vision.pipe.CVPipe;
|
import org.photonvision.vision.pipe.CVPipe;
|
||||||
import org.photonvision.vision.target.TargetModel;
|
import org.photonvision.vision.target.TargetModel;
|
||||||
@@ -35,6 +37,8 @@ import org.photonvision.vision.target.TrackedTarget;
|
|||||||
public class SolvePNPPipe
|
public class SolvePNPPipe
|
||||||
extends CVPipe<List<TrackedTarget>, List<TrackedTarget>, SolvePNPPipe.SolvePNPPipeParams> {
|
extends CVPipe<List<TrackedTarget>, List<TrackedTarget>, SolvePNPPipe.SolvePNPPipeParams> {
|
||||||
|
|
||||||
|
private static final Logger logger = new Logger(SolvePNPPipe.class, LogGroup.VisionModule);
|
||||||
|
|
||||||
private final MatOfPoint2f imagePoints = new MatOfPoint2f();
|
private final MatOfPoint2f imagePoints = new MatOfPoint2f();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -68,7 +72,7 @@ public class SolvePNPPipe
|
|||||||
rVec,
|
rVec,
|
||||||
tVec);
|
tVec);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
logger.error("Exception when attempting solvePnP!", e);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -197,8 +197,7 @@ public class VisionModule {
|
|||||||
try {
|
try {
|
||||||
method.invoke(visionSource.getSettables(), newPropValue);
|
method.invoke(visionSource.getSettables(), newPropValue);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("Failed to invoke camera settable method: " + method.getName());
|
logger.error("Failed to invoke camera settable method: " + method.getName(), e);
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -249,11 +248,10 @@ public class VisionModule {
|
|||||||
+ " with value "
|
+ " with value "
|
||||||
+ newPropValue
|
+ newPropValue
|
||||||
+ " on "
|
+ " on "
|
||||||
+ currentSettings);
|
+ currentSettings,
|
||||||
e.printStackTrace();
|
e);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("Unknown exception when setting PSC prop!");
|
logger.error("Unknown exception when setting PSC prop!", e);
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
saveModule();
|
saveModule();
|
||||||
|
|||||||
Reference in New Issue
Block a user