Skip to content

Commit

Permalink
Fix everything
Browse files Browse the repository at this point in the history
  • Loading branch information
srimanachanta committed Dec 27, 2023
1 parent 112f3ca commit 7034bb9
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@

namespace photon {
PhotonPipelineResult::PhotonPipelineResult(
units::second_t latency, std::span<const PhotonTrackedTarget> targets)
units::millisecond_t latency, std::span<const PhotonTrackedTarget> targets)
: latency(latency),
targets(targets.data(), targets.data() + targets.size()) {}

PhotonPipelineResult::PhotonPipelineResult(
units::second_t latency, std::span<const PhotonTrackedTarget> targets,
units::millisecond_t latency, std::span<const PhotonTrackedTarget> targets,
MultiTargetPNPResult multitagResult)
: latency(latency),
targets(targets.data(), targets.data() + targets.size()),
Expand All @@ -37,7 +37,7 @@ bool PhotonPipelineResult::operator==(const PhotonPipelineResult& other) const {

Packet& operator<<(Packet& packet, const PhotonPipelineResult& result) {
// Encode latency and number of targets.
packet << result.latency.value() * 1000 << result.multitagResult
packet << result.latency.value() << result.multitagResult
<< static_cast<int8_t>(result.targets.size());

// Encode the information of each target.
Expand All @@ -52,7 +52,7 @@ Packet& operator>>(Packet& packet, PhotonPipelineResult& result) {
double latencyMillis = 0;
int8_t targetCount = 0;
packet >> latencyMillis >> result.multitagResult >> targetCount;
result.latency = units::second_t(latencyMillis / 1000.0);
result.latency = units::millisecond_t(latencyMillis);

result.targets.clear();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "photon/targeting/proto/MultiTargetPNPResultProto.h"

#include "photon.pb.h"
#include "photon/targeting/proto/PNPResultProto.h"

google::protobuf::Message* wpi::Protobuf<photon::MultiTargetPNPResult>::New(
google::protobuf::Arena* arena) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@ photon::PNPResult wpi::Protobuf<photon::PNPResult>::Unpack(
return photon::PNPResult();
}

return photon::PNPResult{wpi::UnpackProtobuf<frc::Transform3d>(m->best()),
return photon::PNPResult{true,
wpi::UnpackProtobuf<frc::Transform3d>(m->best()),
m->best_reproj_err(),
wpi::UnpackProtobuf<frc::Transform3d>(m->alt()),
m->alt_reproj_err(), m->ambiguity()};
m->alt_reproj_err(),
m->ambiguity()};
}

void wpi::Protobuf<photon::PNPResult>::Pack(google::protobuf::Message* msg,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#include "photon/targeting/proto/PhotonPipelineResultProto.h"

#include "photon.pb.h"
#include "photon/targeting/proto/MultiTargetPNPResultProto.h"
#include "photon/targeting/proto/PhotonTrackedTargetProto.h"

google::protobuf::Message* wpi::Protobuf<photon::PhotonPipelineResult>::New(
google::protobuf::Arena* arena) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class PhotonPipelineResult {
* @param latency The latency in the pipeline.
* @param targets The list of targets identified by the pipeline.
*/
PhotonPipelineResult(units::second_t latency,
PhotonPipelineResult(units::millisecond_t latency,
std::span<const PhotonTrackedTarget> targets);

/**
Expand All @@ -53,7 +53,7 @@ class PhotonPipelineResult {
* @param targets The list of targets identified by the pipeline.
* @param multitagResult The multitarget result
*/
PhotonPipelineResult(units::second_t latency,
PhotonPipelineResult(units::millisecond_t latency,
std::span<const PhotonTrackedTarget> targets,
MultiTargetPNPResult multitagResult);

Expand Down Expand Up @@ -81,7 +81,7 @@ class PhotonPipelineResult {
* Returns the latency in the pipeline.
* @return The latency in the pipeline.
*/
units::second_t GetLatency() const { return latency; }
units::millisecond_t GetLatency() const { return latency; }

/**
* Returns the estimated time the frame was taken,
Expand Down Expand Up @@ -125,7 +125,7 @@ class PhotonPipelineResult {
friend Packet& operator<<(Packet& packet, const PhotonPipelineResult& result);
friend Packet& operator>>(Packet& packet, PhotonPipelineResult& result);

units::second_t latency = 0_s;
units::millisecond_t latency = 0_s;
units::second_t timestamp = -1_s;
wpi::SmallVector<PhotonTrackedTarget, 10> targets;
MultiTargetPNPResult multitagResult;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "gtest/gtest.h"
#include "photon.pb.h"
#include "photon/targeting/MultiTargetPNPResult.h"
#include "photon/targeting/proto/MultiTargetPNPResultProto.h"

TEST(MultiTargetPNPResultTest, Roundtrip) {
photon::MultiTargetPNPResult result;
Expand All @@ -33,12 +34,14 @@ TEST(MultiTargetPNPResultTest, Roundtrip) {
EXPECT_EQ(result, unpacked_data);

photon::PNPResult pnpRes{
true,
frc::Transform3d(frc::Translation3d(1_m, 2_m, 3_m),
frc::Rotation3d(1_rad, 2_rad, 3_rad)),
0.1,
frc::Transform3d(frc::Translation3d(1_m, 2_m, 3_m),
frc::Rotation3d(1_rad, 2_rad, 3_rad)),
0.1, 0};
0.1,
0};

photon::MultiTargetPNPResult result1{pnpRes, {1, 2, 3, 4}};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "gtest/gtest.h"
#include "photon.pb.h"
#include "photon/targeting/PNPResult.h"
#include "photon/targeting/proto/PNPResultProto.h"

TEST(PNPResultTest, Roundtrip) {
photon::PNPResult result;
Expand All @@ -33,12 +34,14 @@ TEST(PNPResultTest, Roundtrip) {
EXPECT_EQ(result, unpacked_data);

photon::PNPResult result1{
true,
frc::Transform3d(frc::Translation3d(1_m, 2_m, 3_m),
frc::Rotation3d(1_rad, 2_rad, 3_rad)),
0.1,
frc::Transform3d(frc::Translation3d(1_m, 2_m, 3_m),
frc::Rotation3d(1_rad, 2_rad, 3_rad)),
0.1, 0};
0.1,
0};

proto = wpi::Protobuf<photon::PNPResult>::New(&arena);
wpi::Protobuf<photon::PNPResult>::Pack(proto, result1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "gtest/gtest.h"
#include "photon.pb.h"
#include "photon/targeting/PhotonPipelineResult.h"
#include "photon/targeting/proto/PhotonPipelineResultProto.h"

TEST(PhotonPipelineResultTest, Roundtrip) {
photon::PhotonPipelineResult result{12_ms, {}};
Expand Down Expand Up @@ -72,12 +73,14 @@ TEST(PhotonPipelineResultTest, Roundtrip) {
EXPECT_EQ(result2, unpacked_data2);

photon::PNPResult pnpRes{
true,
frc::Transform3d(frc::Translation3d(1_m, 2_m, 3_m),
frc::Rotation3d(1_rad, 2_rad, 3_rad)),
0.1,
frc::Transform3d(frc::Translation3d(1_m, 2_m, 3_m),
frc::Rotation3d(1_rad, 2_rad, 3_rad)),
0.1, 0};
0.1,
0};

photon::MultiTargetPNPResult multitagRes{pnpRes, {1, 2, 3, 4}};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "gtest/gtest.h"
#include "photon.pb.h"
#include "photon/targeting/PhotonTrackedTarget.h"
#include "photon/targeting/proto/PhotonTrackedTargetProto.h"

TEST(PhotonTrackedTargetTest, Roundtrip) {
photon::PhotonTrackedTarget target{
Expand Down

0 comments on commit 7034bb9

Please sign in to comment.