Upgrade to Gradle 7.2 and WPILib 2022 (#316)

This commit is contained in:
Tyler Veness
2021-11-21 17:22:56 -08:00
committed by GitHub
parent ffe34f00fe
commit 5ca39e7f84
316 changed files with 671 additions and 1019 deletions

View File

@@ -48,7 +48,7 @@ PhotonPipelineResult PhotonCamera::GetLatestResult() const {
std::shared_ptr<nt::Value> ntvalue = rawBytesEntry.GetValue();
if (!ntvalue) return result;
std::string value = ntvalue->GetRaw();
std::string value{ntvalue->GetRaw()};
std::vector<char> bytes{value.begin(), value.end()};
photonlib::Packet packet{bytes};

View File

@@ -19,7 +19,7 @@
namespace photonlib {
PhotonPipelineResult::PhotonPipelineResult(
units::second_t latency, wpi::ArrayRef<PhotonTrackedTarget> targets)
units::second_t latency, wpi::span<const PhotonTrackedTarget> targets)
: latency(latency),
targets(targets.data(), targets.data() + targets.size()) {}
@@ -33,7 +33,7 @@ bool PhotonPipelineResult::operator!=(const PhotonPipelineResult& other) const {
Packet& operator<<(Packet& packet, const PhotonPipelineResult& result) {
// Encode latency and number of targets.
packet << result.latency.to<double>() * 1000
packet << result.latency.value() * 1000
<< static_cast<int8_t>(result.targets.size());
// Encode the information of each target.

View File

@@ -39,9 +39,9 @@ bool PhotonTrackedTarget::operator!=(const PhotonTrackedTarget& other) const {
Packet& operator<<(Packet& packet, const PhotonTrackedTarget& target) {
return packet << target.yaw << target.pitch << target.area << target.skew
<< target.cameraToTarget.Translation().X().to<double>()
<< target.cameraToTarget.Translation().Y().to<double>()
<< target.cameraToTarget.Rotation().Degrees().to<double>();
<< target.cameraToTarget.Translation().X().value()
<< target.cameraToTarget.Translation().Y().value()
<< target.cameraToTarget.Rotation().Degrees().value();
}
Packet& operator>>(Packet& packet, PhotonTrackedTarget& target) {

View File

@@ -26,7 +26,7 @@ SimPhotonCamera::SimPhotonCamera(const std::string& cameraName)
: PhotonCamera(cameraName) {}
void SimPhotonCamera::SubmitProcessedFrame(
units::second_t latency, wpi::ArrayRef<PhotonTrackedTarget> tgtList) {
units::second_t latency, wpi::span<const PhotonTrackedTarget> tgtList) {
if (!GetDriverMode()) {
// Clear the current packet.
simPacket.Clear();
@@ -34,8 +34,8 @@ void SimPhotonCamera::SubmitProcessedFrame(
// Create the new result and pump it into the packet
simPacket << PhotonPipelineResult(latency, tgtList);
rawBytesEntry.SetRaw(
wpi::StringRef(simPacket.GetData().data(), simPacket.GetData().size()));
rawBytesEntry.SetRaw(std::string_view{simPacket.GetData().data(),
simPacket.GetData().size()});
}
}

View File

@@ -21,6 +21,7 @@
#include <units/angle.h>
#include <units/length.h>
#include <wpi/span.h>
namespace photonlib {
@@ -73,36 +74,34 @@ void SimVisionSystem::ProcessFrame(frc::Pose2d robotPose) {
units::meter_t distHypot =
units::math::hypot(distAlongGround, distVertical);
double area = tgt.tgtArea.to<double>() / GetM2PerPx(distAlongGround);
double area = tgt.tgtArea.value() / GetM2PerPx(distAlongGround);
// 2D yaw mode considers the target as a point, and should ignore target
// rotation.
// Photon reports it in the correct robot reference frame.
// IE: targets to the left of the image should report negative yaw.
units::degree_t yawAngle =
-1.0 * units::math::atan2(camToTargetTrans.Translation().Y(),
camToTargetTrans.Translation().X());
units::degree_t yawAngle = -units::math::atan2(
camToTargetTrans.Translation().Y(), camToTargetTrans.Translation().X());
units::degree_t pitchAngle =
units::math::atan2(distVertical, distAlongGround) - camPitch;
if (CamCanSeeTarget(distHypot, yawAngle, pitchAngle, area)) {
PhotonTrackedTarget newTgt =
PhotonTrackedTarget(yawAngle.to<double>(), pitchAngle.to<double>(),
area, 0.0, camToTargetTrans);
PhotonTrackedTarget newTgt = PhotonTrackedTarget(
yawAngle.value(), pitchAngle.value(), area, 0.0, camToTargetTrans);
visibleTgtList.push_back(newTgt);
}
}
units::second_t procDelay(0.0); // Future - tie this to something meaningful
cam.SubmitProcessedFrame(
procDelay, wpi::MutableArrayRef<PhotonTrackedTarget>(visibleTgtList));
cam.SubmitProcessedFrame(procDelay,
wpi::span<PhotonTrackedTarget>(visibleTgtList));
}
double SimVisionSystem::GetM2PerPx(units::meter_t dist) {
double heightMPerPx = 2 * dist.to<double>() *
units::math::tan(camVertFOV / 2) / cameraResHeight;
double widthMPerPx = 2 * dist.to<double>() *
units::math::tan(camHorizFOV / 2) / cameraResWidth;
double heightMPerPx =
2 * dist.value() * units::math::tan(camVertFOV / 2) / cameraResHeight;
double widthMPerPx =
2 * dist.value() * units::math::tan(camHorizFOV / 2) / cameraResWidth;
return widthMPerPx * heightMPerPx;
}

View File

@@ -19,10 +19,10 @@
#include <string>
#include <frc/DriverStation.h>
#include <frc/Errors.h>
#include <units/time.h>
#include <wpi/ArrayRef.h>
#include <wpi/SmallVector.h>
#include <wpi/span.h>
#include "photonlib/Packet.h"
#include "photonlib/PhotonTrackedTarget.h"
@@ -44,7 +44,7 @@ class PhotonPipelineResult {
* @param targets The list of targets identified by the pipeline.
*/
PhotonPipelineResult(units::second_t latency,
wpi::ArrayRef<PhotonTrackedTarget> targets);
wpi::span<const PhotonTrackedTarget> targets);
/**
* Returns the best target in this pipeline result. If there are no targets,
@@ -55,7 +55,8 @@ class PhotonPipelineResult {
*/
PhotonTrackedTarget GetBestTarget() const {
if (!HasTargets() && !HAS_WARNED) {
::frc::DriverStation::ReportError(
FRC_ReportError(
frc::warn::Warning, "{}",
"This PhotonPipelineResult object has no targets associated with it! "
"Please check HasTargets() before calling this method. For more "
"information, please review the PhotonLib documentation at "
@@ -81,7 +82,7 @@ class PhotonPipelineResult {
* Returns a reference to the vector of targets.
* @return A reference to the vector of targets.
*/
const wpi::ArrayRef<PhotonTrackedTarget> GetTargets() const {
const wpi::span<const PhotonTrackedTarget> GetTargets() const {
return targets;
}

View File

@@ -21,8 +21,8 @@
#include <string>
#include <units/time.h>
#include <wpi/ArrayRef.h>
#include <wpi/SmallVector.h>
#include <wpi/span.h>
#include "photonlib/Packet.h"
#include "photonlib/PhotonCamera.h"
@@ -56,7 +56,7 @@ class SimPhotonCamera : public PhotonCamera {
* @param tgtList Set of targets detected
*/
void SubmitProcessedFrame(units::second_t latency,
wpi::ArrayRef<PhotonTrackedTarget> tgtList);
wpi::span<const PhotonTrackedTarget> tgtList);
private:
mutable Packet simPacket;

View File

@@ -25,7 +25,6 @@
#include <units/area.h>
#include <units/length.h>
#include <units/time.h>
#include <wpi/ArrayRef.h>
#include <wpi/SmallVector.h>
#include "photonlib/SimPhotonCamera.h"