[wpiutil, ntcore] Add structured data support (#5391)

This adds support for two serialization formats for complex data types:

- Protobuf for complex objects with variable length internals that need forward and backward wire compatibility (lower speed, more flexible)
- Raw struct (ByteBuffer-style) for fixed-length objects (higher speed, less flexible)

Deserialization can be done either by creating a new object (for immutable objects) or overwriting the contents of an existing object (for mutable objects).

Implementing classes should provide inner classes that implement the Protobuf or Struct interface (in Java) or specialize the wpi::Protobuf or wpi::Struct struct (in C++). It is possible for classes to implement both. If the class itself does not implement serialization, it's possible for third parties/users to provide an implementation instead.

Uses the Google protobuf implementation for C++ and the QuickBuffers alternative protobuf implementation for Java.
This commit is contained in:
Peter Johnson
2023-10-19 21:41:47 -07:00
committed by GitHub
parent ecb7cfa9ef
commit cf54d9ccb7
133 changed files with 13506 additions and 90 deletions

View File

@@ -0,0 +1,37 @@
syntax = "proto3";
package wpi.proto;
option java_package = "edu.wpi.first.math.proto";
message ProtobufArmFeedforward {
double ks = 1;
double kg = 2;
double kv = 3;
double ka = 4;
}
message ProtobufDifferentialDriveFeedforward {
double kv_linear = 1;
double ka_linear = 2;
double kv_angular = 3;
double ka_angular = 4;
}
message ProtobufElevatorFeedforward {
double ks = 1;
double kg = 2;
double kv = 3;
double ka = 4;
}
message ProtobufSimpleMotorFeedforward {
double ks = 1;
double kv = 2;
double ka = 3;
}
message ProtobufDifferentialDriveWheelVoltages {
double left = 1;
double right = 2;
}

View File

@@ -0,0 +1,30 @@
syntax = "proto3";
package wpi.proto;
option java_package = "edu.wpi.first.math.proto";
message ProtobufTranslation2d {
double x = 1;
double y = 2;
}
message ProtobufRotation2d {
double value = 1;
}
message ProtobufPose2d {
ProtobufTranslation2d translation = 1;
ProtobufRotation2d rotation = 2;
}
message ProtobufTransform2d {
ProtobufTranslation2d translation = 1;
ProtobufRotation2d rotation = 2;
}
message ProtobufTwist2d {
double dx = 1;
double dy = 2;
double dtheta = 3;
}

View File

@@ -0,0 +1,41 @@
syntax = "proto3";
package wpi.proto;
option java_package = "edu.wpi.first.math.proto";
message ProtobufTranslation3d {
double x = 1;
double y = 2;
double z = 3;
}
message ProtobufQuaternion {
double w = 1;
double x = 2;
double y = 3;
double z = 4;
}
message ProtobufRotation3d {
ProtobufQuaternion q = 1;
}
message ProtobufPose3d {
ProtobufTranslation3d translation = 1;
ProtobufRotation3d rotation = 2;
}
message ProtobufTransform3d {
ProtobufTranslation3d translation = 1;
ProtobufRotation3d rotation = 2;
}
message ProtobufTwist3d {
double dx = 1;
double dy = 2;
double dz = 3;
double rx = 4;
double ry = 5;
double rz = 6;
}

View File

@@ -0,0 +1,64 @@
syntax = "proto3";
package wpi.proto;
import "geometry2d.proto";
option java_package = "edu.wpi.first.math.proto";
message ProtobufChassisSpeeds {
double vx = 1;
double vy = 2;
double omega = 3;
}
message ProtobufDifferentialDriveKinematics {
double track_width = 1;
}
message ProtobufDifferentialDriveWheelSpeeds {
double left = 1;
double right = 2;
}
message ProtobufMecanumDriveKinematics {
ProtobufTranslation2d front_left = 1;
ProtobufTranslation2d front_right = 2;
ProtobufTranslation2d rear_left = 3;
ProtobufTranslation2d rear_right = 4;
}
message ProtobufMecanumDriveMotorVoltages {
double front_left = 1;
double front_right = 2;
double rear_left = 3;
double rear_right = 4;
}
message ProtobufMecanumDriveWheelPositions {
double front_left = 1;
double front_right = 2;
double rear_left = 3;
double rear_right = 4;
}
message ProtobufMecanumDriveWheelSpeeds {
double front_left = 1;
double front_right = 2;
double rear_left = 3;
double rear_right = 4;
}
message ProtobufSwerveDriveKinematics {
repeated ProtobufTranslation2d modules = 1;
}
message ProtobufSwerveModulePosition {
double distance = 1;
ProtobufRotation2d angle = 2;
}
message ProtobufSwerveModuleState {
double speed = 1;
ProtobufRotation2d angle = 2;
}

View File

@@ -0,0 +1,16 @@
syntax = "proto3";
package wpi.proto;
option java_package = "edu.wpi.first.math.proto";
message ProtobufDCMotor {
double nominal_voltage = 1;
double stall_torque = 2;
double stall_current = 3;
double free_current = 4;
double free_speed = 5;
double r = 6;
double kv = 7;
double kt = 8;
}

View File

@@ -0,0 +1,19 @@
syntax = "proto3";
package wpi.proto;
option java_package = "edu.wpi.first.math.proto";
message ProtobufCubicHermiteSpline {
repeated double x_initial = 1;
repeated double x_final = 2;
repeated double y_initial = 3;
repeated double y_final = 4;
}
message ProtobufQuinticHermiteSpline {
repeated double x_initial = 1;
repeated double x_final = 2;
repeated double y_initial = 3;
repeated double y_final = 4;
}

View File

@@ -0,0 +1,17 @@
syntax = "proto3";
package wpi.proto;
import "wpimath.proto";
option java_package = "edu.wpi.first.math.proto";
message ProtobufLinearSystem {
uint32 num_states = 1;
uint32 num_inputs = 2;
uint32 num_outputs = 3;
ProtobufMatrix a = 4;
ProtobufMatrix b = 5;
ProtobufMatrix c = 6;
ProtobufMatrix d = 7;
}

View File

@@ -0,0 +1,20 @@
syntax = "proto3";
package wpi.proto;
import "geometry2d.proto";
option java_package = "edu.wpi.first.math.proto";
message ProtobufTrajectoryState {
double time = 1;
double velocity = 2;
double acceleration = 3;
ProtobufPose2d pose = 4;
double curvature = 5;
}
message ProtobufTrajectory {
double total_time = 1;
repeated ProtobufTrajectoryState states = 2;
}

View File

@@ -0,0 +1,15 @@
syntax = "proto3";
package wpi.proto;
option java_package = "edu.wpi.first.math.proto";
message ProtobufMatrix {
uint32 num_rows = 1;
uint32 num_cols = 2;
repeated double data = 3;
}
message ProtobufVector {
repeated double rows = 1;
}