[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:
PJ Reiniger
2023-11-21 13:14:06 -05:00
committed by GitHub
parent 35744a036e
commit bb05e20247
158 changed files with 4266 additions and 4 deletions

View File

@@ -0,0 +1,33 @@
// 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 "frc/controller/proto/ArmFeedforwardProto.h"
#include "controller.pb.h"
google::protobuf::Message* wpi::Protobuf<frc::ArmFeedforward>::New(
google::protobuf::Arena* arena) {
return google::protobuf::Arena::CreateMessage<
wpi::proto::ProtobufArmFeedforward>(arena);
}
frc::ArmFeedforward wpi::Protobuf<frc::ArmFeedforward>::Unpack(
const google::protobuf::Message& msg) {
auto m = static_cast<const wpi::proto::ProtobufArmFeedforward*>(&msg);
return frc::ArmFeedforward{
units::volt_t{m->ks()},
units::volt_t{m->kg()},
units::unit_t<frc::ArmFeedforward::kv_unit>{m->kv()},
units::unit_t<frc::ArmFeedforward::ka_unit>{m->ka()},
};
}
void wpi::Protobuf<frc::ArmFeedforward>::Pack(
google::protobuf::Message* msg, const frc::ArmFeedforward& value) {
auto m = static_cast<wpi::proto::ProtobufArmFeedforward*>(msg);
m->set_ks(value.kS.value());
m->set_kg(value.kG.value());
m->set_kv(value.kV.value());
m->set_ka(value.kA.value());
}

View File

@@ -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 "frc/controller/proto/DifferentialDriveWheelVoltagesProto.h"
#include "controller.pb.h"
google::protobuf::Message* wpi::Protobuf<
frc::DifferentialDriveWheelVoltages>::New(google::protobuf::Arena* arena) {
return google::protobuf::Arena::CreateMessage<
wpi::proto::ProtobufDifferentialDriveWheelVoltages>(arena);
}
frc::DifferentialDriveWheelVoltages
wpi::Protobuf<frc::DifferentialDriveWheelVoltages>::Unpack(
const google::protobuf::Message& msg) {
auto m =
static_cast<const wpi::proto::ProtobufDifferentialDriveWheelVoltages*>(
&msg);
return frc::DifferentialDriveWheelVoltages{
units::volt_t{m->left()},
units::volt_t{m->right()},
};
}
void wpi::Protobuf<frc::DifferentialDriveWheelVoltages>::Pack(
google::protobuf::Message* msg,
const frc::DifferentialDriveWheelVoltages& value) {
auto m =
static_cast<wpi::proto::ProtobufDifferentialDriveWheelVoltages*>(msg);
m->set_left(value.left.value());
m->set_right(value.right.value());
}

View File

@@ -0,0 +1,33 @@
// 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 "frc/controller/proto/ElevatorFeedforwardProto.h"
#include "controller.pb.h"
google::protobuf::Message* wpi::Protobuf<frc::ElevatorFeedforward>::New(
google::protobuf::Arena* arena) {
return google::protobuf::Arena::CreateMessage<
wpi::proto::ProtobufElevatorFeedforward>(arena);
}
frc::ElevatorFeedforward wpi::Protobuf<frc::ElevatorFeedforward>::Unpack(
const google::protobuf::Message& msg) {
auto m = static_cast<const wpi::proto::ProtobufElevatorFeedforward*>(&msg);
return frc::ElevatorFeedforward{
units::volt_t{m->ks()},
units::volt_t{m->kg()},
units::unit_t<frc::ElevatorFeedforward::kv_unit>{m->kv()},
units::unit_t<frc::ElevatorFeedforward::ka_unit>{m->ka()},
};
}
void wpi::Protobuf<frc::ElevatorFeedforward>::Pack(
google::protobuf::Message* msg, const frc::ElevatorFeedforward& value) {
auto m = static_cast<wpi::proto::ProtobufElevatorFeedforward*>(msg);
m->set_ks(value.kS());
m->set_kg(value.kG());
m->set_kv(value.kV());
m->set_ka(value.kA());
}