Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream' into 2d-use-calibration
Browse files Browse the repository at this point in the history
  • Loading branch information
mcm001 committed Oct 15, 2023
2 parents 56aeae1 + 760de0f commit 3c2f942
Show file tree
Hide file tree
Showing 131 changed files with 384 additions and 417 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,14 @@ jobs:
run: |
chmod +x gradlew
./gradlew copyPhotonlib -x check
./gradlew buildAllExamples -x check --max-workers 2
./gradlew build -x check --max-workers 2
- name: Build C++ examples
working-directory: photonlib-cpp-examples
run: |
chmod +x gradlew
./gradlew copyPhotonlib -x check
./gradlew buildAllExamples -x check --max-workers 2
./gradlew build -x check --max-workers 2
photon-build-all:
# The type of runner that the job will run on.
runs-on: ubuntu-22.04
Expand Down Expand Up @@ -225,6 +225,7 @@ jobs:
include:
- os: windows-2022
artifact-name: Win64
architecture: x64
# Mac builds are broken due to opencv class loading issues -- disable for now
# - os: macos-11
# artifact-name: macOS
Expand Down Expand Up @@ -255,7 +256,7 @@ jobs:
fail-fast: false
matrix:
include:
- container: wpilib/roborio-cross-ubuntu:2023-22.04
- container: wpilib/roborio-cross-ubuntu:2024-22.04
artifact-name: Athena
- container: wpilib/raspbian-cross-ubuntu:bullseye-22.04
artifact-name: Raspbian
Expand Down
18 changes: 12 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ plugins {
id "com.diffplug.spotless" version "6.19.0"
id "com.github.johnrengelman.shadow" version "7.1.2"
id "com.github.node-gradle.node" version "3.1.1" apply false
id "edu.wpi.first.GradleJni" version "1.0.0"
id "edu.wpi.first.GradleVsCode" version "1.1.0"
id "edu.wpi.first.NativeUtils" version "2023.11.1" apply false
id "edu.wpi.first.GradleJni" version "1.1.0"
id "edu.wpi.first.GradleVsCode" version "1.3.0"
id "edu.wpi.first.NativeUtils" version "2024.2.0" apply false
id "edu.wpi.first.wpilib.repositories.WPILibRepositoriesPlugin" version "2020.2"
id "org.hidetake.ssh" version "2.10.1"
id 'edu.wpi.first.WpilibTools' version '1.0.0'
id 'edu.wpi.first.WpilibTools' version '1.1.0'
}

import org.gradle.api.internal.artifacts.dependencies.DefaultExternalModuleDependency;
Expand All @@ -26,10 +26,12 @@ allprojects {
apply from: "versioningHelper.gradle"

ext {
wpilibVersion = "2023.4.2"
opencvVersion = "4.6.0-4"
wpilibVersion = "2024.1.1-beta-1"
openCVversion = "4.8.0-1"
joglVersion = "2.4.0-rc-20200307"
javalinVersion = "5.6.2"
frcYear = "2024"

pubVersion = versionString
isDev = pubVersion.startsWith("dev")

Expand Down Expand Up @@ -61,3 +63,7 @@ spotless {
targetExclude("photon-lib/src/main/java/org/photonvision/PhotonVersion.java")
}
}

wrapper {
gradleVersion '8.3'
}
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
distributionUrl=https\://services\.gradle\.org/distributions/gradle-8\.3-bin\.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
3 changes: 2 additions & 1 deletion gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ do
esac
done

APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit

APP_NAME="Gradle"
APP_BASE_NAME=${0##*/}
Expand Down
2 changes: 1 addition & 1 deletion photon-core/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'edu.wpi.first.WpilibTools' version '1.0.0'
id 'edu.wpi.first.WpilibTools' version '1.1.0'
}

import java.nio.file.Path
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAccessor;
import java.util.*;
import java.util.Date;
import java.util.List;
import org.photonvision.common.logging.LogGroup;
import org.photonvision.common.logging.Logger;
import org.photonvision.common.util.file.FileUtils;
Expand All @@ -47,13 +48,13 @@ public class ConfigManager {

private final ConfigProvider m_provider;

private Thread settingsSaveThread;
private final Thread settingsSaveThread;
private long saveRequestTimestamp = -1;

enum ConfigSaveStrategy {
SQL,
LEGACY,
ATOMIC_ZIP;
ATOMIC_ZIP
}

// This logic decides which kind of ConfigManager we load as the default. If we want
Expand Down Expand Up @@ -115,9 +116,8 @@ private void translateLegacyIfPresent(Path folderPath) {
e1.printStackTrace();
}

// So we can't save the old config, and we couldn't copy the folder
// But we've loaded the config. So just try to delete the directory so we don't try to load
// form it next time. That does mean we have no backup recourse, tho
// Delete the directory because we were successfully able to load the config but were unable
// to save or copy the folder.
if (maybeCams.exists()) FileUtils.deleteDirectory(maybeCams.toPath());
}

Expand Down Expand Up @@ -225,7 +225,7 @@ public String taToLogFname(TemporalAccessor date) {
}

public Date logFnameToDate(String fname) throws ParseException {
// Strip away known unneded portions of the log file name
// Strip away known unneeded portions of the log file name
fname = fname.replace(LOG_PREFIX, "").replace(LOG_EXT, "");
DateFormat format = new SimpleDateFormat(LOG_DATE_TIME_FORMAT);
return format.parse(fname);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class LegacyConfigProvider extends ConfigProvider {
final File configDirectoryFile;

private long saveRequestTimestamp = -1;
private Thread settingsSaveThread;
private final Thread settingsSaveThread;

public static void saveUploadedSettingsZip(File uploadPath) {
var folderPath = Path.of(System.getProperty("java.io.tmpdir"), "photonvision").toFile();
Expand All @@ -67,7 +67,6 @@ public static void saveUploadedSettingsZip(File uploadPath) {
logger.info("Copied settings successfully!");
} catch (IOException e) {
logger.error("Exception copying uploaded settings!", e);
return;
}
}

Expand Down Expand Up @@ -371,7 +370,7 @@ public String taToLogFname(TemporalAccessor date) {
}

public Date logFnameToDate(String fname) throws ParseException {
// Strip away known unneded portions of the log file name
// Strip away known unneeded portions of the log file name
fname = fname.replace(LOG_PREFIX, "").replace(LOG_EXT, "");
DateFormat format = new SimpleDateFormat(LOG_DATE_TIME_FORMAT);
return format.parse(fname);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import org.photonvision.common.util.file.JacksonUtils;

public class NetworkConfig {
// Can be a integer team number, or a IP address
// Can be an integer team number, or an IP address
public String ntServerAddress = "0";
public NetworkMode connectionType = NetworkMode.DHCP;
public String staticIp = "";
Expand Down Expand Up @@ -58,7 +58,7 @@ public NetworkConfig() {
.orElse("Wired connection 1");
}

// We can (usually) manage networking on Linux devices, and if we can we should try to. Command
// We can (usually) manage networking on Linux devices, and if we can, we should try to. Command
// line inhibitions happen at a level above this class
setShouldManage(deviceCanManageNetwork());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@

// TODO rename this class
public class PhotonConfiguration {
private HardwareConfig hardwareConfig;
private HardwareSettings hardwareSettings;
private final HardwareConfig hardwareConfig;
private final HardwareSettings hardwareSettings;
private NetworkConfig networkConfig;
private HashMap<String, CameraConfiguration> cameraConfigurations;
private final HashMap<String, CameraConfiguration> cameraConfigurations;

public PhotonConfiguration(
HardwareConfig hardwareConfig,
Expand Down Expand Up @@ -113,7 +113,7 @@ public Map<String, Object> toHashMap() {

var lightingConfig = new UILightingConfig();
lightingConfig.brightness = hardwareSettings.ledBrightnessPercentage;
lightingConfig.supported = (hardwareConfig.ledPins.size() != 0);
lightingConfig.supported = !hardwareConfig.ledPins.isEmpty();
settingsSubmap.put("lighting", SerializationUtils.objectToHashMap(lightingConfig));

var generalSubmap = new HashMap<String, Object>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,7 @@
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -255,8 +251,7 @@ private String getOneConfigFile(Connection conn, String filename) {
var result = query.executeQuery();

while (result.next()) {
var contents = result.getString("contents");
return contents;
return result.getString("contents");
}
} catch (SQLException e) {
logger.error("SQL Err getting file " + filename, e);
Expand Down Expand Up @@ -286,7 +281,7 @@ private void saveCameras(Connection conn) {
statement.setString(2, JacksonUtils.serializeToString(config));
statement.setString(3, JacksonUtils.serializeToString(config.driveModeSettings));

// Serializing a list of abstract classes sucks. Instead, make it into a array
// Serializing a list of abstract classes sucks. Instead, make it into an array
// of strings, which we can later unpack back into individual settings
List<String> settings =
config.pipelineSettings.stream()
Expand Down Expand Up @@ -424,7 +419,7 @@ public boolean saveUploadedNetworkConfig(Path uploadPath) {
private HashMap<String, CameraConfiguration> loadCameraConfigs(Connection conn) {
HashMap<String, CameraConfiguration> loadedConfigurations = new HashMap<>();

// Querry every single row of the cameras db
// Query every single row of the cameras db
PreparedStatement query = null;
try {
query =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import java.util.Objects;
import org.photonvision.common.dataflow.events.DataChangeEvent;

@SuppressWarnings("rawtypes")
public abstract class DataChangeSubscriber {
public final List<DataChangeSource> wantedSources;
public final List<DataChangeDestination> wantedDestinations;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class NTDataPublisher implements CVPipelineResultConsumer {

private final NetworkTable rootTable = NetworkTablesManager.getInstance().kRootTable;

private NTTopicSet ts = new NTTopicSet();
private final NTTopicSet ts = new NTTopicSet();

NTDataChangeListener pipelineIndexListener;
private final Supplier<Integer> pipelineIndexSupplier;
Expand Down Expand Up @@ -181,15 +181,12 @@ public void accept(CVPipelineResult result) {
}

// Something in the result can sometimes be null -- so check probably too many things
if (result != null
&& result.inputAndOutputFrame != null
if (result.inputAndOutputFrame != null
&& result.inputAndOutputFrame.frameStaticProperties != null
&& result.inputAndOutputFrame.frameStaticProperties.cameraCalibration != null) {
var fsp = result.inputAndOutputFrame.frameStaticProperties;
if (fsp.cameraCalibration != null) {
ts.cameraIntrinsicsPublisher.accept(fsp.cameraCalibration.getIntrinsicsArr());
ts.cameraDistortionPublisher.accept(fsp.cameraCalibration.getExtrinsicsArr());
}
ts.cameraIntrinsicsPublisher.accept(fsp.cameraCalibration.getIntrinsicsArr());
ts.cameraDistortionPublisher.accept(fsp.cameraCalibration.getExtrinsicsArr());
} else {
ts.cameraIntrinsicsPublisher.accept(new double[] {});
ts.cameraDistortionPublisher.accept(new double[] {});
Expand All @@ -215,8 +212,8 @@ public static List<PhotonTrackedTarget> simpleFromTrackedTargets(List<TrackedTar
}
{
var points = t.getTargetCorners();
for (int i = 0; i < points.size(); i++) {
detectedCorners.add(new TargetCorner(points.get(i).x, points.get(i).y));
for (Point point : points) {
detectedCorners.add(new TargetCorner(point.x, point.y));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ private void setClientMode(String ntServerAddress) {
ntInstance.stopServer();
ntInstance.startClient4("photonvision");
try {
Integer t = Integer.parseInt(ntServerAddress);
int t = Integer.parseInt(ntServerAddress);
if (!isRetryingConnection) logger.info("Starting NT Client, server team is " + t);
ntInstance.setServerTeam(t);
} catch (NumberFormatException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

package org.photonvision.common.hardware.GPIO.pi;

import static org.photonvision.common.hardware.GPIO.pi.PigpioException.*;

import org.photonvision.common.hardware.GPIO.GPIOBase;
import org.photonvision.common.logging.LogGroup;
import org.photonvision.common.logging.Logger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package org.photonvision.common.hardware.GPIO.pi;

import static org.photonvision.common.hardware.GPIO.pi.PigpioException.*;
import static org.photonvision.common.hardware.GPIO.pi.PigpioException.PI_NO_WAVEFORM_ID;

import java.io.IOException;
import java.nio.ByteBuffer;
Expand Down Expand Up @@ -149,7 +148,7 @@ private int waveAddGeneric(ArrayList<PigpioPulse> pulses) throws PigpioException
// ## extension ##
// III on/off/delay * pulses

if (pulses == null || pulses.size() == 0) return 0;
if (pulses == null || pulses.isEmpty()) return 0;

try {
ByteBuffer bb = ByteBuffer.allocate(pulses.size() * 12);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ public class HardwareManager {
private final StatusLED statusLED;

@SuppressWarnings("FieldCanBeLocal")
private IntegerSubscriber ledModeRequest;
private final IntegerSubscriber ledModeRequest;

private IntegerPublisher ledModeState;
private final IntegerPublisher ledModeState;

@SuppressWarnings({"FieldCanBeLocal", "unused"})
private final NTDataChangeListener ledModeListener;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public enum PiVersion {
private static final ShellExec shell = new ShellExec(true, false);
private static final PiVersion currentPiVersion = calcPiVersion();

private PiVersion(String s) {
PiVersion(String s) {
this.identifier = s.toLowerCase();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

package org.photonvision.common.hardware;

import com.jogamp.common.os.Platform.OSType;
import edu.wpi.first.util.RuntimeDetector;
import java.io.BufferedReader;
import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class VisionLED {

private int mappedBrightnessPercentage;

private Consumer<Integer> modeConsumer;
private final Consumer<Integer> modeConsumer;

public VisionLED(
List<Integer> ledPins,
Expand Down Expand Up @@ -179,11 +179,7 @@ private void setInternal(VisionLEDMode newLedMode, boolean fromNT) {
}
currentLedMode = newLedMode;
logger.info(
"Changing LED mode from \""
+ lastLedMode.toString()
+ "\" to \""
+ newLedMode.toString()
+ "\"");
"Changing LED mode from \"" + lastLedMode.toString() + "\" to \"" + newLedMode + "\"");
} else {
if (currentLedMode == VisionLEDMode.kDefault) {
switch (newLedMode) {
Expand Down
Loading

0 comments on commit 3c2f942

Please sign in to comment.