2021-01-16 20:41:47 -08:00
|
|
|
/*
|
2022-01-20 19:35:28 -08:00
|
|
|
* MIT License
|
2021-01-16 20:41:47 -08:00
|
|
|
*
|
2022-01-20 19:35:28 -08:00
|
|
|
* Copyright (c) 2022 PhotonVision
|
2021-01-16 20:41:47 -08:00
|
|
|
*
|
2022-01-20 19:35:28 -08:00
|
|
|
* 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:
|
2021-01-16 20:41:47 -08:00
|
|
|
*
|
2022-01-20 19:35:28 -08:00
|
|
|
* 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.
|
2021-01-16 20:41:47 -08:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
|
|
#include <units/angle.h>
|
|
|
|
|
|
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
#include "photonlib/PhotonPipelineResult.h"
|
|
|
|
|
#include "photonlib/PhotonTrackedTarget.h"
|
|
|
|
|
|
|
|
|
|
TEST(PacketTest, PhotonTrackedTarget) {
|
|
|
|
|
photonlib::PhotonTrackedTarget target{
|
2022-01-10 20:31:36 -08:00
|
|
|
3.0,
|
|
|
|
|
4.0,
|
|
|
|
|
9.0,
|
|
|
|
|
-5.0,
|
2022-09-28 18:21:41 -07:00
|
|
|
-1,
|
|
|
|
|
frc::Transform3d(frc::Translation3d(1_m, 2_m, 3_m),
|
|
|
|
|
frc::Rotation3d(1_rad, 2_rad, 3_rad)),
|
2022-12-30 00:40:13 -06:00
|
|
|
frc::Transform3d(frc::Translation3d(1_m, 2_m, 3_m),
|
|
|
|
|
frc::Rotation3d(1_rad, 2_rad, 3_rad)),
|
|
|
|
|
-1,
|
2023-01-14 09:06:15 -06:00
|
|
|
{std::pair{1, 2}, std::pair{3, 4}, std::pair{5, 6}, std::pair{7, 8}},
|
2022-01-10 20:31:36 -08:00
|
|
|
{std::pair{1, 2}, std::pair{3, 4}, std::pair{5, 6}, std::pair{7, 8}}};
|
|
|
|
|
|
2021-01-16 20:41:47 -08:00
|
|
|
photonlib::Packet p;
|
|
|
|
|
p << target;
|
|
|
|
|
|
|
|
|
|
photonlib::PhotonTrackedTarget b;
|
|
|
|
|
p >> b;
|
|
|
|
|
|
|
|
|
|
for (auto& c : p.GetData()) {
|
|
|
|
|
std::cout << static_cast<int>(c) << ",";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
EXPECT_EQ(target, b);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(PacketTest, PhotonPipelineResult) {
|
|
|
|
|
photonlib::PhotonPipelineResult result{1_s, {}};
|
|
|
|
|
photonlib::Packet p;
|
|
|
|
|
p << result;
|
|
|
|
|
|
|
|
|
|
photonlib::PhotonPipelineResult b;
|
|
|
|
|
p >> b;
|
|
|
|
|
|
|
|
|
|
EXPECT_EQ(result, b);
|
|
|
|
|
|
|
|
|
|
wpi::SmallVector<photonlib::PhotonTrackedTarget, 2> targets{
|
|
|
|
|
photonlib::PhotonTrackedTarget{
|
2022-01-10 20:31:36 -08:00
|
|
|
3.0,
|
|
|
|
|
-4.0,
|
|
|
|
|
9.0,
|
|
|
|
|
4.0,
|
2022-09-28 18:21:41 -07:00
|
|
|
1,
|
|
|
|
|
frc::Transform3d(frc::Translation3d(1_m, 2_m, 3_m),
|
|
|
|
|
frc::Rotation3d(1_rad, 2_rad, 3_rad)),
|
2022-12-30 00:40:13 -06:00
|
|
|
frc::Transform3d(frc::Translation3d(1_m, 2_m, 3_m),
|
|
|
|
|
frc::Rotation3d(1_rad, 2_rad, 3_rad)),
|
|
|
|
|
-1,
|
2023-01-14 09:06:15 -06:00
|
|
|
{std::pair{1, 2}, std::pair{3, 4}, std::pair{5, 6}, std::pair{7, 8}},
|
2022-01-10 20:31:36 -08:00
|
|
|
{std::pair{1, 2}, std::pair{3, 4}, std::pair{5, 6}, std::pair{7, 8}}},
|
2021-01-16 20:41:47 -08:00
|
|
|
photonlib::PhotonTrackedTarget{
|
2022-01-10 20:31:36 -08:00
|
|
|
3.0,
|
|
|
|
|
-4.0,
|
|
|
|
|
9.1,
|
|
|
|
|
6.7,
|
2022-09-28 18:21:41 -07:00
|
|
|
-1,
|
|
|
|
|
frc::Transform3d(frc::Translation3d(1_m, 2_m, 3_m),
|
|
|
|
|
frc::Rotation3d(1_rad, 2_rad, 3_rad)),
|
2022-12-30 00:40:13 -06:00
|
|
|
frc::Transform3d(frc::Translation3d(1_m, 2_m, 3_m),
|
|
|
|
|
frc::Rotation3d(1_rad, 2_rad, 3_rad)),
|
|
|
|
|
-1,
|
2023-01-14 09:06:15 -06:00
|
|
|
{std::pair{1, 2}, std::pair{3, 4}, std::pair{5, 6}, std::pair{7, 8}},
|
2022-01-10 20:31:36 -08:00
|
|
|
{std::pair{1, 2}, std::pair{3, 4}, std::pair{5, 6},
|
|
|
|
|
std::pair{7, 8}}}};
|
2021-01-16 20:41:47 -08:00
|
|
|
|
|
|
|
|
photonlib::PhotonPipelineResult result2{2_s, targets};
|
|
|
|
|
photonlib::Packet p2;
|
|
|
|
|
p2 << result2;
|
|
|
|
|
|
|
|
|
|
photonlib::PhotonPipelineResult b2;
|
|
|
|
|
p2 >> b2;
|
|
|
|
|
|
|
|
|
|
EXPECT_EQ(result2, b2);
|
|
|
|
|
}
|