mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-25 01:41: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,31 @@
|
||||
// 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/kinematics/proto/ChassisSpeedsProto.h"
|
||||
|
||||
#include "kinematics.pb.h"
|
||||
|
||||
google::protobuf::Message* wpi::Protobuf<frc::ChassisSpeeds>::New(
|
||||
google::protobuf::Arena* arena) {
|
||||
return google::protobuf::Arena::CreateMessage<
|
||||
wpi::proto::ProtobufChassisSpeeds>(arena);
|
||||
}
|
||||
|
||||
frc::ChassisSpeeds wpi::Protobuf<frc::ChassisSpeeds>::Unpack(
|
||||
const google::protobuf::Message& msg) {
|
||||
auto m = static_cast<const wpi::proto::ProtobufChassisSpeeds*>(&msg);
|
||||
return frc::ChassisSpeeds{
|
||||
units::meters_per_second_t{m->vx()},
|
||||
units::meters_per_second_t{m->vy()},
|
||||
units::radians_per_second_t{m->omega()},
|
||||
};
|
||||
}
|
||||
|
||||
void wpi::Protobuf<frc::ChassisSpeeds>::Pack(google::protobuf::Message* msg,
|
||||
const frc::ChassisSpeeds& value) {
|
||||
auto m = static_cast<wpi::proto::ProtobufChassisSpeeds*>(msg);
|
||||
m->set_vx(value.vx.value());
|
||||
m->set_vy(value.vy.value());
|
||||
m->set_omega(value.omega.value());
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
// 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/kinematics/proto/DifferentialDriveKinematicsProto.h"
|
||||
|
||||
#include "kinematics.pb.h"
|
||||
|
||||
google::protobuf::Message* wpi::Protobuf<frc::DifferentialDriveKinematics>::New(
|
||||
google::protobuf::Arena* arena) {
|
||||
return google::protobuf::Arena::CreateMessage<
|
||||
wpi::proto::ProtobufDifferentialDriveKinematics>(arena);
|
||||
}
|
||||
|
||||
frc::DifferentialDriveKinematics
|
||||
wpi::Protobuf<frc::DifferentialDriveKinematics>::Unpack(
|
||||
const google::protobuf::Message& msg) {
|
||||
auto m =
|
||||
static_cast<const wpi::proto::ProtobufDifferentialDriveKinematics*>(&msg);
|
||||
return frc::DifferentialDriveKinematics{
|
||||
units::meter_t{m->track_width()},
|
||||
};
|
||||
}
|
||||
|
||||
void wpi::Protobuf<frc::DifferentialDriveKinematics>::Pack(
|
||||
google::protobuf::Message* msg,
|
||||
const frc::DifferentialDriveKinematics& value) {
|
||||
auto m = static_cast<wpi::proto::ProtobufDifferentialDriveKinematics*>(msg);
|
||||
m->set_track_width(value.trackWidth.value());
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
// 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/kinematics/proto/DifferentialDriveWheelSpeedsProto.h"
|
||||
|
||||
#include "kinematics.pb.h"
|
||||
|
||||
google::protobuf::Message* wpi::Protobuf<
|
||||
frc::DifferentialDriveWheelSpeeds>::New(google::protobuf::Arena* arena) {
|
||||
return google::protobuf::Arena::CreateMessage<
|
||||
wpi::proto::ProtobufDifferentialDriveWheelSpeeds>(arena);
|
||||
}
|
||||
|
||||
frc::DifferentialDriveWheelSpeeds
|
||||
wpi::Protobuf<frc::DifferentialDriveWheelSpeeds>::Unpack(
|
||||
const google::protobuf::Message& msg) {
|
||||
auto m = static_cast<const wpi::proto::ProtobufDifferentialDriveWheelSpeeds*>(
|
||||
&msg);
|
||||
return frc::DifferentialDriveWheelSpeeds{
|
||||
units::meters_per_second_t{m->left()},
|
||||
units::meters_per_second_t{m->right()},
|
||||
};
|
||||
}
|
||||
|
||||
void wpi::Protobuf<frc::DifferentialDriveWheelSpeeds>::Pack(
|
||||
google::protobuf::Message* msg,
|
||||
const frc::DifferentialDriveWheelSpeeds& value) {
|
||||
auto m = static_cast<wpi::proto::ProtobufDifferentialDriveWheelSpeeds*>(msg);
|
||||
m->set_left(value.left.value());
|
||||
m->set_right(value.right.value());
|
||||
}
|
||||
@@ -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/kinematics/proto/MecanumDriveKinematicsProto.h"
|
||||
|
||||
#include "kinematics.pb.h"
|
||||
|
||||
google::protobuf::Message* wpi::Protobuf<frc::MecanumDriveKinematics>::New(
|
||||
google::protobuf::Arena* arena) {
|
||||
return google::protobuf::Arena::CreateMessage<
|
||||
wpi::proto::ProtobufMecanumDriveKinematics>(arena);
|
||||
}
|
||||
|
||||
frc::MecanumDriveKinematics wpi::Protobuf<frc::MecanumDriveKinematics>::Unpack(
|
||||
const google::protobuf::Message& msg) {
|
||||
auto m = static_cast<const wpi::proto::ProtobufMecanumDriveKinematics*>(&msg);
|
||||
return frc::MecanumDriveKinematics{
|
||||
wpi::UnpackProtobuf<frc::Translation2d>(m->front_left()),
|
||||
wpi::UnpackProtobuf<frc::Translation2d>(m->front_right()),
|
||||
wpi::UnpackProtobuf<frc::Translation2d>(m->rear_left()),
|
||||
wpi::UnpackProtobuf<frc::Translation2d>(m->rear_right()),
|
||||
};
|
||||
}
|
||||
|
||||
void wpi::Protobuf<frc::MecanumDriveKinematics>::Pack(
|
||||
google::protobuf::Message* msg, const frc::MecanumDriveKinematics& value) {
|
||||
auto m = static_cast<wpi::proto::ProtobufMecanumDriveKinematics*>(msg);
|
||||
wpi::PackProtobuf(m->mutable_front_left(), value.GetFrontLeftWheel());
|
||||
wpi::PackProtobuf(m->mutable_front_right(), value.GetFrontRightWheel());
|
||||
wpi::PackProtobuf(m->mutable_rear_left(), value.GetRearLeftWheel());
|
||||
wpi::PackProtobuf(m->mutable_rear_right(), value.GetRearRightWheel());
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
// 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/kinematics/proto/MecanumDriveWheelPositionsProto.h"
|
||||
|
||||
#include "kinematics.pb.h"
|
||||
|
||||
google::protobuf::Message* wpi::Protobuf<frc::MecanumDriveWheelPositions>::New(
|
||||
google::protobuf::Arena* arena) {
|
||||
return google::protobuf::Arena::CreateMessage<
|
||||
wpi::proto::ProtobufMecanumDriveWheelPositions>(arena);
|
||||
}
|
||||
|
||||
frc::MecanumDriveWheelPositions
|
||||
wpi::Protobuf<frc::MecanumDriveWheelPositions>::Unpack(
|
||||
const google::protobuf::Message& msg) {
|
||||
auto m =
|
||||
static_cast<const wpi::proto::ProtobufMecanumDriveWheelPositions*>(&msg);
|
||||
return frc::MecanumDriveWheelPositions{
|
||||
units::meter_t{m->front_left()},
|
||||
units::meter_t{m->front_right()},
|
||||
units::meter_t{m->rear_left()},
|
||||
units::meter_t{m->rear_right()},
|
||||
};
|
||||
}
|
||||
|
||||
void wpi::Protobuf<frc::MecanumDriveWheelPositions>::Pack(
|
||||
google::protobuf::Message* msg,
|
||||
const frc::MecanumDriveWheelPositions& value) {
|
||||
auto m = static_cast<wpi::proto::ProtobufMecanumDriveWheelPositions*>(msg);
|
||||
m->set_front_left(value.frontLeft.value());
|
||||
m->set_front_right(value.frontRight.value());
|
||||
m->set_rear_left(value.rearLeft.value());
|
||||
m->set_rear_right(value.rearRight.value());
|
||||
}
|
||||
@@ -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 "frc/kinematics/proto/MecanumDriveWheelSpeedsProto.h"
|
||||
|
||||
#include "kinematics.pb.h"
|
||||
|
||||
google::protobuf::Message* wpi::Protobuf<frc::MecanumDriveWheelSpeeds>::New(
|
||||
google::protobuf::Arena* arena) {
|
||||
return google::protobuf::Arena::CreateMessage<
|
||||
wpi::proto::ProtobufMecanumDriveWheelSpeeds>(arena);
|
||||
}
|
||||
|
||||
frc::MecanumDriveWheelSpeeds
|
||||
wpi::Protobuf<frc::MecanumDriveWheelSpeeds>::Unpack(
|
||||
const google::protobuf::Message& msg) {
|
||||
auto m =
|
||||
static_cast<const wpi::proto::ProtobufMecanumDriveWheelSpeeds*>(&msg);
|
||||
return frc::MecanumDriveWheelSpeeds{
|
||||
units::meters_per_second_t{m->front_left()},
|
||||
units::meters_per_second_t{m->front_right()},
|
||||
units::meters_per_second_t{m->rear_left()},
|
||||
units::meters_per_second_t{m->rear_right()},
|
||||
};
|
||||
}
|
||||
|
||||
void wpi::Protobuf<frc::MecanumDriveWheelSpeeds>::Pack(
|
||||
google::protobuf::Message* msg, const frc::MecanumDriveWheelSpeeds& value) {
|
||||
auto m = static_cast<wpi::proto::ProtobufMecanumDriveWheelSpeeds*>(msg);
|
||||
m->set_front_left(value.frontLeft.value());
|
||||
m->set_front_right(value.frontRight.value());
|
||||
m->set_rear_left(value.rearLeft.value());
|
||||
m->set_rear_right(value.rearRight.value());
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
// 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/kinematics/proto/SwerveModulePositionProto.h"
|
||||
|
||||
#include "kinematics.pb.h"
|
||||
|
||||
google::protobuf::Message* wpi::Protobuf<frc::SwerveModulePosition>::New(
|
||||
google::protobuf::Arena* arena) {
|
||||
return google::protobuf::Arena::CreateMessage<
|
||||
wpi::proto::ProtobufSwerveModulePosition>(arena);
|
||||
}
|
||||
|
||||
frc::SwerveModulePosition wpi::Protobuf<frc::SwerveModulePosition>::Unpack(
|
||||
const google::protobuf::Message& msg) {
|
||||
auto m = static_cast<const wpi::proto::ProtobufSwerveModulePosition*>(&msg);
|
||||
return frc::SwerveModulePosition{
|
||||
units::meter_t{m->distance()},
|
||||
wpi::UnpackProtobuf<frc::Rotation2d>(m->angle()),
|
||||
};
|
||||
}
|
||||
|
||||
void wpi::Protobuf<frc::SwerveModulePosition>::Pack(
|
||||
google::protobuf::Message* msg, const frc::SwerveModulePosition& value) {
|
||||
auto m = static_cast<wpi::proto::ProtobufSwerveModulePosition*>(msg);
|
||||
m->set_distance(value.distance.value());
|
||||
wpi::PackProtobuf(m->mutable_angle(), value.angle);
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
// 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/kinematics/proto/SwerveModuleStateProto.h"
|
||||
|
||||
#include "kinematics.pb.h"
|
||||
|
||||
google::protobuf::Message* wpi::Protobuf<frc::SwerveModuleState>::New(
|
||||
google::protobuf::Arena* arena) {
|
||||
return google::protobuf::Arena::CreateMessage<
|
||||
wpi::proto::ProtobufSwerveModuleState>(arena);
|
||||
}
|
||||
|
||||
frc::SwerveModuleState wpi::Protobuf<frc::SwerveModuleState>::Unpack(
|
||||
const google::protobuf::Message& msg) {
|
||||
auto m = static_cast<const wpi::proto::ProtobufSwerveModuleState*>(&msg);
|
||||
return frc::SwerveModuleState{
|
||||
units::meters_per_second_t{m->speed()},
|
||||
wpi::UnpackProtobuf<frc::Rotation2d>(m->angle()),
|
||||
};
|
||||
}
|
||||
|
||||
void wpi::Protobuf<frc::SwerveModuleState>::Pack(
|
||||
google::protobuf::Message* msg, const frc::SwerveModuleState& value) {
|
||||
auto m = static_cast<wpi::proto::ProtobufSwerveModuleState*>(msg);
|
||||
m->set_speed(value.speed.value());
|
||||
wpi::PackProtobuf(m->mutable_angle(), value.angle);
|
||||
}
|
||||
Reference in New Issue
Block a user