mirror of
https://github.com/PhotonVision/photonvision
synced 2026-06-21 01:01:41 +00:00
Hardware Management, Metrics, PWM/GPIO support. (#12)
* [Server] Hardware Management * [Server] Hardware Management * [Server] Hardware Management * [Server] Hardware Management * [Server] Hardware Management * [Server] Hardware Management * Added metricsPublisher * [Server] Hardware Management * [Server] Hardware Management * Fill in HardwareConfig, allow JSON Comments * Use hardware config * [Hardware Management] Use Hardware Config * [Hardware Management] Use softPWM for dimming * [Hardware] Added HardwareConfig Test * [Hardware] Started HardwareManager * Start metrics thread in hardwareManager * [Hardware] Added Hardware Manager Test * [Hardware] Spotless * [Hardware] Added logging, cleaned up HardwareConfig * [Hardware] Added logging to PWM class * [Hardware] Rebase off master, fix merge conflicts * [Hardware] Ignore metrics commands if on pi * [Hardware] Remove GPIO provision after shutdown * [Hardware] Switch over to diozero * [Hardware] Use broadcom pins * [Hardware] Fix PWM port * [Hardware] Use jpi instead of pigpio * [Hardware] Use dizero-core * [Hardware] No need to close LED * [Hardware] Switch to jpigpio * [Hardware] Initalize JPiGPIO in unit tests * [Hardware] Use dutyCycle for LED dimming * [Hardware] Add blink test to HardwareManager * [Hardware] Fix PWM port * [Hardware] Fix HardwareManagerTest * [Hardware] Fix HardwareManagerTest * [Hardware] Use waves for LED blinking * [Hardware] Make blinking part of PWM * [Hardware] Add API methods to hardware Manager * [Hardware] Only start pigpio if on pi * [Hardware] Merge PWM classes into GPIO * [Hardware] Add Hardware stuff to VisionModules * [Hardware] Remove random semicolon Co-authored-by: Banks Troutman <btrout.dhrs@gmail.com>
This commit is contained in:
@@ -1,107 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2020 Photon Vision.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.photonvision.common.util;
|
||||
|
||||
import edu.wpi.first.wpiutil.RuntimeDetector;
|
||||
import java.io.IOException;
|
||||
import org.apache.commons.lang3.SystemUtils;
|
||||
import org.photonvision.common.logging.LogGroup;
|
||||
import org.photonvision.common.logging.Logger;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public enum Platform {
|
||||
WINDOWS_32("Windows x32"),
|
||||
WINDOWS_64("Windows x64"),
|
||||
LINUX_32("Linux x32"),
|
||||
LINUX_64("Linux x64"),
|
||||
LINUX_RASPBIAN("Linux Raspbian"), // TODO: check that RaspiOS reports the same way
|
||||
LINUX_AARCH64BIONIC("Linux Aarch64 Bionic"),
|
||||
UNSUPPORTED(
|
||||
"Unsupported Platform - OS: "
|
||||
+ SystemUtils.OS_NAME
|
||||
+ ", Architecture: "
|
||||
+ SystemUtils.OS_ARCH);
|
||||
|
||||
public final String value;
|
||||
public final boolean isRoot = checkForRoot();
|
||||
|
||||
Platform(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
private static final Logger logger = new Logger(Platform.class, LogGroup.General);
|
||||
|
||||
public static final Platform CurrentPlatform = getCurrentPlatform();
|
||||
|
||||
public static boolean isWindows() {
|
||||
return CurrentPlatform == WINDOWS_64 || CurrentPlatform == WINDOWS_32;
|
||||
}
|
||||
|
||||
public static boolean isLinux() {
|
||||
return CurrentPlatform != UNSUPPORTED && !isWindows();
|
||||
}
|
||||
|
||||
public static boolean isRaspberryPi() {
|
||||
return CurrentPlatform.equals(LINUX_RASPBIAN);
|
||||
}
|
||||
|
||||
private static ShellExec shell = new ShellExec(true, false);
|
||||
|
||||
@SuppressWarnings("StatementWithEmptyBody")
|
||||
private boolean checkForRoot() {
|
||||
if (isLinux()) {
|
||||
try {
|
||||
shell.execute("id", null, true, "-u");
|
||||
} catch (IOException e) {
|
||||
logger.error("Failed to perform root check!", e);
|
||||
}
|
||||
|
||||
while (!shell.isOutputCompleted()) {
|
||||
// TODO: add timeout
|
||||
}
|
||||
|
||||
if (shell.getExitCode() == 0) {
|
||||
return shell.getOutput().split("\n")[0].equals("0");
|
||||
}
|
||||
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static Platform getCurrentPlatform() {
|
||||
if (RuntimeDetector.isWindows()) {
|
||||
if (RuntimeDetector.is32BitIntel()) return WINDOWS_32;
|
||||
if (RuntimeDetector.is64BitIntel()) return WINDOWS_64;
|
||||
}
|
||||
|
||||
if (RuntimeDetector.isLinux()) {
|
||||
if (RuntimeDetector.is32BitIntel()) return LINUX_32;
|
||||
if (RuntimeDetector.is64BitIntel()) return LINUX_64;
|
||||
if (RuntimeDetector.isRaspbian()) return LINUX_RASPBIAN;
|
||||
if (RuntimeDetector.isAarch64Bionic()) return LINUX_AARCH64BIONIC;
|
||||
}
|
||||
|
||||
return UNSUPPORTED;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return this.value;
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,7 @@ package org.photonvision.common.util;
|
||||
|
||||
import edu.wpi.cscore.CameraServerCvJNI;
|
||||
import java.awt.*;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import org.opencv.core.Mat;
|
||||
@@ -165,6 +166,10 @@ public class TestUtils {
|
||||
return getResourcesFolderPath().resolve("calibrationBoardImages");
|
||||
}
|
||||
|
||||
public static File getHardwareConfigJson() {
|
||||
return getResourcesFolderPath().resolve("hardware").resolve("HardwareConfig.json").toFile();
|
||||
}
|
||||
|
||||
public static void loadLibraries() {
|
||||
try {
|
||||
CameraServerCvJNI.forceLoad();
|
||||
|
||||
@@ -26,9 +26,9 @@ import java.nio.file.attribute.PosixFilePermission;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import org.photonvision.common.hardware.Platform;
|
||||
import org.photonvision.common.logging.LogGroup;
|
||||
import org.photonvision.common.logging.Logger;
|
||||
import org.photonvision.common.util.Platform;
|
||||
|
||||
public class FileUtils {
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
|
||||
package org.photonvision.common.util.file;
|
||||
|
||||
import com.fasterxml.jackson.core.json.JsonReadFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
|
||||
import com.fasterxml.jackson.databind.json.JsonMapper;
|
||||
@@ -51,6 +52,7 @@ public class JacksonUtils {
|
||||
BasicPolymorphicTypeValidator.builder().allowIfBaseType(ref).build();
|
||||
ObjectMapper objectMapper =
|
||||
JsonMapper.builder()
|
||||
.configure(JsonReadFeature.ALLOW_JAVA_COMMENTS, true)
|
||||
.activateDefaultTyping(ptv, ObjectMapper.DefaultTyping.JAVA_LANG_OBJECT)
|
||||
.build();
|
||||
File jsonFile = new File(path.toString());
|
||||
|
||||
Reference in New Issue
Block a user