mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
[wpiutil] Change C++ protobuf to nanopb (#7309)
The Google C++ protobuf implementation has issues with dynamic linkage across DLL boundaries because it uses global variables. It also has a compile-time dependency because the protoc version must exactly match the libprotobuf version. Using nanopb with a customized generator fixes both of these issues. Co-authored-by: Gold856 <117957790+Gold856@users.noreply.github.com>
This commit is contained in:
@@ -4,31 +4,33 @@
|
||||
|
||||
#include "frc/controller/proto/ArmFeedforwardProto.h"
|
||||
|
||||
#include <wpi/ProtoHelper.h>
|
||||
#include <optional>
|
||||
|
||||
#include "controller.pb.h"
|
||||
#include "wpimath/protobuf/controller.npb.h"
|
||||
|
||||
google::protobuf::Message* wpi::Protobuf<frc::ArmFeedforward>::New(
|
||||
google::protobuf::Arena* arena) {
|
||||
return wpi::CreateMessage<wpi::proto::ProtobufArmFeedforward>(arena);
|
||||
}
|
||||
std::optional<frc::ArmFeedforward> wpi::Protobuf<frc::ArmFeedforward>::Unpack(
|
||||
InputStream& stream) {
|
||||
wpi_proto_ProtobufArmFeedforward msg;
|
||||
if (!stream.Decode(msg)) {
|
||||
return {};
|
||||
}
|
||||
|
||||
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()},
|
||||
units::volt_t{msg.ks},
|
||||
units::volt_t{msg.kg},
|
||||
units::unit_t<frc::ArmFeedforward::kv_unit>{msg.kv},
|
||||
units::unit_t<frc::ArmFeedforward::ka_unit>{msg.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.GetKs().value());
|
||||
m->set_kg(value.GetKg().value());
|
||||
m->set_kv(value.GetKv().value());
|
||||
m->set_ka(value.GetKa().value());
|
||||
bool wpi::Protobuf<frc::ArmFeedforward>::Pack(
|
||||
OutputStream& stream, const frc::ArmFeedforward& value) {
|
||||
wpi_proto_ProtobufArmFeedforward msg{
|
||||
.ks = value.GetKs().value(),
|
||||
.kg = value.GetKg().value(),
|
||||
.kv = value.GetKv().value(),
|
||||
.ka = value.GetKa().value(),
|
||||
.dt = 0,
|
||||
};
|
||||
return stream.Encode(msg);
|
||||
}
|
||||
|
||||
@@ -4,33 +4,30 @@
|
||||
|
||||
#include "frc/controller/proto/DifferentialDriveFeedforwardProto.h"
|
||||
|
||||
#include <wpi/ProtoHelper.h>
|
||||
#include "wpimath/protobuf/controller.npb.h"
|
||||
|
||||
#include "controller.pb.h"
|
||||
std::optional<frc::DifferentialDriveFeedforward>
|
||||
wpi::Protobuf<frc::DifferentialDriveFeedforward>::Unpack(InputStream& stream) {
|
||||
wpi_proto_ProtobufDifferentialDriveFeedforward msg;
|
||||
if (!stream.Decode(msg)) {
|
||||
return {};
|
||||
}
|
||||
|
||||
google::protobuf::Message* wpi::Protobuf<
|
||||
frc::DifferentialDriveFeedforward>::New(google::protobuf::Arena* arena) {
|
||||
return wpi::CreateMessage<wpi::proto::ProtobufDifferentialDriveFeedforward>(
|
||||
arena);
|
||||
return frc::DifferentialDriveFeedforward{
|
||||
decltype(1_V / 1_mps){msg.kv_linear},
|
||||
decltype(1_V / 1_mps_sq){msg.ka_linear},
|
||||
decltype(1_V / 1_mps){msg.kv_angular},
|
||||
decltype(1_V / 1_mps_sq){msg.ka_angular},
|
||||
};
|
||||
}
|
||||
|
||||
frc::DifferentialDriveFeedforward
|
||||
wpi::Protobuf<frc::DifferentialDriveFeedforward>::Unpack(
|
||||
const google::protobuf::Message& msg) {
|
||||
auto m = static_cast<const wpi::proto::ProtobufDifferentialDriveFeedforward*>(
|
||||
&msg);
|
||||
return {decltype(1_V / 1_mps){m->kv_linear()},
|
||||
decltype(1_V / 1_mps_sq){m->ka_linear()},
|
||||
decltype(1_V / 1_mps){m->kv_angular()},
|
||||
decltype(1_V / 1_mps_sq){m->ka_angular()}};
|
||||
}
|
||||
|
||||
void wpi::Protobuf<frc::DifferentialDriveFeedforward>::Pack(
|
||||
google::protobuf::Message* msg,
|
||||
const frc::DifferentialDriveFeedforward& value) {
|
||||
auto m = static_cast<wpi::proto::ProtobufDifferentialDriveFeedforward*>(msg);
|
||||
m->set_kv_linear(value.m_kVLinear.value());
|
||||
m->set_ka_linear(value.m_kALinear.value());
|
||||
m->set_kv_angular(value.m_kVAngular.value());
|
||||
m->set_ka_angular(value.m_kAAngular.value());
|
||||
bool wpi::Protobuf<frc::DifferentialDriveFeedforward>::Pack(
|
||||
OutputStream& stream, const frc::DifferentialDriveFeedforward& value) {
|
||||
wpi_proto_ProtobufDifferentialDriveFeedforward msg{
|
||||
.kv_linear = value.m_kVLinear.value(),
|
||||
.ka_linear = value.m_kALinear.value(),
|
||||
.kv_angular = value.m_kVAngular.value(),
|
||||
.ka_angular = value.m_kAAngular.value(),
|
||||
};
|
||||
return stream.Encode(msg);
|
||||
}
|
||||
|
||||
@@ -4,33 +4,28 @@
|
||||
|
||||
#include "frc/controller/proto/DifferentialDriveWheelVoltagesProto.h"
|
||||
|
||||
#include <wpi/ProtoHelper.h>
|
||||
#include <optional>
|
||||
|
||||
#include "controller.pb.h"
|
||||
#include "wpimath/protobuf/controller.npb.h"
|
||||
|
||||
google::protobuf::Message* wpi::Protobuf<
|
||||
frc::DifferentialDriveWheelVoltages>::New(google::protobuf::Arena* arena) {
|
||||
return wpi::CreateMessage<wpi::proto::ProtobufDifferentialDriveWheelVoltages>(
|
||||
arena);
|
||||
}
|
||||
std::optional<frc::DifferentialDriveWheelVoltages> wpi::Protobuf<
|
||||
frc::DifferentialDriveWheelVoltages>::Unpack(InputStream& stream) {
|
||||
wpi_proto_ProtobufDifferentialDriveWheelVoltages msg;
|
||||
if (!stream.Decode(msg)) {
|
||||
return {};
|
||||
}
|
||||
|
||||
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()},
|
||||
units::volt_t{msg.left},
|
||||
units::volt_t{msg.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());
|
||||
bool wpi::Protobuf<frc::DifferentialDriveWheelVoltages>::Pack(
|
||||
OutputStream& stream, const frc::DifferentialDriveWheelVoltages& value) {
|
||||
wpi_proto_ProtobufDifferentialDriveWheelVoltages msg{
|
||||
.left = value.left.value(),
|
||||
.right = value.right.value(),
|
||||
};
|
||||
return stream.Encode(msg);
|
||||
}
|
||||
|
||||
@@ -4,31 +4,33 @@
|
||||
|
||||
#include "frc/controller/proto/ElevatorFeedforwardProto.h"
|
||||
|
||||
#include <wpi/ProtoHelper.h>
|
||||
#include <optional>
|
||||
|
||||
#include "controller.pb.h"
|
||||
#include "wpimath/protobuf/controller.npb.h"
|
||||
|
||||
google::protobuf::Message* wpi::Protobuf<frc::ElevatorFeedforward>::New(
|
||||
google::protobuf::Arena* arena) {
|
||||
return wpi::CreateMessage<wpi::proto::ProtobufElevatorFeedforward>(arena);
|
||||
}
|
||||
std::optional<frc::ElevatorFeedforward>
|
||||
wpi::Protobuf<frc::ElevatorFeedforward>::Unpack(InputStream& stream) {
|
||||
wpi_proto_ProtobufElevatorFeedforward msg;
|
||||
if (!stream.Decode(msg)) {
|
||||
return {};
|
||||
}
|
||||
|
||||
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()},
|
||||
units::volt_t{msg.ks},
|
||||
units::volt_t{msg.kg},
|
||||
units::unit_t<frc::ElevatorFeedforward::kv_unit>{msg.kv},
|
||||
units::unit_t<frc::ElevatorFeedforward::ka_unit>{msg.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.GetKs().value());
|
||||
m->set_kg(value.GetKg().value());
|
||||
m->set_kv(value.GetKv().value());
|
||||
m->set_ka(value.GetKa().value());
|
||||
bool wpi::Protobuf<frc::ElevatorFeedforward>::Pack(
|
||||
OutputStream& stream, const frc::ElevatorFeedforward& value) {
|
||||
wpi_proto_ProtobufElevatorFeedforward msg{
|
||||
.ks = value.GetKs().value(),
|
||||
.kg = value.GetKg().value(),
|
||||
.kv = value.GetKv().value(),
|
||||
.ka = value.GetKa().value(),
|
||||
.dt = 0,
|
||||
};
|
||||
return stream.Encode(msg);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user