mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-23 01:21: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:
@@ -8,11 +8,14 @@
|
||||
#include <wpi/protobuf/Protobuf.h>
|
||||
|
||||
#include "frc/controller/ArmFeedforward.h"
|
||||
#include "pb.h"
|
||||
#include "wpimath/protobuf/controller.npb.h"
|
||||
|
||||
template <>
|
||||
struct WPILIB_DLLEXPORT wpi::Protobuf<frc::ArmFeedforward> {
|
||||
static google::protobuf::Message* New(google::protobuf::Arena* arena);
|
||||
static frc::ArmFeedforward Unpack(const google::protobuf::Message& msg);
|
||||
static void Pack(google::protobuf::Message* msg,
|
||||
const frc::ArmFeedforward& value);
|
||||
using MessageStruct = wpi_proto_ProtobufArmFeedforward;
|
||||
using InputStream = wpi::ProtoInputStream<frc::ArmFeedforward>;
|
||||
using OutputStream = wpi::ProtoOutputStream<frc::ArmFeedforward>;
|
||||
static std::optional<frc::ArmFeedforward> Unpack(InputStream& stream);
|
||||
static bool Pack(OutputStream& stream, const frc::ArmFeedforward& value);
|
||||
};
|
||||
|
||||
@@ -8,12 +8,17 @@
|
||||
#include <wpi/protobuf/Protobuf.h>
|
||||
|
||||
#include "frc/controller/DifferentialDriveFeedforward.h"
|
||||
#include "pb.h"
|
||||
#include "wpimath/protobuf/controller.npb.h"
|
||||
|
||||
template <>
|
||||
struct WPILIB_DLLEXPORT wpi::Protobuf<frc::DifferentialDriveFeedforward> {
|
||||
static google::protobuf::Message* New(google::protobuf::Arena* arena);
|
||||
static frc::DifferentialDriveFeedforward Unpack(
|
||||
const google::protobuf::Message& msg);
|
||||
static void Pack(google::protobuf::Message* msg,
|
||||
using MessageStruct = wpi_proto_ProtobufDifferentialDriveFeedforward;
|
||||
using InputStream = wpi::ProtoInputStream<frc::DifferentialDriveFeedforward>;
|
||||
using OutputStream =
|
||||
wpi::ProtoOutputStream<frc::DifferentialDriveFeedforward>;
|
||||
static std::optional<frc::DifferentialDriveFeedforward> Unpack(
|
||||
InputStream& stream);
|
||||
static bool Pack(OutputStream& stream,
|
||||
const frc::DifferentialDriveFeedforward& value);
|
||||
};
|
||||
|
||||
@@ -8,12 +8,18 @@
|
||||
#include <wpi/protobuf/Protobuf.h>
|
||||
|
||||
#include "frc/controller/DifferentialDriveWheelVoltages.h"
|
||||
#include "pb.h"
|
||||
#include "wpimath/protobuf/controller.npb.h"
|
||||
|
||||
template <>
|
||||
struct WPILIB_DLLEXPORT wpi::Protobuf<frc::DifferentialDriveWheelVoltages> {
|
||||
static google::protobuf::Message* New(google::protobuf::Arena* arena);
|
||||
static frc::DifferentialDriveWheelVoltages Unpack(
|
||||
const google::protobuf::Message& msg);
|
||||
static void Pack(google::protobuf::Message* msg,
|
||||
using MessageStruct = wpi_proto_ProtobufDifferentialDriveWheelVoltages;
|
||||
using InputStream =
|
||||
wpi::ProtoInputStream<frc::DifferentialDriveWheelVoltages>;
|
||||
using OutputStream =
|
||||
wpi::ProtoOutputStream<frc::DifferentialDriveWheelVoltages>;
|
||||
static std::optional<frc::DifferentialDriveWheelVoltages> Unpack(
|
||||
InputStream& stream);
|
||||
static bool Pack(OutputStream& stream,
|
||||
const frc::DifferentialDriveWheelVoltages& value);
|
||||
};
|
||||
|
||||
@@ -8,11 +8,14 @@
|
||||
#include <wpi/protobuf/Protobuf.h>
|
||||
|
||||
#include "frc/controller/ElevatorFeedforward.h"
|
||||
#include "pb.h"
|
||||
#include "wpimath/protobuf/controller.npb.h"
|
||||
|
||||
template <>
|
||||
struct WPILIB_DLLEXPORT wpi::Protobuf<frc::ElevatorFeedforward> {
|
||||
static google::protobuf::Message* New(google::protobuf::Arena* arena);
|
||||
static frc::ElevatorFeedforward Unpack(const google::protobuf::Message& msg);
|
||||
static void Pack(google::protobuf::Message* msg,
|
||||
const frc::ElevatorFeedforward& value);
|
||||
using MessageStruct = wpi_proto_ProtobufElevatorFeedforward;
|
||||
using InputStream = wpi::ProtoInputStream<frc::ElevatorFeedforward>;
|
||||
using OutputStream = wpi::ProtoOutputStream<frc::ElevatorFeedforward>;
|
||||
static std::optional<frc::ElevatorFeedforward> Unpack(InputStream& stream);
|
||||
static bool Pack(OutputStream& stream, const frc::ElevatorFeedforward& value);
|
||||
};
|
||||
|
||||
@@ -4,47 +4,55 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <wpi/ProtoHelper.h>
|
||||
#include <wpi/protobuf/Protobuf.h>
|
||||
|
||||
#include "controller.pb.h"
|
||||
#include "frc/controller/SimpleMotorFeedforward.h"
|
||||
#include "pb.h"
|
||||
#include "units/length.h"
|
||||
#include "wpimath/protobuf/controller.npb.h"
|
||||
|
||||
// Everything is converted into units for
|
||||
// frc::SimpleMotorFeedforward<units::meters>
|
||||
|
||||
template <class Distance>
|
||||
struct wpi::Protobuf<frc::SimpleMotorFeedforward<Distance>> {
|
||||
static google::protobuf::Message* New(google::protobuf::Arena* arena) {
|
||||
return wpi::CreateMessage<wpi::proto::ProtobufSimpleMotorFeedforward>(
|
||||
arena);
|
||||
}
|
||||
struct wpi::Protobuf<frc::SimpleMotorFeedforward<Distance>> { // NOLINT
|
||||
using MessageStruct = wpi_proto_ProtobufSimpleMotorFeedforward;
|
||||
using InputStream =
|
||||
wpi::ProtoInputStream<frc::SimpleMotorFeedforward<Distance>>;
|
||||
using OutputStream =
|
||||
wpi::ProtoOutputStream<frc::SimpleMotorFeedforward<Distance>>;
|
||||
|
||||
static frc::SimpleMotorFeedforward<Distance> Unpack(
|
||||
const google::protobuf::Message& msg) {
|
||||
auto m =
|
||||
static_cast<const wpi::proto::ProtobufSimpleMotorFeedforward*>(&msg);
|
||||
return {units::volt_t{m->ks()},
|
||||
units::unit_t<frc::SimpleMotorFeedforward<units::meters>::kv_unit>{
|
||||
m->kv()},
|
||||
units::unit_t<frc::SimpleMotorFeedforward<units::meters>::ka_unit>{
|
||||
m->ka()},
|
||||
units::second_t{m->dt()}};
|
||||
}
|
||||
static std::optional<frc::SimpleMotorFeedforward<Distance>> Unpack(
|
||||
InputStream& stream) {
|
||||
wpi_proto_ProtobufSimpleMotorFeedforward msg;
|
||||
if (!stream.Decode(msg)) {
|
||||
return {};
|
||||
}
|
||||
|
||||
static void Pack(google::protobuf::Message* msg,
|
||||
const frc::SimpleMotorFeedforward<Distance>& value) {
|
||||
auto m = static_cast<wpi::proto::ProtobufSimpleMotorFeedforward*>(msg);
|
||||
m->set_ks(value.GetKs().value());
|
||||
m->set_kv(
|
||||
return frc::SimpleMotorFeedforward<Distance>{
|
||||
units::volt_t{msg.ks},
|
||||
units::unit_t<frc::SimpleMotorFeedforward<units::meters>::kv_unit>{
|
||||
value.GetKv()}
|
||||
.value());
|
||||
m->set_ka(
|
||||
msg.kv},
|
||||
units::unit_t<frc::SimpleMotorFeedforward<units::meters>::ka_unit>{
|
||||
value.GetKa()}
|
||||
.value());
|
||||
m->set_dt(units::second_t{value.GetDt()}.value());
|
||||
msg.ka},
|
||||
units::second_t{msg.dt},
|
||||
};
|
||||
}
|
||||
|
||||
static bool Pack(OutputStream& stream,
|
||||
const frc::SimpleMotorFeedforward<Distance>& value) {
|
||||
wpi_proto_ProtobufSimpleMotorFeedforward msg{
|
||||
.ks = value.GetKs().value(),
|
||||
.kv =
|
||||
units::unit_t<frc::SimpleMotorFeedforward<units::meters>::kv_unit>{
|
||||
value.GetKv()}
|
||||
.value(),
|
||||
.ka =
|
||||
units::unit_t<frc::SimpleMotorFeedforward<units::meters>::ka_unit>{
|
||||
value.GetKa()}
|
||||
.value(),
|
||||
.dt = units::second_t{value.GetDt()}.value(),
|
||||
};
|
||||
return stream.Encode(msg);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -8,10 +8,13 @@
|
||||
#include <wpi/protobuf/Protobuf.h>
|
||||
|
||||
#include "frc/geometry/Ellipse2d.h"
|
||||
#include "wpimath/protobuf/geometry2d.npb.h"
|
||||
|
||||
template <>
|
||||
struct WPILIB_DLLEXPORT wpi::Protobuf<frc::Ellipse2d> {
|
||||
static google::protobuf::Message* New(google::protobuf::Arena* arena);
|
||||
static frc::Ellipse2d Unpack(const google::protobuf::Message& msg);
|
||||
static void Pack(google::protobuf::Message* msg, const frc::Ellipse2d& value);
|
||||
using MessageStruct = wpi_proto_ProtobufEllipse2d;
|
||||
using InputStream = wpi::ProtoInputStream<frc::Ellipse2d>;
|
||||
using OutputStream = wpi::ProtoOutputStream<frc::Ellipse2d>;
|
||||
static std::optional<frc::Ellipse2d> Unpack(InputStream& stream);
|
||||
static bool Pack(OutputStream& stream, const frc::Ellipse2d& value);
|
||||
};
|
||||
|
||||
@@ -8,10 +8,14 @@
|
||||
#include <wpi/protobuf/Protobuf.h>
|
||||
|
||||
#include "frc/geometry/Pose2d.h"
|
||||
#include "pb.h"
|
||||
#include "wpimath/protobuf/geometry2d.npb.h"
|
||||
|
||||
template <>
|
||||
struct WPILIB_DLLEXPORT wpi::Protobuf<frc::Pose2d> {
|
||||
static google::protobuf::Message* New(google::protobuf::Arena* arena);
|
||||
static frc::Pose2d Unpack(const google::protobuf::Message& msg);
|
||||
static void Pack(google::protobuf::Message* msg, const frc::Pose2d& value);
|
||||
using MessageStruct = wpi_proto_ProtobufPose2d;
|
||||
using InputStream = wpi::ProtoInputStream<frc::Pose2d>;
|
||||
using OutputStream = wpi::ProtoOutputStream<frc::Pose2d>;
|
||||
static std::optional<frc::Pose2d> Unpack(InputStream& stream);
|
||||
static bool Pack(OutputStream& stream, const frc::Pose2d& value);
|
||||
};
|
||||
|
||||
@@ -8,10 +8,13 @@
|
||||
#include <wpi/protobuf/Protobuf.h>
|
||||
|
||||
#include "frc/geometry/Pose3d.h"
|
||||
#include "wpimath/protobuf/geometry3d.npb.h"
|
||||
|
||||
template <>
|
||||
struct WPILIB_DLLEXPORT wpi::Protobuf<frc::Pose3d> {
|
||||
static google::protobuf::Message* New(google::protobuf::Arena* arena);
|
||||
static frc::Pose3d Unpack(const google::protobuf::Message& msg);
|
||||
static void Pack(google::protobuf::Message* msg, const frc::Pose3d& value);
|
||||
using MessageStruct = wpi_proto_ProtobufPose3d;
|
||||
using InputStream = wpi::ProtoInputStream<frc::Pose3d>;
|
||||
using OutputStream = wpi::ProtoOutputStream<frc::Pose3d>;
|
||||
static std::optional<frc::Pose3d> Unpack(InputStream& stream);
|
||||
static bool Pack(OutputStream& stream, const frc::Pose3d& value);
|
||||
};
|
||||
|
||||
@@ -8,11 +8,13 @@
|
||||
#include <wpi/protobuf/Protobuf.h>
|
||||
|
||||
#include "frc/geometry/Quaternion.h"
|
||||
#include "wpimath/protobuf/geometry3d.npb.h"
|
||||
|
||||
template <>
|
||||
struct WPILIB_DLLEXPORT wpi::Protobuf<frc::Quaternion> {
|
||||
static google::protobuf::Message* New(google::protobuf::Arena* arena);
|
||||
static frc::Quaternion Unpack(const google::protobuf::Message& msg);
|
||||
static void Pack(google::protobuf::Message* msg,
|
||||
const frc::Quaternion& value);
|
||||
using MessageStruct = wpi_proto_ProtobufQuaternion;
|
||||
using InputStream = wpi::ProtoInputStream<frc::Quaternion>;
|
||||
using OutputStream = wpi::ProtoOutputStream<frc::Quaternion>;
|
||||
static std::optional<frc::Quaternion> Unpack(InputStream& stream);
|
||||
static bool Pack(OutputStream& stream, const frc::Quaternion& value);
|
||||
};
|
||||
|
||||
@@ -8,11 +8,13 @@
|
||||
#include <wpi/protobuf/Protobuf.h>
|
||||
|
||||
#include "frc/geometry/Rectangle2d.h"
|
||||
#include "wpimath/protobuf/geometry2d.npb.h"
|
||||
|
||||
template <>
|
||||
struct WPILIB_DLLEXPORT wpi::Protobuf<frc::Rectangle2d> {
|
||||
static google::protobuf::Message* New(google::protobuf::Arena* arena);
|
||||
static frc::Rectangle2d Unpack(const google::protobuf::Message& msg);
|
||||
static void Pack(google::protobuf::Message* msg,
|
||||
const frc::Rectangle2d& value);
|
||||
using MessageStruct = wpi_proto_ProtobufRectangle2d;
|
||||
using InputStream = wpi::ProtoInputStream<frc::Rectangle2d>;
|
||||
using OutputStream = wpi::ProtoOutputStream<frc::Rectangle2d>;
|
||||
static std::optional<frc::Rectangle2d> Unpack(InputStream& stream);
|
||||
static bool Pack(OutputStream& stream, const frc::Rectangle2d& value);
|
||||
};
|
||||
|
||||
@@ -8,11 +8,14 @@
|
||||
#include <wpi/protobuf/Protobuf.h>
|
||||
|
||||
#include "frc/geometry/Rotation2d.h"
|
||||
#include "pb.h"
|
||||
#include "wpimath/protobuf/geometry2d.npb.h"
|
||||
|
||||
template <>
|
||||
struct WPILIB_DLLEXPORT wpi::Protobuf<frc::Rotation2d> {
|
||||
static google::protobuf::Message* New(google::protobuf::Arena* arena);
|
||||
static frc::Rotation2d Unpack(const google::protobuf::Message& msg);
|
||||
static void Pack(google::protobuf::Message* msg,
|
||||
const frc::Rotation2d& value);
|
||||
using MessageStruct = wpi_proto_ProtobufRotation2d;
|
||||
using InputStream = wpi::ProtoInputStream<frc::Rotation2d>;
|
||||
using OutputStream = wpi::ProtoOutputStream<frc::Rotation2d>;
|
||||
static std::optional<frc::Rotation2d> Unpack(InputStream& stream);
|
||||
static bool Pack(OutputStream& stream, const frc::Rotation2d& value);
|
||||
};
|
||||
|
||||
@@ -8,11 +8,13 @@
|
||||
#include <wpi/protobuf/Protobuf.h>
|
||||
|
||||
#include "frc/geometry/Rotation3d.h"
|
||||
#include "wpimath/protobuf/geometry3d.npb.h"
|
||||
|
||||
template <>
|
||||
struct WPILIB_DLLEXPORT wpi::Protobuf<frc::Rotation3d> {
|
||||
static google::protobuf::Message* New(google::protobuf::Arena* arena);
|
||||
static frc::Rotation3d Unpack(const google::protobuf::Message& msg);
|
||||
static void Pack(google::protobuf::Message* msg,
|
||||
const frc::Rotation3d& value);
|
||||
using MessageStruct = wpi_proto_ProtobufRotation3d;
|
||||
using InputStream = wpi::ProtoInputStream<frc::Rotation3d>;
|
||||
using OutputStream = wpi::ProtoOutputStream<frc::Rotation3d>;
|
||||
static std::optional<frc::Rotation3d> Unpack(InputStream& stream);
|
||||
static bool Pack(OutputStream& stream, const frc::Rotation3d& value);
|
||||
};
|
||||
|
||||
@@ -8,11 +8,13 @@
|
||||
#include <wpi/protobuf/Protobuf.h>
|
||||
|
||||
#include "frc/geometry/Transform2d.h"
|
||||
#include "wpimath/protobuf/geometry2d.npb.h"
|
||||
|
||||
template <>
|
||||
struct WPILIB_DLLEXPORT wpi::Protobuf<frc::Transform2d> {
|
||||
static google::protobuf::Message* New(google::protobuf::Arena* arena);
|
||||
static frc::Transform2d Unpack(const google::protobuf::Message& msg);
|
||||
static void Pack(google::protobuf::Message* msg,
|
||||
const frc::Transform2d& value);
|
||||
using MessageStruct = wpi_proto_ProtobufTransform2d;
|
||||
using InputStream = wpi::ProtoInputStream<frc::Transform2d>;
|
||||
using OutputStream = wpi::ProtoOutputStream<frc::Transform2d>;
|
||||
static std::optional<frc::Transform2d> Unpack(InputStream& stream);
|
||||
static bool Pack(OutputStream& stream, const frc::Transform2d& value);
|
||||
};
|
||||
|
||||
@@ -8,11 +8,13 @@
|
||||
#include <wpi/protobuf/Protobuf.h>
|
||||
|
||||
#include "frc/geometry/Transform3d.h"
|
||||
#include "wpimath/protobuf/geometry3d.npb.h"
|
||||
|
||||
template <>
|
||||
struct WPILIB_DLLEXPORT wpi::Protobuf<frc::Transform3d> {
|
||||
static google::protobuf::Message* New(google::protobuf::Arena* arena);
|
||||
static frc::Transform3d Unpack(const google::protobuf::Message& msg);
|
||||
static void Pack(google::protobuf::Message* msg,
|
||||
const frc::Transform3d& value);
|
||||
using MessageStruct = wpi_proto_ProtobufTransform3d;
|
||||
using InputStream = wpi::ProtoInputStream<frc::Transform3d>;
|
||||
using OutputStream = wpi::ProtoOutputStream<frc::Transform3d>;
|
||||
static std::optional<frc::Transform3d> Unpack(InputStream& stream);
|
||||
static bool Pack(OutputStream& stream, const frc::Transform3d& value);
|
||||
};
|
||||
|
||||
@@ -8,11 +8,14 @@
|
||||
#include <wpi/protobuf/Protobuf.h>
|
||||
|
||||
#include "frc/geometry/Translation2d.h"
|
||||
#include "pb.h"
|
||||
#include "wpimath/protobuf/geometry2d.npb.h"
|
||||
|
||||
template <>
|
||||
struct WPILIB_DLLEXPORT wpi::Protobuf<frc::Translation2d> {
|
||||
static google::protobuf::Message* New(google::protobuf::Arena* arena);
|
||||
static frc::Translation2d Unpack(const google::protobuf::Message& msg);
|
||||
static void Pack(google::protobuf::Message* msg,
|
||||
const frc::Translation2d& value);
|
||||
using MessageStruct = wpi_proto_ProtobufTranslation2d;
|
||||
using InputStream = wpi::ProtoInputStream<frc::Translation2d>;
|
||||
using OutputStream = wpi::ProtoOutputStream<frc::Translation2d>;
|
||||
static std::optional<frc::Translation2d> Unpack(InputStream& stream);
|
||||
static bool Pack(OutputStream& stream, const frc::Translation2d& value);
|
||||
};
|
||||
|
||||
@@ -8,11 +8,13 @@
|
||||
#include <wpi/protobuf/Protobuf.h>
|
||||
|
||||
#include "frc/geometry/Translation3d.h"
|
||||
#include "wpimath/protobuf/geometry3d.npb.h"
|
||||
|
||||
template <>
|
||||
struct WPILIB_DLLEXPORT wpi::Protobuf<frc::Translation3d> {
|
||||
static google::protobuf::Message* New(google::protobuf::Arena* arena);
|
||||
static frc::Translation3d Unpack(const google::protobuf::Message& msg);
|
||||
static void Pack(google::protobuf::Message* msg,
|
||||
const frc::Translation3d& value);
|
||||
using MessageStruct = wpi_proto_ProtobufTranslation3d;
|
||||
using InputStream = wpi::ProtoInputStream<frc::Translation3d>;
|
||||
using OutputStream = wpi::ProtoOutputStream<frc::Translation3d>;
|
||||
static std::optional<frc::Translation3d> Unpack(InputStream& stream);
|
||||
static bool Pack(OutputStream& stream, const frc::Translation3d& value);
|
||||
};
|
||||
|
||||
@@ -8,10 +8,13 @@
|
||||
#include <wpi/protobuf/Protobuf.h>
|
||||
|
||||
#include "frc/geometry/Twist2d.h"
|
||||
#include "wpimath/protobuf/geometry2d.npb.h"
|
||||
|
||||
template <>
|
||||
struct WPILIB_DLLEXPORT wpi::Protobuf<frc::Twist2d> {
|
||||
static google::protobuf::Message* New(google::protobuf::Arena* arena);
|
||||
static frc::Twist2d Unpack(const google::protobuf::Message& msg);
|
||||
static void Pack(google::protobuf::Message* msg, const frc::Twist2d& value);
|
||||
using MessageStruct = wpi_proto_ProtobufTwist2d;
|
||||
using InputStream = wpi::ProtoInputStream<frc::Twist2d>;
|
||||
using OutputStream = wpi::ProtoOutputStream<frc::Twist2d>;
|
||||
static std::optional<frc::Twist2d> Unpack(InputStream& stream);
|
||||
static bool Pack(OutputStream& stream, const frc::Twist2d& value);
|
||||
};
|
||||
|
||||
@@ -8,10 +8,13 @@
|
||||
#include <wpi/protobuf/Protobuf.h>
|
||||
|
||||
#include "frc/geometry/Twist3d.h"
|
||||
#include "wpimath/protobuf/geometry3d.npb.h"
|
||||
|
||||
template <>
|
||||
struct WPILIB_DLLEXPORT wpi::Protobuf<frc::Twist3d> {
|
||||
static google::protobuf::Message* New(google::protobuf::Arena* arena);
|
||||
static frc::Twist3d Unpack(const google::protobuf::Message& msg);
|
||||
static void Pack(google::protobuf::Message* msg, const frc::Twist3d& value);
|
||||
using MessageStruct = wpi_proto_ProtobufTwist3d;
|
||||
using InputStream = wpi::ProtoInputStream<frc::Twist3d>;
|
||||
using OutputStream = wpi::ProtoOutputStream<frc::Twist3d>;
|
||||
static std::optional<frc::Twist3d> Unpack(InputStream& stream);
|
||||
static bool Pack(OutputStream& stream, const frc::Twist3d& value);
|
||||
};
|
||||
|
||||
@@ -24,6 +24,8 @@ template <typename WheelSpeeds, typename WheelPositions>
|
||||
std::assignable_from<WheelPositions&, const WheelPositions&>
|
||||
class WPILIB_DLLEXPORT Kinematics {
|
||||
public:
|
||||
virtual ~Kinematics() noexcept = default;
|
||||
|
||||
/**
|
||||
* Performs forward kinematics to return the resulting chassis speed from the
|
||||
* wheel speeds. This method is often used for odometry -- determining the
|
||||
|
||||
@@ -429,7 +429,7 @@ class SwerveDriveKinematics
|
||||
return {result};
|
||||
}
|
||||
|
||||
const wpi::array<Translation2d, NumModules> GetModules() const {
|
||||
const wpi::array<Translation2d, NumModules>& GetModules() const {
|
||||
return m_modules;
|
||||
}
|
||||
|
||||
|
||||
@@ -8,11 +8,13 @@
|
||||
#include <wpi/protobuf/Protobuf.h>
|
||||
|
||||
#include "frc/kinematics/ChassisSpeeds.h"
|
||||
#include "wpimath/protobuf/kinematics.npb.h"
|
||||
|
||||
template <>
|
||||
struct WPILIB_DLLEXPORT wpi::Protobuf<frc::ChassisSpeeds> {
|
||||
static google::protobuf::Message* New(google::protobuf::Arena* arena);
|
||||
static frc::ChassisSpeeds Unpack(const google::protobuf::Message& msg);
|
||||
static void Pack(google::protobuf::Message* msg,
|
||||
const frc::ChassisSpeeds& value);
|
||||
using MessageStruct = wpi_proto_ProtobufChassisSpeeds;
|
||||
using InputStream = wpi::ProtoInputStream<frc::ChassisSpeeds>;
|
||||
using OutputStream = wpi::ProtoOutputStream<frc::ChassisSpeeds>;
|
||||
static std::optional<frc::ChassisSpeeds> Unpack(InputStream& stream);
|
||||
static bool Pack(OutputStream& stream, const frc::ChassisSpeeds& value);
|
||||
};
|
||||
|
||||
@@ -8,12 +8,15 @@
|
||||
#include <wpi/protobuf/Protobuf.h>
|
||||
|
||||
#include "frc/kinematics/DifferentialDriveKinematics.h"
|
||||
#include "wpimath/protobuf/kinematics.npb.h"
|
||||
|
||||
template <>
|
||||
struct WPILIB_DLLEXPORT wpi::Protobuf<frc::DifferentialDriveKinematics> {
|
||||
static google::protobuf::Message* New(google::protobuf::Arena* arena);
|
||||
static frc::DifferentialDriveKinematics Unpack(
|
||||
const google::protobuf::Message& msg);
|
||||
static void Pack(google::protobuf::Message* msg,
|
||||
using MessageStruct = wpi_proto_ProtobufDifferentialDriveKinematics;
|
||||
using InputStream = wpi::ProtoInputStream<frc::DifferentialDriveKinematics>;
|
||||
using OutputStream = wpi::ProtoOutputStream<frc::DifferentialDriveKinematics>;
|
||||
static std::optional<frc::DifferentialDriveKinematics> Unpack(
|
||||
InputStream& stream);
|
||||
static bool Pack(OutputStream& stream,
|
||||
const frc::DifferentialDriveKinematics& value);
|
||||
};
|
||||
|
||||
@@ -8,12 +8,17 @@
|
||||
#include <wpi/protobuf/Protobuf.h>
|
||||
|
||||
#include "frc/kinematics/DifferentialDriveWheelPositions.h"
|
||||
#include "wpimath/protobuf/kinematics.npb.h"
|
||||
|
||||
template <>
|
||||
struct WPILIB_DLLEXPORT wpi::Protobuf<frc::DifferentialDriveWheelPositions> {
|
||||
static google::protobuf::Message* New(google::protobuf::Arena* arena);
|
||||
static frc::DifferentialDriveWheelPositions Unpack(
|
||||
const google::protobuf::Message& msg);
|
||||
static void Pack(google::protobuf::Message* msg,
|
||||
using MessageStruct = wpi_proto_ProtobufDifferentialDriveWheelPositions;
|
||||
using InputStream =
|
||||
wpi::ProtoInputStream<frc::DifferentialDriveWheelPositions>;
|
||||
using OutputStream =
|
||||
wpi::ProtoOutputStream<frc::DifferentialDriveWheelPositions>;
|
||||
static std::optional<frc::DifferentialDriveWheelPositions> Unpack(
|
||||
InputStream& stream);
|
||||
static bool Pack(OutputStream& stream,
|
||||
const frc::DifferentialDriveWheelPositions& value);
|
||||
};
|
||||
|
||||
@@ -8,12 +8,16 @@
|
||||
#include <wpi/protobuf/Protobuf.h>
|
||||
|
||||
#include "frc/kinematics/DifferentialDriveWheelSpeeds.h"
|
||||
#include "wpimath/protobuf/kinematics.npb.h"
|
||||
|
||||
template <>
|
||||
struct WPILIB_DLLEXPORT wpi::Protobuf<frc::DifferentialDriveWheelSpeeds> {
|
||||
static google::protobuf::Message* New(google::protobuf::Arena* arena);
|
||||
static frc::DifferentialDriveWheelSpeeds Unpack(
|
||||
const google::protobuf::Message& msg);
|
||||
static void Pack(google::protobuf::Message* msg,
|
||||
using MessageStruct = wpi_proto_ProtobufDifferentialDriveWheelSpeeds;
|
||||
using InputStream = wpi::ProtoInputStream<frc::DifferentialDriveWheelSpeeds>;
|
||||
using OutputStream =
|
||||
wpi::ProtoOutputStream<frc::DifferentialDriveWheelSpeeds>;
|
||||
static std::optional<frc::DifferentialDriveWheelSpeeds> Unpack(
|
||||
InputStream& stream);
|
||||
static bool Pack(OutputStream& stream,
|
||||
const frc::DifferentialDriveWheelSpeeds& value);
|
||||
};
|
||||
|
||||
@@ -8,12 +8,14 @@
|
||||
#include <wpi/protobuf/Protobuf.h>
|
||||
|
||||
#include "frc/kinematics/MecanumDriveKinematics.h"
|
||||
#include "wpimath/protobuf/kinematics.npb.h"
|
||||
|
||||
template <>
|
||||
struct WPILIB_DLLEXPORT wpi::Protobuf<frc::MecanumDriveKinematics> {
|
||||
static google::protobuf::Message* New(google::protobuf::Arena* arena);
|
||||
static frc::MecanumDriveKinematics Unpack(
|
||||
const google::protobuf::Message& msg);
|
||||
static void Pack(google::protobuf::Message* msg,
|
||||
using MessageStruct = wpi_proto_ProtobufMecanumDriveKinematics;
|
||||
using InputStream = wpi::ProtoInputStream<frc::MecanumDriveKinematics>;
|
||||
using OutputStream = wpi::ProtoOutputStream<frc::MecanumDriveKinematics>;
|
||||
static std::optional<frc::MecanumDriveKinematics> Unpack(InputStream& stream);
|
||||
static bool Pack(OutputStream& stream,
|
||||
const frc::MecanumDriveKinematics& value);
|
||||
};
|
||||
|
||||
@@ -8,12 +8,15 @@
|
||||
#include <wpi/protobuf/Protobuf.h>
|
||||
|
||||
#include "frc/kinematics/MecanumDriveWheelPositions.h"
|
||||
#include "wpimath/protobuf/kinematics.npb.h"
|
||||
|
||||
template <>
|
||||
struct WPILIB_DLLEXPORT wpi::Protobuf<frc::MecanumDriveWheelPositions> {
|
||||
static google::protobuf::Message* New(google::protobuf::Arena* arena);
|
||||
static frc::MecanumDriveWheelPositions Unpack(
|
||||
const google::protobuf::Message& msg);
|
||||
static void Pack(google::protobuf::Message* msg,
|
||||
using MessageStruct = wpi_proto_ProtobufMecanumDriveWheelPositions;
|
||||
using InputStream = wpi::ProtoInputStream<frc::MecanumDriveWheelPositions>;
|
||||
using OutputStream = wpi::ProtoOutputStream<frc::MecanumDriveWheelPositions>;
|
||||
static std::optional<frc::MecanumDriveWheelPositions> Unpack(
|
||||
InputStream& stream);
|
||||
static bool Pack(OutputStream& stream,
|
||||
const frc::MecanumDriveWheelPositions& value);
|
||||
};
|
||||
|
||||
@@ -8,12 +8,15 @@
|
||||
#include <wpi/protobuf/Protobuf.h>
|
||||
|
||||
#include "frc/kinematics/MecanumDriveWheelSpeeds.h"
|
||||
#include "wpimath/protobuf/kinematics.npb.h"
|
||||
|
||||
template <>
|
||||
struct WPILIB_DLLEXPORT wpi::Protobuf<frc::MecanumDriveWheelSpeeds> {
|
||||
static google::protobuf::Message* New(google::protobuf::Arena* arena);
|
||||
static frc::MecanumDriveWheelSpeeds Unpack(
|
||||
const google::protobuf::Message& msg);
|
||||
static void Pack(google::protobuf::Message* msg,
|
||||
using MessageStruct = wpi_proto_ProtobufMecanumDriveWheelSpeeds;
|
||||
using InputStream = wpi::ProtoInputStream<frc::MecanumDriveWheelSpeeds>;
|
||||
using OutputStream = wpi::ProtoOutputStream<frc::MecanumDriveWheelSpeeds>;
|
||||
static std::optional<frc::MecanumDriveWheelSpeeds> Unpack(
|
||||
InputStream& stream);
|
||||
static bool Pack(OutputStream& stream,
|
||||
const frc::MecanumDriveWheelSpeeds& value);
|
||||
};
|
||||
|
||||
@@ -7,36 +7,40 @@
|
||||
#include <stdexcept>
|
||||
|
||||
#include <fmt/format.h>
|
||||
#include <wpi/ProtoHelper.h>
|
||||
#include <wpi/protobuf/Protobuf.h>
|
||||
#include <wpi/protobuf/ProtobufCallbacks.h>
|
||||
|
||||
#include "frc/kinematics/SwerveDriveKinematics.h"
|
||||
#include "kinematics.pb.h"
|
||||
#include "wpimath/protobuf/kinematics.npb.h"
|
||||
|
||||
template <size_t NumModules>
|
||||
struct wpi::Protobuf<frc::SwerveDriveKinematics<NumModules>> {
|
||||
static google::protobuf::Message* New(google::protobuf::Arena* arena) {
|
||||
return wpi::CreateMessage<wpi::proto::ProtobufSwerveDriveKinematics>(arena);
|
||||
}
|
||||
using MessageStruct = wpi_proto_ProtobufSwerveDriveKinematics;
|
||||
using InputStream =
|
||||
wpi::ProtoInputStream<frc::SwerveDriveKinematics<NumModules>>;
|
||||
using OutputStream =
|
||||
wpi::ProtoOutputStream<frc::SwerveDriveKinematics<NumModules>>;
|
||||
|
||||
static frc::SwerveDriveKinematics<NumModules> Unpack(
|
||||
const google::protobuf::Message& msg) {
|
||||
auto m =
|
||||
static_cast<const wpi::proto::ProtobufSwerveDriveKinematics*>(&msg);
|
||||
if (m->modules_size() != NumModules) {
|
||||
throw std::invalid_argument(fmt::format(
|
||||
"Tried to unpack message with {} elements in modules into "
|
||||
"SwerveDriveKinematics with {} modules",
|
||||
m->modules_size(), NumModules));
|
||||
static std::optional<frc::SwerveDriveKinematics<NumModules>> Unpack(
|
||||
InputStream& stream) {
|
||||
wpi::WpiArrayUnpackCallback<frc::Translation2d, NumModules> modules;
|
||||
wpi_proto_ProtobufSwerveDriveKinematics msg{
|
||||
.modules = modules.Callback(),
|
||||
};
|
||||
modules.SetLimits(wpi::DecodeLimits::Fail);
|
||||
if (!stream.Decode(msg)) {
|
||||
return {};
|
||||
}
|
||||
return frc::SwerveDriveKinematics<NumModules>{
|
||||
wpi::UnpackProtobufArray<wpi::proto::ProtobufTranslation2d,
|
||||
frc::Translation2d, NumModules>(m->modules())};
|
||||
|
||||
return frc::SwerveDriveKinematics<NumModules>{modules.Array()};
|
||||
}
|
||||
|
||||
static void Pack(google::protobuf::Message* msg,
|
||||
static bool Pack(OutputStream& stream,
|
||||
const frc::SwerveDriveKinematics<NumModules>& value) {
|
||||
auto m = static_cast<wpi::proto::ProtobufSwerveDriveKinematics*>(msg);
|
||||
wpi::PackProtobufArray(m->mutable_modules(), value.GetModules());
|
||||
wpi::PackCallback<frc::Translation2d> modules{value.GetModules()};
|
||||
wpi_proto_ProtobufSwerveDriveKinematics msg{
|
||||
.modules = modules.Callback(),
|
||||
};
|
||||
return stream.Encode(msg);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -8,11 +8,14 @@
|
||||
#include <wpi/protobuf/Protobuf.h>
|
||||
|
||||
#include "frc/kinematics/SwerveModulePosition.h"
|
||||
#include "wpimath/protobuf/kinematics.npb.h"
|
||||
|
||||
template <>
|
||||
struct WPILIB_DLLEXPORT wpi::Protobuf<frc::SwerveModulePosition> {
|
||||
static google::protobuf::Message* New(google::protobuf::Arena* arena);
|
||||
static frc::SwerveModulePosition Unpack(const google::protobuf::Message& msg);
|
||||
static void Pack(google::protobuf::Message* msg,
|
||||
using MessageStruct = wpi_proto_ProtobufSwerveModulePosition;
|
||||
using InputStream = wpi::ProtoInputStream<frc::SwerveModulePosition>;
|
||||
using OutputStream = wpi::ProtoOutputStream<frc::SwerveModulePosition>;
|
||||
static std::optional<frc::SwerveModulePosition> Unpack(InputStream& stream);
|
||||
static bool Pack(OutputStream& stream,
|
||||
const frc::SwerveModulePosition& value);
|
||||
};
|
||||
|
||||
@@ -8,11 +8,13 @@
|
||||
#include <wpi/protobuf/Protobuf.h>
|
||||
|
||||
#include "frc/kinematics/SwerveModuleState.h"
|
||||
#include "wpimath/protobuf/kinematics.npb.h"
|
||||
|
||||
template <>
|
||||
struct WPILIB_DLLEXPORT wpi::Protobuf<frc::SwerveModuleState> {
|
||||
static google::protobuf::Message* New(google::protobuf::Arena* arena);
|
||||
static frc::SwerveModuleState Unpack(const google::protobuf::Message& msg);
|
||||
static void Pack(google::protobuf::Message* msg,
|
||||
const frc::SwerveModuleState& value);
|
||||
using MessageStruct = wpi_proto_ProtobufSwerveModuleState;
|
||||
using InputStream = wpi::ProtoInputStream<frc::SwerveModuleState>;
|
||||
using OutputStream = wpi::ProtoOutputStream<frc::SwerveModuleState>;
|
||||
static std::optional<frc::SwerveModuleState> Unpack(InputStream& stream);
|
||||
static bool Pack(OutputStream& stream, const frc::SwerveModuleState& value);
|
||||
};
|
||||
|
||||
@@ -7,50 +7,65 @@
|
||||
#include <stdexcept>
|
||||
|
||||
#include <fmt/format.h>
|
||||
#include <wpi/ProtoHelper.h>
|
||||
#include <wpi/protobuf/Protobuf.h>
|
||||
#include <wpi/protobuf/ProtobufCallbacks.h>
|
||||
|
||||
#include "frc/EigenCore.h"
|
||||
#include "wpimath.pb.h"
|
||||
#include "wpimath/protobuf/wpimath.npb.h"
|
||||
|
||||
template <int Rows, int Cols, int Options, int MaxRows, int MaxCols>
|
||||
requires(Cols != 1)
|
||||
struct wpi::Protobuf<frc::Matrixd<Rows, Cols, Options, MaxRows, MaxCols>> {
|
||||
static google::protobuf::Message* New(google::protobuf::Arena* arena) {
|
||||
return wpi::CreateMessage<wpi::proto::ProtobufMatrix>(arena);
|
||||
}
|
||||
using MessageStruct = wpi_proto_ProtobufMatrix;
|
||||
using InputStream = wpi::ProtoInputStream<
|
||||
frc::Matrixd<Rows, Cols, Options, MaxRows, MaxCols>>;
|
||||
using OutputStream = wpi::ProtoOutputStream<
|
||||
frc::Matrixd<Rows, Cols, Options, MaxRows, MaxCols>>;
|
||||
|
||||
static frc::Matrixd<Rows, Cols, Options, MaxRows, MaxCols> Unpack(
|
||||
const google::protobuf::Message& msg) {
|
||||
auto m = static_cast<const wpi::proto::ProtobufMatrix*>(&msg);
|
||||
if (m->num_rows() != Rows || m->num_cols() != Cols) {
|
||||
throw std::invalid_argument(fmt::format(
|
||||
"Tried to unpack message with {} rows and {} columns into "
|
||||
"Matrix with {} rows and {} columns",
|
||||
m->num_rows(), m->num_cols(), Rows, Cols));
|
||||
static std::optional<frc::Matrixd<Rows, Cols, Options, MaxRows, MaxCols>>
|
||||
Unpack(InputStream& stream) {
|
||||
constexpr bool isSmall = Rows * Cols * sizeof(double) < 256;
|
||||
using UnpackType =
|
||||
std::conditional_t<isSmall, wpi::UnpackCallback<double, Rows * Cols>,
|
||||
wpi::StdVectorUnpackCallback<double, Rows * Cols>>;
|
||||
UnpackType data;
|
||||
data.Vec().reserve(Rows * Cols);
|
||||
data.SetLimits(wpi::DecodeLimits::Fail);
|
||||
wpi_proto_ProtobufMatrix msg;
|
||||
msg.data = data.Callback();
|
||||
if (!stream.Decode(msg)) {
|
||||
return {};
|
||||
}
|
||||
if (m->data_size() != Rows * Cols) {
|
||||
throw std::invalid_argument(
|
||||
fmt::format("Tried to unpack message with {} elements in data into "
|
||||
"Matrix with {} elements",
|
||||
m->data_size(), Rows * Cols));
|
||||
|
||||
if (msg.num_rows != Rows || msg.num_cols != Cols) {
|
||||
return {};
|
||||
}
|
||||
|
||||
auto items = data.Items();
|
||||
|
||||
if (items.size() != Rows * Cols) {
|
||||
return {};
|
||||
}
|
||||
|
||||
frc::Matrixd<Rows, Cols, Options, MaxRows, MaxCols> mat;
|
||||
for (int i = 0; i < Rows * Cols; i++) {
|
||||
mat(i) = m->data(i);
|
||||
mat(i) = items[i];
|
||||
}
|
||||
|
||||
return mat;
|
||||
}
|
||||
|
||||
static void Pack(
|
||||
google::protobuf::Message* msg,
|
||||
static bool Pack(
|
||||
OutputStream& stream,
|
||||
const frc::Matrixd<Rows, Cols, Options, MaxRows, MaxCols>& value) {
|
||||
auto m = static_cast<wpi::proto::ProtobufMatrix*>(msg);
|
||||
m->set_num_rows(Rows);
|
||||
m->set_num_cols(Cols);
|
||||
m->clear_data();
|
||||
for (int i = 0; i < Rows * Cols; i++) {
|
||||
m->add_data(value(i));
|
||||
}
|
||||
std::span<const double> dataSpan{value.data(),
|
||||
static_cast<size_t>(Rows * Cols)};
|
||||
wpi::PackCallback<double> data{dataSpan};
|
||||
wpi_proto_ProtobufMatrix msg{
|
||||
.num_rows = Rows,
|
||||
.num_cols = Cols,
|
||||
.data = data.Callback(),
|
||||
};
|
||||
return stream.Encode(msg);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -7,41 +7,58 @@
|
||||
#include <stdexcept>
|
||||
|
||||
#include <fmt/format.h>
|
||||
#include <wpi/ProtoHelper.h>
|
||||
#include <wpi/protobuf/Protobuf.h>
|
||||
#include <wpi/protobuf/ProtobufCallbacks.h>
|
||||
|
||||
#include "frc/EigenCore.h"
|
||||
#include "wpimath.pb.h"
|
||||
#include "wpimath/protobuf/wpimath.npb.h"
|
||||
|
||||
template <int Size, int Options, int MaxRows, int MaxCols>
|
||||
struct wpi::Protobuf<frc::Matrixd<Size, 1, Options, MaxRows, MaxCols>> {
|
||||
static google::protobuf::Message* New(google::protobuf::Arena* arena) {
|
||||
return wpi::CreateMessage<wpi::proto::ProtobufVector>(arena);
|
||||
}
|
||||
using MessageStruct = wpi_proto_ProtobufVector;
|
||||
using InputStream =
|
||||
wpi::ProtoInputStream<frc::Matrixd<Size, 1, Options, MaxRows, MaxCols>>;
|
||||
using OutputStream =
|
||||
wpi::ProtoOutputStream<frc::Matrixd<Size, 1, Options, MaxRows, MaxCols>>;
|
||||
|
||||
static frc::Matrixd<Size, 1, Options, MaxRows, MaxCols> Unpack(
|
||||
const google::protobuf::Message& msg) {
|
||||
auto m = static_cast<const wpi::proto::ProtobufVector*>(&msg);
|
||||
if (m->rows_size() != Size) {
|
||||
throw std::invalid_argument(
|
||||
fmt::format("Tried to unpack message with {} elements in rows into "
|
||||
"Vector with {} rows",
|
||||
m->rows_size(), Size));
|
||||
static std::optional<frc::Matrixd<Size, 1, Options, MaxRows, MaxCols>> Unpack(
|
||||
InputStream& stream) {
|
||||
constexpr bool isSmall = Size * sizeof(double) < 256;
|
||||
using UnpackType =
|
||||
std::conditional_t<isSmall, wpi::UnpackCallback<double, Size>,
|
||||
wpi::StdVectorUnpackCallback<double, Size>>;
|
||||
UnpackType rows;
|
||||
rows.Vec().reserve(Size);
|
||||
rows.SetLimits(wpi::DecodeLimits::Fail);
|
||||
wpi_proto_ProtobufVector msg{
|
||||
.rows = rows.Callback(),
|
||||
};
|
||||
if (!stream.Decode(msg)) {
|
||||
return {};
|
||||
}
|
||||
frc::Matrixd<Size, 1, Options, MaxRows, MaxCols> vec;
|
||||
|
||||
auto items = rows.Items();
|
||||
|
||||
if (items.size() != Size) {
|
||||
return {};
|
||||
}
|
||||
|
||||
frc::Matrixd<Size, 1, Options, MaxRows, MaxCols> mat;
|
||||
for (int i = 0; i < Size; i++) {
|
||||
vec(i) = m->rows(i);
|
||||
mat(i) = items[i];
|
||||
}
|
||||
return vec;
|
||||
|
||||
return mat;
|
||||
}
|
||||
|
||||
static void Pack(
|
||||
google::protobuf::Message* msg,
|
||||
static bool Pack(
|
||||
OutputStream& stream,
|
||||
const frc::Matrixd<Size, 1, Options, MaxRows, MaxCols>& value) {
|
||||
auto m = static_cast<wpi::proto::ProtobufVector*>(msg);
|
||||
m->clear_rows();
|
||||
for (int i = 0; i < Size; i++) {
|
||||
m->add_rows(value(i));
|
||||
}
|
||||
std::span<const double> rowsSpan{value.data(), static_cast<size_t>(Size)};
|
||||
wpi::PackCallback<double> rows{rowsSpan};
|
||||
wpi_proto_ProtobufVector msg{
|
||||
.rows = rows.Callback(),
|
||||
};
|
||||
return stream.Encode(msg);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -8,11 +8,13 @@
|
||||
#include <wpi/protobuf/Protobuf.h>
|
||||
|
||||
#include "frc/spline/CubicHermiteSpline.h"
|
||||
#include "wpimath/protobuf/spline.npb.h"
|
||||
|
||||
template <>
|
||||
struct WPILIB_DLLEXPORT wpi::Protobuf<frc::CubicHermiteSpline> {
|
||||
static google::protobuf::Message* New(google::protobuf::Arena* arena);
|
||||
static frc::CubicHermiteSpline Unpack(const google::protobuf::Message& msg);
|
||||
static void Pack(google::protobuf::Message* msg,
|
||||
const frc::CubicHermiteSpline& value);
|
||||
using MessageStruct = wpi_proto_ProtobufCubicHermiteSpline;
|
||||
using InputStream = wpi::ProtoInputStream<frc::CubicHermiteSpline>;
|
||||
using OutputStream = wpi::ProtoOutputStream<frc::CubicHermiteSpline>;
|
||||
static std::optional<frc::CubicHermiteSpline> Unpack(InputStream& stream);
|
||||
static bool Pack(OutputStream& stream, const frc::CubicHermiteSpline& value);
|
||||
};
|
||||
|
||||
@@ -8,11 +8,14 @@
|
||||
#include <wpi/protobuf/Protobuf.h>
|
||||
|
||||
#include "frc/spline/QuinticHermiteSpline.h"
|
||||
#include "wpimath/protobuf/spline.npb.h"
|
||||
|
||||
template <>
|
||||
struct WPILIB_DLLEXPORT wpi::Protobuf<frc::QuinticHermiteSpline> {
|
||||
static google::protobuf::Message* New(google::protobuf::Arena* arena);
|
||||
static frc::QuinticHermiteSpline Unpack(const google::protobuf::Message& msg);
|
||||
static void Pack(google::protobuf::Message* msg,
|
||||
using MessageStruct = wpi_proto_ProtobufQuinticHermiteSpline;
|
||||
using InputStream = wpi::ProtoInputStream<frc::QuinticHermiteSpline>;
|
||||
using OutputStream = wpi::ProtoOutputStream<frc::QuinticHermiteSpline>;
|
||||
static std::optional<frc::QuinticHermiteSpline> Unpack(InputStream& stream);
|
||||
static bool Pack(OutputStream& stream,
|
||||
const frc::QuinticHermiteSpline& value);
|
||||
};
|
||||
|
||||
@@ -8,10 +8,13 @@
|
||||
#include <wpi/protobuf/Protobuf.h>
|
||||
|
||||
#include "frc/system/plant/DCMotor.h"
|
||||
#include "wpimath/protobuf/plant.npb.h"
|
||||
|
||||
template <>
|
||||
struct WPILIB_DLLEXPORT wpi::Protobuf<frc::DCMotor> {
|
||||
static google::protobuf::Message* New(google::protobuf::Arena* arena);
|
||||
static frc::DCMotor Unpack(const google::protobuf::Message& msg);
|
||||
static void Pack(google::protobuf::Message* msg, const frc::DCMotor& value);
|
||||
using MessageStruct = wpi_proto_ProtobufDCMotor;
|
||||
using InputStream = wpi::ProtoInputStream<frc::DCMotor>;
|
||||
using OutputStream = wpi::ProtoOutputStream<frc::DCMotor>;
|
||||
static std::optional<frc::DCMotor> Unpack(InputStream& stream);
|
||||
static bool Pack(OutputStream& stream, const frc::DCMotor& value);
|
||||
};
|
||||
|
||||
@@ -5,48 +5,84 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdexcept>
|
||||
#include <utility>
|
||||
|
||||
#include <fmt/format.h>
|
||||
#include <wpi/ProtoHelper.h>
|
||||
#include <wpi/protobuf/Protobuf.h>
|
||||
#include <wpi/protobuf/ProtobufCallbacks.h>
|
||||
|
||||
#include "frc/proto/MatrixProto.h"
|
||||
#include "frc/system/LinearSystem.h"
|
||||
#include "system.pb.h"
|
||||
#include "wpimath/protobuf/system.npb.h"
|
||||
|
||||
template <int States, int Inputs, int Outputs>
|
||||
struct wpi::Protobuf<frc::LinearSystem<States, Inputs, Outputs>> {
|
||||
static google::protobuf::Message* New(google::protobuf::Arena* arena) {
|
||||
return wpi::CreateMessage<wpi::proto::ProtobufLinearSystem>(arena);
|
||||
}
|
||||
using MessageStruct = wpi_proto_ProtobufLinearSystem;
|
||||
using InputStream =
|
||||
wpi::ProtoInputStream<frc::LinearSystem<States, Inputs, Outputs>>;
|
||||
using OutputStream =
|
||||
wpi::ProtoOutputStream<frc::LinearSystem<States, Inputs, Outputs>>;
|
||||
|
||||
static frc::LinearSystem<States, Inputs, Outputs> Unpack(
|
||||
const google::protobuf::Message& msg) {
|
||||
auto m = static_cast<const wpi::proto::ProtobufLinearSystem*>(&msg);
|
||||
if (m->num_states() != States || m->num_inputs() != Inputs ||
|
||||
m->num_outputs() != Outputs) {
|
||||
throw std::invalid_argument(fmt::format(
|
||||
"Tried to unpack message with {} states and {} inputs and {} outputs "
|
||||
"into LinearSystem with {} states and {} inputs and {} outputs",
|
||||
m->num_states(), m->num_inputs(), m->num_outputs(), States, Inputs,
|
||||
Outputs));
|
||||
static std::optional<frc::LinearSystem<States, Inputs, Outputs>> Unpack(
|
||||
InputStream& stream) {
|
||||
wpi::UnpackCallback<frc::Matrixd<States, States>> a;
|
||||
a.SetLimits(wpi::DecodeLimits::Fail);
|
||||
wpi::UnpackCallback<frc::Matrixd<States, Inputs>> b;
|
||||
a.SetLimits(wpi::DecodeLimits::Fail);
|
||||
wpi::UnpackCallback<frc::Matrixd<Outputs, States>> c;
|
||||
a.SetLimits(wpi::DecodeLimits::Fail);
|
||||
wpi::UnpackCallback<frc::Matrixd<Outputs, Inputs>> d;
|
||||
a.SetLimits(wpi::DecodeLimits::Fail);
|
||||
|
||||
wpi_proto_ProtobufLinearSystem msg;
|
||||
msg.a = a.Callback();
|
||||
msg.b = b.Callback();
|
||||
msg.c = c.Callback();
|
||||
msg.d = d.Callback();
|
||||
|
||||
if (!stream.Decode(msg)) {
|
||||
return {};
|
||||
}
|
||||
|
||||
if (msg.num_inputs != Inputs || msg.num_outputs != Outputs ||
|
||||
msg.num_states != States) {
|
||||
return {};
|
||||
}
|
||||
|
||||
auto ai = a.Items();
|
||||
auto bi = b.Items();
|
||||
auto ci = c.Items();
|
||||
auto di = d.Items();
|
||||
|
||||
if (ai.empty() || bi.empty() || ci.empty() || di.empty()) {
|
||||
return {};
|
||||
}
|
||||
|
||||
return frc::LinearSystem<States, Inputs, Outputs>{
|
||||
wpi::UnpackProtobuf<frc::Matrixd<States, States>>(m->wpi_a()),
|
||||
wpi::UnpackProtobuf<frc::Matrixd<States, Inputs>>(m->wpi_b()),
|
||||
wpi::UnpackProtobuf<frc::Matrixd<Outputs, States>>(m->wpi_c()),
|
||||
wpi::UnpackProtobuf<frc::Matrixd<Outputs, Inputs>>(m->wpi_d())};
|
||||
std::move(ai[0]),
|
||||
std::move(bi[0]),
|
||||
std::move(ci[0]),
|
||||
std::move(di[0]),
|
||||
};
|
||||
}
|
||||
|
||||
static void Pack(google::protobuf::Message* msg,
|
||||
static bool Pack(OutputStream& stream,
|
||||
const frc::LinearSystem<States, Inputs, Outputs>& value) {
|
||||
auto m = static_cast<wpi::proto::ProtobufLinearSystem*>(msg);
|
||||
m->set_num_states(States);
|
||||
m->set_num_inputs(Inputs);
|
||||
m->set_num_outputs(Outputs);
|
||||
wpi::PackProtobuf(m->mutable_a(), value.A());
|
||||
wpi::PackProtobuf(m->mutable_b(), value.B());
|
||||
wpi::PackProtobuf(m->mutable_c(), value.C());
|
||||
wpi::PackProtobuf(m->mutable_d(), value.D());
|
||||
wpi::PackCallback a{&value.A()};
|
||||
wpi::PackCallback b{&value.B()};
|
||||
wpi::PackCallback c{&value.C()};
|
||||
wpi::PackCallback d{&value.D()};
|
||||
|
||||
wpi_proto_ProtobufLinearSystem msg{
|
||||
.num_states = States,
|
||||
.num_inputs = Inputs,
|
||||
.num_outputs = Outputs,
|
||||
.a = a.Callback(),
|
||||
.b = b.Callback(),
|
||||
.c = c.Callback(),
|
||||
.d = d.Callback(),
|
||||
};
|
||||
|
||||
return stream.Encode(msg);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -8,11 +8,13 @@
|
||||
#include <wpi/protobuf/Protobuf.h>
|
||||
|
||||
#include "frc/trajectory/Trajectory.h"
|
||||
#include "wpimath/protobuf/trajectory.npb.h"
|
||||
|
||||
template <>
|
||||
struct WPILIB_DLLEXPORT wpi::Protobuf<frc::Trajectory> {
|
||||
static google::protobuf::Message* New(google::protobuf::Arena* arena);
|
||||
static frc::Trajectory Unpack(const google::protobuf::Message& msg);
|
||||
static void Pack(google::protobuf::Message* msg,
|
||||
const frc::Trajectory& value);
|
||||
using MessageStruct = wpi_proto_ProtobufTrajectory;
|
||||
using InputStream = wpi::ProtoInputStream<frc::Trajectory>;
|
||||
using OutputStream = wpi::ProtoOutputStream<frc::Trajectory>;
|
||||
static std::optional<frc::Trajectory> Unpack(InputStream& stream);
|
||||
static bool Pack(OutputStream& stream, const frc::Trajectory& value);
|
||||
};
|
||||
|
||||
@@ -8,11 +8,13 @@
|
||||
#include <wpi/protobuf/Protobuf.h>
|
||||
|
||||
#include "frc/trajectory/Trajectory.h"
|
||||
#include "wpimath/protobuf/trajectory.npb.h"
|
||||
|
||||
template <>
|
||||
struct WPILIB_DLLEXPORT wpi::Protobuf<frc::Trajectory::State> {
|
||||
static google::protobuf::Message* New(google::protobuf::Arena* arena);
|
||||
static frc::Trajectory::State Unpack(const google::protobuf::Message& msg);
|
||||
static void Pack(google::protobuf::Message* msg,
|
||||
const frc::Trajectory::State& value);
|
||||
using MessageStruct = wpi_proto_ProtobufTrajectoryState;
|
||||
using InputStream = wpi::ProtoInputStream<frc::Trajectory::State>;
|
||||
using OutputStream = wpi::ProtoOutputStream<frc::Trajectory::State>;
|
||||
static std::optional<frc::Trajectory::State> Unpack(InputStream& stream);
|
||||
static bool Pack(OutputStream& stream, const frc::Trajectory::State& value);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user