mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-21 01:01:43 +00:00
[wpimath] Add protobuf/struct for trivial types (#5935)
This implements de/serialization for the types that aren't templated (SwerveDriveKinematics) in C++ or where there is no trivial way to go round-trip (Splines) for the messages.
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "frc/trajectory/Trajectory.h"
|
||||
#include "trajectory.pb.h"
|
||||
|
||||
using namespace frc;
|
||||
|
||||
namespace {
|
||||
|
||||
using ProtoType = wpi::Protobuf<frc::Trajectory>;
|
||||
|
||||
const Trajectory kExpectedData = Trajectory{std::vector<frc::Trajectory::State>{
|
||||
Trajectory::State{1.1_s, 2.2_mps, 3.3_mps_sq,
|
||||
Pose2d(Translation2d(1.1_m, 2.2_m), Rotation2d(2.2_rad)),
|
||||
units::curvature_t{6.6}},
|
||||
Trajectory::State{2.1_s, 2.2_mps, 3.3_mps_sq,
|
||||
Pose2d(Translation2d(2.1_m, 2.2_m), Rotation2d(2.2_rad)),
|
||||
units::curvature_t{6.6}},
|
||||
Trajectory::State{3.1_s, 2.2_mps, 3.3_mps_sq,
|
||||
Pose2d(Translation2d(3.1_m, 2.2_m), Rotation2d(2.2_rad)),
|
||||
units::curvature_t{6.6}}}};
|
||||
} // namespace
|
||||
|
||||
TEST(TrajectoryProtoTest, Roundtrip) {
|
||||
google::protobuf::Arena arena;
|
||||
google::protobuf::Message* proto = ProtoType::New(&arena);
|
||||
ProtoType::Pack(proto, kExpectedData);
|
||||
|
||||
Trajectory unpacked_data = ProtoType::Unpack(*proto);
|
||||
EXPECT_EQ(kExpectedData.States(), unpacked_data.States());
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "frc/trajectory/Trajectory.h"
|
||||
#include "trajectory.pb.h"
|
||||
|
||||
using namespace frc;
|
||||
|
||||
namespace {
|
||||
|
||||
using ProtoType = wpi::Protobuf<frc::Trajectory::State>;
|
||||
|
||||
const Trajectory::State kExpectedData = Trajectory::State{
|
||||
1.91_s, 4.4_mps, 17.4_mps_sq,
|
||||
Pose2d{Translation2d{1.74_m, 19.1_m}, Rotation2d{22.9_rad}},
|
||||
units::curvature_t{0.174}};
|
||||
} // namespace
|
||||
|
||||
TEST(TrajectoryStateProtoTest, Roundtrip) {
|
||||
google::protobuf::Arena arena;
|
||||
google::protobuf::Message* proto = ProtoType::New(&arena);
|
||||
ProtoType::Pack(proto, kExpectedData);
|
||||
|
||||
Trajectory::State unpacked_data = ProtoType::Unpack(*proto);
|
||||
EXPECT_EQ(kExpectedData.t.value(), unpacked_data.t.value());
|
||||
EXPECT_EQ(kExpectedData.velocity.value(), unpacked_data.velocity.value());
|
||||
EXPECT_EQ(kExpectedData.acceleration.value(),
|
||||
unpacked_data.acceleration.value());
|
||||
EXPECT_EQ(kExpectedData.pose, unpacked_data.pose);
|
||||
EXPECT_EQ(kExpectedData.curvature.value(), unpacked_data.curvature.value());
|
||||
}
|
||||
Reference in New Issue
Block a user