Skip to content

Commit

Permalink
Fix most of the merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
mcm001 committed Jul 28, 2023
1 parent 2ed6ca6 commit f3193f4
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 132 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
package org.photonvision.common.configuration;

import com.fasterxml.jackson.core.JsonProcessingException;
import edu.wpi.first.apriltag.AprilTagFieldLayout;
import edu.wpi.first.apriltag.AprilTagFields;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
Expand Down Expand Up @@ -45,12 +47,14 @@ class LegacyConfigProvider extends ConfigProvider {
public static final String HW_CFG_FNAME = "hardwareConfig.json";
public static final String HW_SET_FNAME = "hardwareSettings.json";
public static final String NET_SET_FNAME = "networkSettings.json";
public static final String ATFL_SET_FNAME = "apriltagFieldLayout.json";

private PhotonConfiguration config;
private final File hardwareConfigFile;
private final File hardwareSettingsFile;
private final File networkConfigFile;
private final File camerasFolder;
private final File apriltagFieldLayoutFile;

final File configDirectoryFile;

Expand Down Expand Up @@ -87,6 +91,8 @@ protected LegacyConfigProvider(Path configDirectoryFile) {
new File(Path.of(configDirectoryFile.toString(), HW_SET_FNAME).toUri());
this.networkConfigFile =
new File(Path.of(configDirectoryFile.toString(), NET_SET_FNAME).toUri());
this.apriltagFieldLayoutFile =
new File(Path.of(configDirectoryFile.toString(), ATFL_SET_FNAME).toUri());
this.camerasFolder = new File(Path.of(configDirectoryFile.toString(), "cameras").toUri());

settingsSaveThread = new Thread(this::saveAndWriteTask);
Expand Down Expand Up @@ -117,6 +123,7 @@ public void load() {
HardwareConfig hardwareConfig;
HardwareSettings hardwareSettings;
NetworkConfig networkConfig;
AprilTagFieldLayout atfl = null;

if (hardwareConfigFile.exists()) {
try {
Expand Down Expand Up @@ -176,11 +183,40 @@ public void load() {
}
}

if (apriltagFieldLayoutFile.exists()) {
try {
atfl =
JacksonUtils.deserialize(apriltagFieldLayoutFile.toPath(), AprilTagFieldLayout.class);
if (atfl == null) {
logger.error("Could not deserialize apriltag field layout!");
}
} catch (IOException e) {
logger.error("Could not deserialize apriltag field layout!");
atfl = null; // not required, nice to be explicit
}
logger.info("Apriltag layout file not saved!");
atfl = null; // not required, nice to be explicit
}
if (atfl == null) {
logger.info("Loading default apriltags for 2023 field...");
try {
atfl = AprilTagFields.k2023ChargedUp.loadAprilTagLayoutField();
} catch (IOException e) {
logger.error("Error loading WPILib field", e);
atfl = null;
}
if (atfl == null) {
// what do we even do here lmao -- wpilib should always work
logger.error("Field layout is *still* null??????");
atfl = new AprilTagFieldLayout(List.of(), 1, 1);
}
}

HashMap<String, CameraConfiguration> cameraConfigurations = loadCameraConfigs();

this.config =
new PhotonConfiguration(
hardwareConfig, hardwareSettings, networkConfig, cameraConfigurations);
hardwareConfig, hardwareSettings, networkConfig, atfl, cameraConfigurations);
}

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

package org.photonvision.common.configuration;

import edu.wpi.first.apriltag.AprilTagFieldLayout;
import edu.wpi.first.apriltag.AprilTagFields;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
Expand Down Expand Up @@ -57,6 +59,7 @@ static class TableKeys {
static final String NETWORK_CONFIG = "networkConfig";
static final String HARDWARE_CONFIG = "hardwareConfig";
static final String HARDWARE_SETTINGS = "hardwareSettings";
static final String ATFL_CONFIG_FILE = "apriltagFieldLayout";
}

private static final String dbName = "photon.sqlite";
Expand Down Expand Up @@ -206,6 +209,7 @@ public void load() {
HardwareConfig hardwareConfig;
HardwareSettings hardwareSettings;
NetworkConfig networkConfig;
AprilTagFieldLayout atfl;

try {
hardwareConfig =
Expand Down Expand Up @@ -234,6 +238,25 @@ public void load() {
networkConfig = new NetworkConfig();
}

try {
atfl =
JacksonUtils.deserialize(
getOneConfigFile(conn, TableKeys.ATFL_CONFIG_FILE), AprilTagFieldLayout.class);
} catch (IOException e) {
logger.error("Could not deserialize network config! Loading defaults");
try {
atfl = AprilTagFields.k2023ChargedUp.loadAprilTagLayoutField();
} catch (IOException e2) {
logger.error("Error loading WPILib field", e);
atfl = null;
}
if (atfl == null) {
// what do we even do here lmao -- wpilib should always work
logger.error("Field layout is *still* null??????");
atfl = new AprilTagFieldLayout(List.of(), 1, 1);
}
}

var cams = loadCameraConfigs(conn);

try {
Expand All @@ -242,7 +265,8 @@ public void load() {
logger.error("SQL Err closing connection while loading: ", e);
}

this.config = new PhotonConfiguration(hardwareConfig, hardwareSettings, networkConfig, cams);
this.config =
new PhotonConfiguration(hardwareConfig, hardwareSettings, networkConfig, atfl, cams);
}
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@
import edu.wpi.first.math.numbers.*;
import java.util.ArrayList;
import java.util.List;
import org.photonvision.targeting.PNPResults;
import java.util.Objects;
import java.util.stream.Collectors;
import org.photonvision.targeting.PNPResults;
import org.photonvision.targeting.PhotonTrackedTarget;
import org.photonvision.targeting.TargetCorner;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
import org.photonvision.common.networktables.NTTopicSet;
import org.photonvision.estimation.CameraTargetRelation;
import org.photonvision.estimation.OpenCVHelp;
import org.photonvision.estimation.PNPResults;
import org.photonvision.targeting.PNPResults;
import org.photonvision.targeting.PhotonPipelineResult;
import org.photonvision.targeting.PhotonTrackedTarget;
import org.photonvision.targeting.TargetCorner;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,25 @@
/*
* MIT License
* Copyright (C) Photon Vision.
*
* Copyright (c) PhotonVision
* 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.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* 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.
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
* 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.estimation;
package org.photonvision.targeting;

import edu.wpi.first.math.geometry.Transform3d;
import org.photonvision.common.dataflow.structures.Packet;
import org.photonvision.utils.PacketUtils;

/**
* The best estimated transformation from solvePnP, and possibly an alternate transformation
Expand Down Expand Up @@ -90,4 +85,30 @@ public PNPResults(
this.bestReprojErr = bestReprojErr;
this.altReprojErr = altReprojErr;
}

public static final int PACK_SIZE_BYTES = 1 + (Double.BYTES * 7 * 2) + (Double.BYTES * 3);

public static PNPResults createFromPacket(Packet packet) {
var present = packet.decodeBoolean();
var best = PacketUtils.decodeTransform(packet);
var alt = PacketUtils.decodeTransform(packet);
var bestEr = packet.decodeDouble();
var altEr = packet.decodeDouble();
var ambiguity = packet.decodeDouble();
if (present) {
return new PNPResults(best, alt, ambiguity, bestEr, altEr);
} else {
return new PNPResults();
}
}

public Packet populatePacket(Packet packet) {
packet.encode(isPresent);
PacketUtils.encodeTransform(packet, best);
PacketUtils.encodeTransform(packet, alt);
packet.encode(bestReprojErr);
packet.encode(altReprojErr);
packet.encode(ambiguity);
return packet;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -209,27 +209,20 @@ public int hashCode() {

@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
if (this == obj) return true;
if (obj == null) return false;
if (getClass() != obj.getClass()) return false;
PhotonPipelineResult other = (PhotonPipelineResult) obj;
if (targets == null) {
if (other.targets != null)
return false;
} else if (!targets.equals(other.targets))
return false;
if (other.targets != null) return false;
} else if (!targets.equals(other.targets)) return false;
if (Double.doubleToLongBits(latencyMillis) != Double.doubleToLongBits(other.latencyMillis))
return false;
if (Double.doubleToLongBits(timestampSeconds) != Double.doubleToLongBits(other.timestampSeconds))
return false;
if (Double.doubleToLongBits(timestampSeconds)
!= Double.doubleToLongBits(other.timestampSeconds)) return false;
if (multiTagResult == null) {
if (other.multiTagResult != null)
return false;
} else if (!multiTagResult.equals(other.multiTagResult))
return false;
if (other.multiTagResult != null) return false;
} else if (!multiTagResult.equals(other.multiTagResult)) return false;
return true;
}
}

0 comments on commit f3193f4

Please sign in to comment.