[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

@@ -9,10 +9,15 @@ import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import edu.wpi.first.math.interpolation.Interpolatable;
import edu.wpi.first.math.proto.Geometry2D.ProtobufPose2d;
import edu.wpi.first.util.protobuf.Protobuf;
import edu.wpi.first.util.struct.Struct;
import java.nio.ByteBuffer;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Objects;
import us.hebi.quickbuf.Descriptors.Descriptor;
/** Represents a 2D pose containing translational and rotational elements. */
@JsonIgnoreProperties(ignoreUnknown = true)
@@ -305,4 +310,83 @@ public class Pose2d implements Interpolatable<Pose2d> {
return this.exp(scaledTwist);
}
}
public static final class AStruct implements Struct<Pose2d> {
@Override
public Class<Pose2d> getTypeClass() {
return Pose2d.class;
}
@Override
public String getTypeString() {
return "struct:Pose2d";
}
@Override
public int getSize() {
return Translation2d.struct.getSize() + Rotation2d.struct.getSize();
}
@Override
public String getSchema() {
return "Translation2d translation;Rotation2d rotation";
}
@Override
public Struct<?>[] getNested() {
return new Struct<?>[] {Translation2d.struct, Rotation2d.struct};
}
@Override
public Pose2d unpack(ByteBuffer bb) {
Translation2d translation = Translation2d.struct.unpack(bb);
Rotation2d rotation = Rotation2d.struct.unpack(bb);
return new Pose2d(translation, rotation);
}
@Override
public void pack(ByteBuffer bb, Pose2d value) {
Translation2d.struct.pack(bb, value.m_translation);
Rotation2d.struct.pack(bb, value.m_rotation);
}
}
public static final AStruct struct = new AStruct();
public static final class AProto implements Protobuf<Pose2d, ProtobufPose2d> {
@Override
public Class<Pose2d> getTypeClass() {
return Pose2d.class;
}
@Override
public Descriptor getDescriptor() {
return ProtobufPose2d.getDescriptor();
}
@Override
public Protobuf<?, ?>[] getNested() {
return new Protobuf<?, ?>[] {Translation2d.proto, Rotation2d.proto};
}
@Override
public ProtobufPose2d createMessage() {
return ProtobufPose2d.newInstance();
}
@Override
public Pose2d unpack(ProtobufPose2d msg) {
return new Pose2d(
Translation2d.proto.unpack(msg.getTranslation()),
Rotation2d.proto.unpack(msg.getRotation()));
}
@Override
public void pack(ProtobufPose2d msg, Pose2d value) {
Translation2d.proto.pack(msg.getMutableTranslation(), value.m_translation);
Rotation2d.proto.pack(msg.getMutableRotation(), value.m_rotation);
}
}
public static final AProto proto = new AProto();
}

View File

@@ -10,7 +10,12 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import edu.wpi.first.math.WPIMathJNI;
import edu.wpi.first.math.interpolation.Interpolatable;
import edu.wpi.first.math.proto.Geometry3D.ProtobufPose3d;
import edu.wpi.first.util.protobuf.Protobuf;
import edu.wpi.first.util.struct.Struct;
import java.nio.ByteBuffer;
import java.util.Objects;
import us.hebi.quickbuf.Descriptors.Descriptor;
/** Represents a 3D pose containing translational and rotational elements. */
@JsonIgnoreProperties(ignoreUnknown = true)
@@ -318,4 +323,83 @@ public class Pose3d implements Interpolatable<Pose3d> {
return this.exp(scaledTwist);
}
}
public static final class AStruct implements Struct<Pose3d> {
@Override
public Class<Pose3d> getTypeClass() {
return Pose3d.class;
}
@Override
public String getTypeString() {
return "struct:Pose3d";
}
@Override
public int getSize() {
return Translation3d.struct.getSize() + Rotation3d.struct.getSize();
}
@Override
public String getSchema() {
return "Translation3d translation;Rotation3d rotation";
}
@Override
public Struct<?>[] getNested() {
return new Struct<?>[] {Translation3d.struct, Rotation3d.struct};
}
@Override
public Pose3d unpack(ByteBuffer bb) {
Translation3d translation = Translation3d.struct.unpack(bb);
Rotation3d rotation = Rotation3d.struct.unpack(bb);
return new Pose3d(translation, rotation);
}
@Override
public void pack(ByteBuffer bb, Pose3d value) {
Translation3d.struct.pack(bb, value.m_translation);
Rotation3d.struct.pack(bb, value.m_rotation);
}
}
public static final AStruct struct = new AStruct();
public static final class AProto implements Protobuf<Pose3d, ProtobufPose3d> {
@Override
public Class<Pose3d> getTypeClass() {
return Pose3d.class;
}
@Override
public Descriptor getDescriptor() {
return ProtobufPose3d.getDescriptor();
}
@Override
public Protobuf<?, ?>[] getNested() {
return new Protobuf<?, ?>[] {Translation3d.proto, Rotation3d.proto};
}
@Override
public ProtobufPose3d createMessage() {
return ProtobufPose3d.newInstance();
}
@Override
public Pose3d unpack(ProtobufPose3d msg) {
return new Pose3d(
Translation3d.proto.unpack(msg.getTranslation()),
Rotation3d.proto.unpack(msg.getRotation()));
}
@Override
public void pack(ProtobufPose3d msg, Pose3d value) {
Translation3d.proto.pack(msg.getMutableTranslation(), value.m_translation);
Rotation3d.proto.pack(msg.getMutableRotation(), value.m_rotation);
}
}
public static final AProto proto = new AProto();
}

View File

@@ -11,7 +11,12 @@ import com.fasterxml.jackson.annotation.JsonProperty;
import edu.wpi.first.math.VecBuilder;
import edu.wpi.first.math.Vector;
import edu.wpi.first.math.numbers.N3;
import edu.wpi.first.math.proto.Geometry3D.ProtobufQuaternion;
import edu.wpi.first.util.protobuf.Protobuf;
import edu.wpi.first.util.struct.Struct;
import java.nio.ByteBuffer;
import java.util.Objects;
import us.hebi.quickbuf.Descriptors.Descriptor;
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonAutoDetect(getterVisibility = JsonAutoDetect.Visibility.NONE)
@@ -400,4 +405,74 @@ public class Quaternion {
return VecBuilder.fill(coeff * getX(), coeff * getY(), coeff * getZ());
}
public static final class AStruct implements Struct<Quaternion> {
@Override
public Class<Quaternion> getTypeClass() {
return Quaternion.class;
}
@Override
public String getTypeString() {
return "struct:Quaternion";
}
@Override
public int getSize() {
return kSizeDouble * 4;
}
@Override
public String getSchema() {
return "double w;double x;double y;double z";
}
@Override
public Quaternion unpack(ByteBuffer bb) {
double w = bb.getDouble();
double x = bb.getDouble();
double y = bb.getDouble();
double z = bb.getDouble();
return new Quaternion(w, x, y, z);
}
@Override
public void pack(ByteBuffer bb, Quaternion value) {
bb.putDouble(value.getW());
bb.putDouble(value.getX());
bb.putDouble(value.getY());
bb.putDouble(value.getZ());
}
}
public static final AStruct struct = new AStruct();
public static final class AProto implements Protobuf<Quaternion, ProtobufQuaternion> {
@Override
public Class<Quaternion> getTypeClass() {
return Quaternion.class;
}
@Override
public Descriptor getDescriptor() {
return ProtobufQuaternion.getDescriptor();
}
@Override
public ProtobufQuaternion createMessage() {
return ProtobufQuaternion.newInstance();
}
@Override
public Quaternion unpack(ProtobufQuaternion msg) {
return new Quaternion(msg.getW(), msg.getX(), msg.getY(), msg.getZ());
}
@Override
public void pack(ProtobufQuaternion msg, Quaternion value) {
msg.setW(value.getW()).setX(value.getX()).setY(value.getY()).setZ(value.getZ());
}
}
public static final AProto proto = new AProto();
}

View File

@@ -10,8 +10,13 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import edu.wpi.first.math.MathUtil;
import edu.wpi.first.math.interpolation.Interpolatable;
import edu.wpi.first.math.proto.Geometry2D.ProtobufRotation2d;
import edu.wpi.first.math.util.Units;
import edu.wpi.first.util.protobuf.Protobuf;
import edu.wpi.first.util.struct.Struct;
import java.nio.ByteBuffer;
import java.util.Objects;
import us.hebi.quickbuf.Descriptors.Descriptor;
/**
* A rotation in a 2D coordinate frame represented by a point on the unit circle (cosine and sine).
@@ -256,4 +261,67 @@ public class Rotation2d implements Interpolatable<Rotation2d> {
public Rotation2d interpolate(Rotation2d endValue, double t) {
return plus(endValue.minus(this).times(MathUtil.clamp(t, 0, 1)));
}
public static final class AStruct implements Struct<Rotation2d> {
@Override
public Class<Rotation2d> getTypeClass() {
return Rotation2d.class;
}
@Override
public String getTypeString() {
return "struct:Rotation2d";
}
@Override
public int getSize() {
return kSizeDouble;
}
@Override
public String getSchema() {
return "double value";
}
@Override
public Rotation2d unpack(ByteBuffer bb) {
return new Rotation2d(bb.getDouble());
}
@Override
public void pack(ByteBuffer bb, Rotation2d value) {
bb.putDouble(value.m_value);
}
}
public static final AStruct struct = new AStruct();
public static final class AProto implements Protobuf<Rotation2d, ProtobufRotation2d> {
@Override
public Class<Rotation2d> getTypeClass() {
return Rotation2d.class;
}
@Override
public Descriptor getDescriptor() {
return ProtobufRotation2d.getDescriptor();
}
@Override
public ProtobufRotation2d createMessage() {
return ProtobufRotation2d.newInstance();
}
@Override
public Rotation2d unpack(ProtobufRotation2d msg) {
return new Rotation2d(msg.getValue());
}
@Override
public void pack(ProtobufRotation2d msg, Rotation2d value) {
msg.setValue(value.m_value);
}
}
public static final AProto proto = new AProto();
}

View File

@@ -17,8 +17,13 @@ import edu.wpi.first.math.VecBuilder;
import edu.wpi.first.math.Vector;
import edu.wpi.first.math.interpolation.Interpolatable;
import edu.wpi.first.math.numbers.N3;
import edu.wpi.first.math.proto.Geometry3D.ProtobufRotation3d;
import edu.wpi.first.util.protobuf.Protobuf;
import edu.wpi.first.util.struct.Struct;
import java.nio.ByteBuffer;
import java.util.Objects;
import org.ejml.dense.row.factory.DecompositionFactory_DDRM;
import us.hebi.quickbuf.Descriptors.Descriptor;
/** A rotation in a 3D coordinate frame represented by a quaternion. */
@JsonIgnoreProperties(ignoreUnknown = true)
@@ -434,4 +439,77 @@ public class Rotation3d implements Interpolatable<Rotation3d> {
public Rotation3d interpolate(Rotation3d endValue, double t) {
return plus(endValue.minus(this).times(MathUtil.clamp(t, 0, 1)));
}
public static final class AStruct implements Struct<Rotation3d> {
@Override
public Class<Rotation3d> getTypeClass() {
return Rotation3d.class;
}
@Override
public String getTypeString() {
return "struct:Rotation3d";
}
@Override
public int getSize() {
return Quaternion.struct.getSize();
}
@Override
public String getSchema() {
return "Quaternion q";
}
@Override
public Struct<?>[] getNested() {
return new Struct<?>[] {Quaternion.struct};
}
@Override
public Rotation3d unpack(ByteBuffer bb) {
return new Rotation3d(Quaternion.struct.unpack(bb));
}
@Override
public void pack(ByteBuffer bb, Rotation3d value) {
Quaternion.struct.pack(bb, value.m_q);
}
}
public static final AStruct struct = new AStruct();
public static final class AProto implements Protobuf<Rotation3d, ProtobufRotation3d> {
@Override
public Class<Rotation3d> getTypeClass() {
return Rotation3d.class;
}
@Override
public Descriptor getDescriptor() {
return ProtobufRotation3d.getDescriptor();
}
@Override
public Protobuf<?, ?>[] getNested() {
return new Protobuf<?, ?>[] {Quaternion.proto};
}
@Override
public ProtobufRotation3d createMessage() {
return ProtobufRotation3d.newInstance();
}
@Override
public Rotation3d unpack(ProtobufRotation3d msg) {
return new Rotation3d(Quaternion.proto.unpack(msg.getQ()));
}
@Override
public void pack(ProtobufRotation3d msg, Rotation3d value) {
Quaternion.proto.pack(msg.getMutableQ(), value.m_q);
}
}
public static final AProto proto = new AProto();
}

View File

@@ -4,7 +4,12 @@
package edu.wpi.first.math.geometry;
import edu.wpi.first.math.proto.Geometry2D.ProtobufTransform2d;
import edu.wpi.first.util.protobuf.Protobuf;
import edu.wpi.first.util.struct.Struct;
import java.nio.ByteBuffer;
import java.util.Objects;
import us.hebi.quickbuf.Descriptors.Descriptor;
/** Represents a transformation for a Pose2d in the pose's frame. */
public class Transform2d {
@@ -163,4 +168,83 @@ public class Transform2d {
public int hashCode() {
return Objects.hash(m_translation, m_rotation);
}
public static final class AStruct implements Struct<Transform2d> {
@Override
public Class<Transform2d> getTypeClass() {
return Transform2d.class;
}
@Override
public String getTypeString() {
return "struct:Transform2d";
}
@Override
public int getSize() {
return Translation2d.struct.getSize() + Rotation2d.struct.getSize();
}
@Override
public String getSchema() {
return "Translation2d translation;Rotation2d rotation";
}
@Override
public Struct<?>[] getNested() {
return new Struct<?>[] {Translation2d.struct, Rotation2d.struct};
}
@Override
public Transform2d unpack(ByteBuffer bb) {
Translation2d translation = Translation2d.struct.unpack(bb);
Rotation2d rotation = Rotation2d.struct.unpack(bb);
return new Transform2d(translation, rotation);
}
@Override
public void pack(ByteBuffer bb, Transform2d value) {
Translation2d.struct.pack(bb, value.m_translation);
Rotation2d.struct.pack(bb, value.m_rotation);
}
}
public static final AStruct struct = new AStruct();
public static final class AProto implements Protobuf<Transform2d, ProtobufTransform2d> {
@Override
public Class<Transform2d> getTypeClass() {
return Transform2d.class;
}
@Override
public Descriptor getDescriptor() {
return ProtobufTransform2d.getDescriptor();
}
@Override
public Protobuf<?, ?>[] getNested() {
return new Protobuf<?, ?>[] {Translation2d.proto, Rotation2d.proto};
}
@Override
public ProtobufTransform2d createMessage() {
return ProtobufTransform2d.newInstance();
}
@Override
public Transform2d unpack(ProtobufTransform2d msg) {
return new Transform2d(
Translation2d.proto.unpack(msg.getTranslation()),
Rotation2d.proto.unpack(msg.getRotation()));
}
@Override
public void pack(ProtobufTransform2d msg, Transform2d value) {
Translation2d.proto.pack(msg.getMutableTranslation(), value.m_translation);
Rotation2d.proto.pack(msg.getMutableRotation(), value.m_rotation);
}
}
public static final AProto proto = new AProto();
}

View File

@@ -4,7 +4,12 @@
package edu.wpi.first.math.geometry;
import edu.wpi.first.math.proto.Geometry3D.ProtobufTransform3d;
import edu.wpi.first.util.protobuf.Protobuf;
import edu.wpi.first.util.struct.Struct;
import java.nio.ByteBuffer;
import java.util.Objects;
import us.hebi.quickbuf.Descriptors.Descriptor;
/** Represents a transformation for a Pose3d in the pose's frame. */
public class Transform3d {
@@ -173,4 +178,83 @@ public class Transform3d {
public int hashCode() {
return Objects.hash(m_translation, m_rotation);
}
public static final class AStruct implements Struct<Transform3d> {
@Override
public Class<Transform3d> getTypeClass() {
return Transform3d.class;
}
@Override
public String getTypeString() {
return "struct:Transform3d";
}
@Override
public int getSize() {
return Translation3d.struct.getSize() + Rotation3d.struct.getSize();
}
@Override
public String getSchema() {
return "Translation3d translation;Rotation3d rotation";
}
@Override
public Struct<?>[] getNested() {
return new Struct<?>[] {Translation3d.struct, Rotation3d.struct};
}
@Override
public Transform3d unpack(ByteBuffer bb) {
Translation3d translation = Translation3d.struct.unpack(bb);
Rotation3d rotation = Rotation3d.struct.unpack(bb);
return new Transform3d(translation, rotation);
}
@Override
public void pack(ByteBuffer bb, Transform3d value) {
Translation3d.struct.pack(bb, value.m_translation);
Rotation3d.struct.pack(bb, value.m_rotation);
}
}
public static final AStruct struct = new AStruct();
public static final class AProto implements Protobuf<Transform3d, ProtobufTransform3d> {
@Override
public Class<Transform3d> getTypeClass() {
return Transform3d.class;
}
@Override
public Descriptor getDescriptor() {
return ProtobufTransform3d.getDescriptor();
}
@Override
public Protobuf<?, ?>[] getNested() {
return new Protobuf<?, ?>[] {Translation3d.proto, Rotation3d.proto};
}
@Override
public ProtobufTransform3d createMessage() {
return ProtobufTransform3d.newInstance();
}
@Override
public Transform3d unpack(ProtobufTransform3d msg) {
return new Transform3d(
Translation3d.proto.unpack(msg.getTranslation()),
Rotation3d.proto.unpack(msg.getRotation()));
}
@Override
public void pack(ProtobufTransform3d msg, Transform3d value) {
Translation3d.proto.pack(msg.getMutableTranslation(), value.m_translation);
Rotation3d.proto.pack(msg.getMutableRotation(), value.m_rotation);
}
}
public static final AProto proto = new AProto();
}

View File

@@ -10,10 +10,15 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import edu.wpi.first.math.MathUtil;
import edu.wpi.first.math.interpolation.Interpolatable;
import edu.wpi.first.math.proto.Geometry2D.ProtobufTranslation2d;
import edu.wpi.first.util.protobuf.Protobuf;
import edu.wpi.first.util.struct.Struct;
import java.nio.ByteBuffer;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Objects;
import us.hebi.quickbuf.Descriptors.Descriptor;
/**
* Represents a translation in 2D space. This object can be used to represent a point or a vector.
@@ -229,4 +234,70 @@ public class Translation2d implements Interpolatable<Translation2d> {
MathUtil.interpolate(this.getX(), endValue.getX(), t),
MathUtil.interpolate(this.getY(), endValue.getY(), t));
}
public static final class AStruct implements Struct<Translation2d> {
@Override
public Class<Translation2d> getTypeClass() {
return Translation2d.class;
}
@Override
public String getTypeString() {
return "struct:Translation2d";
}
@Override
public int getSize() {
return kSizeDouble * 2;
}
@Override
public String getSchema() {
return "double x;double y";
}
@Override
public Translation2d unpack(ByteBuffer bb) {
double x = bb.getDouble();
double y = bb.getDouble();
return new Translation2d(x, y);
}
@Override
public void pack(ByteBuffer bb, Translation2d value) {
bb.putDouble(value.m_x);
bb.putDouble(value.m_y);
}
}
public static final AStruct struct = new AStruct();
public static final class AProto implements Protobuf<Translation2d, ProtobufTranslation2d> {
@Override
public Class<Translation2d> getTypeClass() {
return Translation2d.class;
}
@Override
public Descriptor getDescriptor() {
return ProtobufTranslation2d.getDescriptor();
}
@Override
public ProtobufTranslation2d createMessage() {
return ProtobufTranslation2d.newInstance();
}
@Override
public Translation2d unpack(ProtobufTranslation2d msg) {
return new Translation2d(msg.getX(), msg.getY());
}
@Override
public void pack(ProtobufTranslation2d msg, Translation2d value) {
msg.setX(value.m_x).setY(value.m_y);
}
}
public static final AProto proto = new AProto();
}

View File

@@ -10,7 +10,12 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import edu.wpi.first.math.MathUtil;
import edu.wpi.first.math.interpolation.Interpolatable;
import edu.wpi.first.math.proto.Geometry3D.ProtobufTranslation3d;
import edu.wpi.first.util.protobuf.Protobuf;
import edu.wpi.first.util.struct.Struct;
import java.nio.ByteBuffer;
import java.util.Objects;
import us.hebi.quickbuf.Descriptors.Descriptor;
/**
* Represents a translation in 3D space. This object can be used to represent a point or a vector.
@@ -231,4 +236,72 @@ public class Translation3d implements Interpolatable<Translation3d> {
MathUtil.interpolate(this.getY(), endValue.getY(), t),
MathUtil.interpolate(this.getZ(), endValue.getZ(), t));
}
public static final class AStruct implements Struct<Translation3d> {
@Override
public Class<Translation3d> getTypeClass() {
return Translation3d.class;
}
@Override
public String getTypeString() {
return "struct:Translation3d";
}
@Override
public int getSize() {
return kSizeDouble * 3;
}
@Override
public String getSchema() {
return "double x;double y;double z";
}
@Override
public Translation3d unpack(ByteBuffer bb) {
double x = bb.getDouble();
double y = bb.getDouble();
double z = bb.getDouble();
return new Translation3d(x, y, z);
}
@Override
public void pack(ByteBuffer bb, Translation3d value) {
bb.putDouble(value.m_x);
bb.putDouble(value.m_y);
bb.putDouble(value.m_z);
}
}
public static final AStruct struct = new AStruct();
public static final class AProto implements Protobuf<Translation3d, ProtobufTranslation3d> {
@Override
public Class<Translation3d> getTypeClass() {
return Translation3d.class;
}
@Override
public Descriptor getDescriptor() {
return ProtobufTranslation3d.getDescriptor();
}
@Override
public ProtobufTranslation3d createMessage() {
return ProtobufTranslation3d.newInstance();
}
@Override
public Translation3d unpack(ProtobufTranslation3d msg) {
return new Translation3d(msg.getX(), msg.getY(), msg.getZ());
}
@Override
public void pack(ProtobufTranslation3d msg, Translation3d value) {
msg.setX(value.m_x).setY(value.m_y).setZ(value.m_z);
}
}
public static final AProto proto = new AProto();
}

View File

@@ -4,7 +4,12 @@
package edu.wpi.first.math.geometry;
import edu.wpi.first.math.proto.Geometry2D.ProtobufTwist2d;
import edu.wpi.first.util.protobuf.Protobuf;
import edu.wpi.first.util.struct.Struct;
import java.nio.ByteBuffer;
import java.util.Objects;
import us.hebi.quickbuf.Descriptors.Descriptor;
/**
* A change in distance along a 2D arc since the last pose update. We can use ideas from
@@ -62,4 +67,72 @@ public class Twist2d {
public int hashCode() {
return Objects.hash(dx, dy, dtheta);
}
public static final class AStruct implements Struct<Twist2d> {
@Override
public Class<Twist2d> getTypeClass() {
return Twist2d.class;
}
@Override
public String getTypeString() {
return "struct:Twist2d";
}
@Override
public int getSize() {
return kSizeDouble * 3;
}
@Override
public String getSchema() {
return "double dx;double dy;double dtheta";
}
@Override
public Twist2d unpack(ByteBuffer bb) {
double dx = bb.getDouble();
double dy = bb.getDouble();
double dtheta = bb.getDouble();
return new Twist2d(dx, dy, dtheta);
}
@Override
public void pack(ByteBuffer bb, Twist2d value) {
bb.putDouble(value.dx);
bb.putDouble(value.dy);
bb.putDouble(value.dtheta);
}
}
public static final AStruct struct = new AStruct();
public static final class AProto implements Protobuf<Twist2d, ProtobufTwist2d> {
@Override
public Class<Twist2d> getTypeClass() {
return Twist2d.class;
}
@Override
public Descriptor getDescriptor() {
return ProtobufTwist2d.getDescriptor();
}
@Override
public ProtobufTwist2d createMessage() {
return ProtobufTwist2d.newInstance();
}
@Override
public Twist2d unpack(ProtobufTwist2d msg) {
return new Twist2d(msg.getDx(), msg.getDy(), msg.getDtheta());
}
@Override
public void pack(ProtobufTwist2d msg, Twist2d value) {
msg.setDx(value.dx).setDy(value.dy).setDtheta(value.dtheta);
}
}
public static final AProto proto = new AProto();
}

View File

@@ -4,7 +4,12 @@
package edu.wpi.first.math.geometry;
import edu.wpi.first.math.proto.Geometry3D.ProtobufTwist3d;
import edu.wpi.first.util.protobuf.Protobuf;
import edu.wpi.first.util.struct.Struct;
import java.nio.ByteBuffer;
import java.util.Objects;
import us.hebi.quickbuf.Descriptors.Descriptor;
/**
* A change in distance along a 3D arc since the last pose update. We can use ideas from
@@ -82,4 +87,84 @@ public class Twist3d {
public int hashCode() {
return Objects.hash(dx, dy, dz, rx, ry, rz);
}
public static final class AStruct implements Struct<Twist3d> {
@Override
public Class<Twist3d> getTypeClass() {
return Twist3d.class;
}
@Override
public String getTypeString() {
return "struct:Twist3d";
}
@Override
public int getSize() {
return kSizeDouble * 6;
}
@Override
public String getSchema() {
return "double dx;double dy;double dz;double rx;double ry;double rz";
}
@Override
public Twist3d unpack(ByteBuffer bb) {
double dx = bb.getDouble();
double dy = bb.getDouble();
double dz = bb.getDouble();
double rx = bb.getDouble();
double ry = bb.getDouble();
double rz = bb.getDouble();
return new Twist3d(dx, dy, dz, rx, ry, rz);
}
@Override
public void pack(ByteBuffer bb, Twist3d value) {
bb.putDouble(value.dx);
bb.putDouble(value.dy);
bb.putDouble(value.dz);
bb.putDouble(value.rx);
bb.putDouble(value.ry);
bb.putDouble(value.rz);
}
}
public static final AStruct struct = new AStruct();
public static final class AProto implements Protobuf<Twist3d, ProtobufTwist3d> {
@Override
public Class<Twist3d> getTypeClass() {
return Twist3d.class;
}
@Override
public Descriptor getDescriptor() {
return ProtobufTwist3d.getDescriptor();
}
@Override
public ProtobufTwist3d createMessage() {
return ProtobufTwist3d.newInstance();
}
@Override
public Twist3d unpack(ProtobufTwist3d msg) {
return new Twist3d(
msg.getDx(), msg.getDy(), msg.getDz(), msg.getRx(), msg.getRy(), msg.getRz());
}
@Override
public void pack(ProtobufTwist3d msg, Twist3d value) {
msg.setDx(value.dx)
.setDy(value.dy)
.setDz(value.dz)
.setRx(value.rx)
.setRy(value.ry)
.setRz(value.rz);
}
}
public static final AProto proto = new AProto();
}

View File

@@ -9,6 +9,7 @@
#include <wpi/json.h>
#include "frc/MathUtil.h"
#include "geometry2d.pb.h"
using namespace frc;
@@ -108,3 +109,23 @@ void frc::from_json(const wpi::json& json, Pose2d& pose) {
pose = Pose2d{json.at("translation").get<Translation2d>(),
json.at("rotation").get<Rotation2d>()};
}
google::protobuf::Message* wpi::Protobuf<frc::Pose2d>::New(
google::protobuf::Arena* arena) {
return google::protobuf::Arena::CreateMessage<wpi::proto::ProtobufPose2d>(
arena);
}
frc::Pose2d wpi::Protobuf<frc::Pose2d>::Unpack(
const google::protobuf::Message& msg) {
auto m = static_cast<const wpi::proto::ProtobufPose2d*>(&msg);
return Pose2d{wpi::UnpackProtobuf<frc::Translation2d>(m->translation()),
wpi::UnpackProtobuf<frc::Rotation2d>(m->rotation())};
}
void wpi::Protobuf<frc::Pose2d>::Pack(google::protobuf::Message* msg,
const frc::Pose2d& value) {
auto m = static_cast<wpi::proto::ProtobufPose2d*>(msg);
wpi::PackProtobuf(m->mutable_translation(), value.Translation());
wpi::PackProtobuf(m->mutable_rotation(), value.Rotation());
}

View File

@@ -9,6 +9,8 @@
#include <Eigen/Core>
#include <wpi/json.h>
#include "geometry3d.pb.h"
using namespace frc;
namespace {
@@ -187,3 +189,23 @@ void frc::from_json(const wpi::json& json, Pose3d& pose) {
pose = Pose3d{json.at("translation").get<Translation3d>(),
json.at("rotation").get<Rotation3d>()};
}
google::protobuf::Message* wpi::Protobuf<frc::Pose3d>::New(
google::protobuf::Arena* arena) {
return google::protobuf::Arena::CreateMessage<wpi::proto::ProtobufPose3d>(
arena);
}
frc::Pose3d wpi::Protobuf<frc::Pose3d>::Unpack(
const google::protobuf::Message& msg) {
auto m = static_cast<const wpi::proto::ProtobufPose3d*>(&msg);
return Pose3d{wpi::UnpackProtobuf<frc::Translation3d>(m->translation()),
wpi::UnpackProtobuf<frc::Rotation3d>(m->rotation())};
}
void wpi::Protobuf<frc::Pose3d>::Pack(google::protobuf::Message* msg,
const frc::Pose3d& value) {
auto m = static_cast<wpi::proto::ProtobufPose3d*>(msg);
wpi::PackProtobuf(m->mutable_translation(), value.Translation());
wpi::PackProtobuf(m->mutable_rotation(), value.Rotation());
}

View File

@@ -8,6 +8,8 @@
#include <wpi/json.h>
#include "geometry3d.pb.h"
using namespace frc;
Quaternion::Quaternion(double w, double x, double y, double z)
@@ -230,3 +232,24 @@ void frc::from_json(const wpi::json& json, Quaternion& quaternion) {
Quaternion{json.at("W").get<double>(), json.at("X").get<double>(),
json.at("Y").get<double>(), json.at("Z").get<double>()};
}
google::protobuf::Message* wpi::Protobuf<frc::Quaternion>::New(
google::protobuf::Arena* arena) {
return google::protobuf::Arena::CreateMessage<wpi::proto::ProtobufQuaternion>(
arena);
}
frc::Quaternion wpi::Protobuf<frc::Quaternion>::Unpack(
const google::protobuf::Message& msg) {
auto m = static_cast<const wpi::proto::ProtobufQuaternion*>(&msg);
return frc::Quaternion{m->w(), m->x(), m->y(), m->z()};
}
void wpi::Protobuf<frc::Quaternion>::Pack(google::protobuf::Message* msg,
const frc::Quaternion& value) {
auto m = static_cast<wpi::proto::ProtobufQuaternion*>(msg);
m->set_w(value.W());
m->set_x(value.X());
m->set_y(value.Y());
m->set_z(value.Z());
}

View File

@@ -8,6 +8,7 @@
#include <wpi/json.h>
#include "geometry2d.pb.h"
#include "units/math.h"
using namespace frc;
@@ -19,3 +20,21 @@ void frc::to_json(wpi::json& json, const Rotation2d& rotation) {
void frc::from_json(const wpi::json& json, Rotation2d& rotation) {
rotation = Rotation2d{units::radian_t{json.at("radians").get<double>()}};
}
google::protobuf::Message* wpi::Protobuf<frc::Rotation2d>::New(
google::protobuf::Arena* arena) {
return google::protobuf::Arena::CreateMessage<wpi::proto::ProtobufRotation2d>(
arena);
}
frc::Rotation2d wpi::Protobuf<frc::Rotation2d>::Unpack(
const google::protobuf::Message& msg) {
auto m = static_cast<const wpi::proto::ProtobufRotation2d*>(&msg);
return frc::Rotation2d{units::radian_t{m->value()}};
}
void wpi::Protobuf<frc::Rotation2d>::Pack(google::protobuf::Message* msg,
const frc::Rotation2d& value) {
auto m = static_cast<wpi::proto::ProtobufRotation2d*>(msg);
m->set_value(value.Radians().value());
}

View File

@@ -13,6 +13,7 @@
#include <wpi/json.h>
#include "frc/fmt/Eigen.h"
#include "geometry3d.pb.h"
#include "units/math.h"
#include "wpimath/MathShared.h"
@@ -261,3 +262,21 @@ void frc::to_json(wpi::json& json, const Rotation3d& rotation) {
void frc::from_json(const wpi::json& json, Rotation3d& rotation) {
rotation = Rotation3d{json.at("quaternion").get<Quaternion>()};
}
google::protobuf::Message* wpi::Protobuf<frc::Rotation3d>::New(
google::protobuf::Arena* arena) {
return google::protobuf::Arena::CreateMessage<wpi::proto::ProtobufRotation3d>(
arena);
}
frc::Rotation3d wpi::Protobuf<frc::Rotation3d>::Unpack(
const google::protobuf::Message& msg) {
auto m = static_cast<const wpi::proto::ProtobufRotation3d*>(&msg);
return Rotation3d{wpi::UnpackProtobuf<frc::Quaternion>(m->q())};
}
void wpi::Protobuf<frc::Rotation3d>::Pack(google::protobuf::Message* msg,
const frc::Rotation3d& value) {
auto m = static_cast<wpi::proto::ProtobufRotation3d*>(msg);
wpi::PackProtobuf(m->mutable_q(), value.GetQuaternion());
}

View File

@@ -5,6 +5,7 @@
#include "frc/geometry/Transform2d.h"
#include "frc/geometry/Pose2d.h"
#include "geometry2d.pb.h"
using namespace frc;
@@ -21,3 +22,23 @@ Transform2d::Transform2d(Pose2d initial, Pose2d final) {
Transform2d Transform2d::operator+(const Transform2d& other) const {
return Transform2d{Pose2d{}, Pose2d{}.TransformBy(*this).TransformBy(other)};
}
google::protobuf::Message* wpi::Protobuf<frc::Transform2d>::New(
google::protobuf::Arena* arena) {
return google::protobuf::Arena::CreateMessage<
wpi::proto::ProtobufTransform2d>(arena);
}
frc::Transform2d wpi::Protobuf<frc::Transform2d>::Unpack(
const google::protobuf::Message& msg) {
auto m = static_cast<const wpi::proto::ProtobufTransform2d*>(&msg);
return Transform2d{wpi::UnpackProtobuf<frc::Translation2d>(m->translation()),
wpi::UnpackProtobuf<frc::Rotation2d>(m->rotation())};
}
void wpi::Protobuf<frc::Transform2d>::Pack(google::protobuf::Message* msg,
const frc::Transform2d& value) {
auto m = static_cast<wpi::proto::ProtobufTransform2d*>(msg);
wpi::PackProtobuf(m->mutable_translation(), value.Translation());
wpi::PackProtobuf(m->mutable_rotation(), value.Rotation());
}

View File

@@ -5,6 +5,7 @@
#include "frc/geometry/Transform3d.h"
#include "frc/geometry/Pose3d.h"
#include "geometry3d.pb.h"
using namespace frc;
@@ -35,3 +36,23 @@ Transform3d Transform3d::Inverse() const {
Transform3d Transform3d::operator+(const Transform3d& other) const {
return Transform3d{Pose3d{}, Pose3d{}.TransformBy(*this).TransformBy(other)};
}
google::protobuf::Message* wpi::Protobuf<frc::Transform3d>::New(
google::protobuf::Arena* arena) {
return google::protobuf::Arena::CreateMessage<
wpi::proto::ProtobufTransform3d>(arena);
}
frc::Transform3d wpi::Protobuf<frc::Transform3d>::Unpack(
const google::protobuf::Message& msg) {
auto m = static_cast<const wpi::proto::ProtobufTransform3d*>(&msg);
return Transform3d{wpi::UnpackProtobuf<frc::Translation3d>(m->translation()),
wpi::UnpackProtobuf<frc::Rotation3d>(m->rotation())};
}
void wpi::Protobuf<frc::Transform3d>::Pack(google::protobuf::Message* msg,
const frc::Transform3d& value) {
auto m = static_cast<wpi::proto::ProtobufTransform3d*>(msg);
wpi::PackProtobuf(m->mutable_translation(), value.Translation());
wpi::PackProtobuf(m->mutable_rotation(), value.Rotation());
}

View File

@@ -6,6 +6,7 @@
#include <wpi/json.h>
#include "geometry2d.pb.h"
#include "units/math.h"
using namespace frc;
@@ -48,3 +49,22 @@ void frc::from_json(const wpi::json& json, Translation2d& translation) {
translation = Translation2d{units::meter_t{json.at("x").get<double>()},
units::meter_t{json.at("y").get<double>()}};
}
google::protobuf::Message* wpi::Protobuf<frc::Translation2d>::New(
google::protobuf::Arena* arena) {
return google::protobuf::Arena::CreateMessage<
wpi::proto::ProtobufTranslation2d>(arena);
}
frc::Translation2d wpi::Protobuf<frc::Translation2d>::Unpack(
const google::protobuf::Message& msg) {
auto m = static_cast<const wpi::proto::ProtobufTranslation2d*>(&msg);
return frc::Translation2d{units::meter_t{m->x()}, units::meter_t{m->y()}};
}
void wpi::Protobuf<frc::Translation2d>::Pack(google::protobuf::Message* msg,
const frc::Translation2d& value) {
auto m = static_cast<wpi::proto::ProtobufTranslation2d*>(msg);
m->set_x(value.X().value());
m->set_y(value.Y().value());
}

View File

@@ -6,6 +6,7 @@
#include <wpi/json.h>
#include "geometry3d.pb.h"
#include "units/length.h"
#include "units/math.h"
@@ -52,3 +53,24 @@ void frc::from_json(const wpi::json& json, Translation3d& translation) {
units::meter_t{json.at("y").get<double>()},
units::meter_t{json.at("z").get<double>()}};
}
google::protobuf::Message* wpi::Protobuf<frc::Translation3d>::New(
google::protobuf::Arena* arena) {
return google::protobuf::Arena::CreateMessage<
wpi::proto::ProtobufTranslation3d>(arena);
}
frc::Translation3d wpi::Protobuf<frc::Translation3d>::Unpack(
const google::protobuf::Message& msg) {
auto m = static_cast<const wpi::proto::ProtobufTranslation3d*>(&msg);
return frc::Translation3d{units::meter_t{m->x()}, units::meter_t{m->y()},
units::meter_t{m->z()}};
}
void wpi::Protobuf<frc::Translation3d>::Pack(google::protobuf::Message* msg,
const frc::Translation3d& value) {
auto m = static_cast<wpi::proto::ProtobufTranslation3d*>(msg);
m->set_x(value.X().value());
m->set_y(value.Y().value());
m->set_z(value.Z().value());
}

View File

@@ -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/geometry/Twist2d.h"
#include "geometry2d.pb.h"
using namespace frc;
google::protobuf::Message* wpi::Protobuf<frc::Twist2d>::New(
google::protobuf::Arena* arena) {
return google::protobuf::Arena::CreateMessage<wpi::proto::ProtobufTwist2d>(
arena);
}
frc::Twist2d wpi::Protobuf<frc::Twist2d>::Unpack(
const google::protobuf::Message& msg) {
auto m = static_cast<const wpi::proto::ProtobufTwist2d*>(&msg);
return frc::Twist2d{units::meter_t{m->dx()}, units::meter_t{m->dy()},
units::radian_t{m->dtheta()}};
}
void wpi::Protobuf<frc::Twist2d>::Pack(google::protobuf::Message* msg,
const frc::Twist2d& value) {
auto m = static_cast<wpi::proto::ProtobufTwist2d*>(msg);
m->set_dx(value.dx.value());
m->set_dy(value.dy.value());
m->set_dtheta(value.dtheta.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/geometry/Twist3d.h"
#include "geometry3d.pb.h"
using namespace frc;
google::protobuf::Message* wpi::Protobuf<frc::Twist3d>::New(
google::protobuf::Arena* arena) {
return google::protobuf::Arena::CreateMessage<wpi::proto::ProtobufTwist3d>(
arena);
}
frc::Twist3d wpi::Protobuf<frc::Twist3d>::Unpack(
const google::protobuf::Message& msg) {
auto m = static_cast<const wpi::proto::ProtobufTwist3d*>(&msg);
return frc::Twist3d{units::meter_t{m->dx()}, units::meter_t{m->dy()},
units::meter_t{m->dz()}, units::radian_t{m->rx()},
units::radian_t{m->ry()}, units::radian_t{m->rz()}};
}
void wpi::Protobuf<frc::Twist3d>::Pack(google::protobuf::Message* msg,
const frc::Twist3d& value) {
auto m = static_cast<wpi::proto::ProtobufTwist3d*>(msg);
m->set_dx(value.dx.value());
m->set_dy(value.dy.value());
m->set_dz(value.dz.value());
m->set_rx(value.rx.value());
m->set_ry(value.ry.value());
m->set_rz(value.rz.value());
}

View File

@@ -9,7 +9,10 @@
#include <wpi/SymbolExports.h>
#include <wpi/json_fwd.h>
#include <wpi/protobuf/Protobuf.h>
#include <wpi/struct/Struct.h>
#include "frc/geometry/Rotation2d.h"
#include "frc/geometry/Transform2d.h"
#include "frc/geometry/Translation2d.h"
#include "frc/geometry/Twist2d.h"
@@ -212,4 +215,38 @@ void from_json(const wpi::json& json, Pose2d& pose);
} // namespace frc
template <>
struct wpi::Struct<frc::Pose2d> {
static constexpr std::string_view kTypeString = "struct:Pose2d";
static constexpr size_t kSize = wpi::Struct<frc::Translation2d>::kSize +
wpi::Struct<frc::Rotation2d>::kSize;
static constexpr std::string_view kSchema =
"Translation2d translation;Rotation2d rotation";
static frc::Pose2d Unpack(std::span<const uint8_t, kSize> data) {
return {wpi::UnpackStruct<frc::Translation2d, 0>(data),
wpi::UnpackStruct<frc::Rotation2d, kRotationOff>(data)};
}
static void Pack(std::span<uint8_t, kSize> data, const frc::Pose2d& value) {
wpi::PackStruct<0>(data, value.Translation());
wpi::PackStruct<kRotationOff>(data, value.Rotation());
}
static void ForEachNested(
std::invocable<std::string_view, std::string_view> auto fn) {
wpi::ForEachStructSchema<frc::Translation2d>(fn);
wpi::ForEachStructSchema<frc::Rotation2d>(fn);
}
private:
static constexpr size_t kRotationOff = wpi::Struct<frc::Translation2d>::kSize;
};
static_assert(wpi::HasNestedStruct<frc::Pose2d>);
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);
};
#include "frc/geometry/Pose2d.inc"

View File

@@ -6,8 +6,11 @@
#include <wpi/SymbolExports.h>
#include <wpi/json_fwd.h>
#include <wpi/protobuf/Protobuf.h>
#include <wpi/struct/Struct.h>
#include "frc/geometry/Pose2d.h"
#include "frc/geometry/Rotation3d.h"
#include "frc/geometry/Transform3d.h"
#include "frc/geometry/Translation3d.h"
#include "frc/geometry/Twist3d.h"
@@ -213,3 +216,37 @@ WPILIB_DLLEXPORT
void from_json(const wpi::json& json, Pose3d& pose);
} // namespace frc
template <>
struct wpi::Struct<frc::Pose3d> {
static constexpr std::string_view kTypeString = "struct:Pose3d";
static constexpr size_t kSize = wpi::Struct<frc::Translation3d>::kSize +
wpi::Struct<frc::Rotation3d>::kSize;
static constexpr std::string_view kSchema =
"Translation3d translation;Rotation3d rotation";
static frc::Pose3d Unpack(std::span<const uint8_t, kSize> data) {
return {wpi::UnpackStruct<frc::Translation3d, 0>(data),
wpi::UnpackStruct<frc::Rotation3d, kRotationOff>(data)};
}
static void Pack(std::span<uint8_t, kSize> data, const frc::Pose3d& value) {
wpi::PackStruct<0>(data, value.Translation());
wpi::PackStruct<kRotationOff>(data, value.Rotation());
}
static void ForEachNested(
std::invocable<std::string_view, std::string_view> auto fn) {
wpi::ForEachStructSchema<frc::Translation3d>(fn);
wpi::ForEachStructSchema<frc::Rotation3d>(fn);
}
private:
static constexpr size_t kRotationOff = wpi::Struct<frc::Translation3d>::kSize;
};
static_assert(wpi::HasNestedStruct<frc::Pose3d>);
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);
};

View File

@@ -7,6 +7,8 @@
#include <Eigen/Core>
#include <wpi/SymbolExports.h>
#include <wpi/json_fwd.h>
#include <wpi/protobuf/Protobuf.h>
#include <wpi/struct/Struct.h>
namespace frc {
@@ -187,3 +189,32 @@ WPILIB_DLLEXPORT
void from_json(const wpi::json& json, Quaternion& quaternion);
} // namespace frc
template <>
struct wpi::Struct<frc::Quaternion> {
static constexpr std::string_view kTypeString = "struct:Quaternion";
static constexpr size_t kSize = 32;
static constexpr std::string_view kSchema =
"double w;double x;double y;double z";
static frc::Quaternion Unpack(std::span<const uint8_t, 32> data) {
return {wpi::UnpackStruct<double, 0>(data),
wpi::UnpackStruct<double, 8>(data),
wpi::UnpackStruct<double, 16>(data),
wpi::UnpackStruct<double, 24>(data)};
}
static void Pack(std::span<uint8_t, 32> data, const frc::Quaternion& value) {
wpi::PackStruct<0>(data, value.W());
wpi::PackStruct<8>(data, value.X());
wpi::PackStruct<16>(data, value.Y());
wpi::PackStruct<24>(data, value.Z());
}
};
template <>
struct WPILIB_DLLEXPORT wpi::Protobuf<frc::Quaternion> {
static constexpr std::string_view kTypeString = "proto: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);
};

View File

@@ -6,6 +6,8 @@
#include <wpi/SymbolExports.h>
#include <wpi/json_fwd.h>
#include <wpi/protobuf/Protobuf.h>
#include <wpi/struct/Struct.h>
#include "units/angle.h"
@@ -176,4 +178,25 @@ void from_json(const wpi::json& json, Rotation2d& rotation);
} // namespace frc
template <>
struct wpi::Struct<frc::Rotation2d> {
static constexpr std::string_view kTypeString = "struct:Rotation2d";
static constexpr size_t kSize = 8;
static constexpr std::string_view kSchema = "double value";
static frc::Rotation2d Unpack(std::span<const uint8_t, 8> data) {
return units::radian_t{wpi::UnpackStruct<double>(data)};
}
static void Pack(std::span<uint8_t, 8> data, const frc::Rotation2d& value) {
wpi::PackStruct(data, value.Radians().value());
}
};
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);
};
#include "frc/geometry/Rotation2d.inc"

View File

@@ -7,6 +7,8 @@
#include <Eigen/Core>
#include <wpi/SymbolExports.h>
#include <wpi/json_fwd.h>
#include <wpi/protobuf/Protobuf.h>
#include <wpi/struct/Struct.h>
#include "frc/geometry/Quaternion.h"
#include "frc/geometry/Rotation2d.h"
@@ -194,3 +196,31 @@ WPILIB_DLLEXPORT
void from_json(const wpi::json& json, Rotation3d& rotation);
} // namespace frc
template <>
struct wpi::Struct<frc::Rotation3d> {
static constexpr std::string_view kTypeString = "struct:Rotation3d";
static constexpr size_t kSize = wpi::Struct<frc::Quaternion>::kSize;
static constexpr std::string_view kSchema = "Quaternion q";
static frc::Rotation3d Unpack(std::span<const uint8_t, kSize> data) {
return frc::Rotation3d{wpi::UnpackStruct<frc::Quaternion, 0>(data)};
}
static void Pack(std::span<uint8_t, kSize> data,
const frc::Rotation3d& value) {
wpi::PackStruct<0>(data, value.GetQuaternion());
}
static void ForEachNested(
std::invocable<std::string_view, std::string_view> auto fn) {
wpi::ForEachStructSchema<frc::Quaternion>(fn);
}
};
static_assert(wpi::HasNestedStruct<frc::Rotation3d>);
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);
};

View File

@@ -5,6 +5,8 @@
#pragma once
#include <wpi/SymbolExports.h>
#include <wpi/protobuf/Protobuf.h>
#include <wpi/struct/Struct.h>
#include "frc/geometry/Translation2d.h"
@@ -124,4 +126,40 @@ class WPILIB_DLLEXPORT Transform2d {
};
} // namespace frc
template <>
struct wpi::Struct<frc::Transform2d> {
static constexpr std::string_view kTypeString = "struct:Transform2d";
static constexpr size_t kSize = wpi::Struct<frc::Translation2d>::kSize +
wpi::Struct<frc::Rotation2d>::kSize;
static constexpr std::string_view kSchema =
"Translation2d translation;Rotation2d rotation";
static frc::Transform2d Unpack(std::span<const uint8_t, kSize> data) {
return {wpi::UnpackStruct<frc::Translation2d, 0>(data),
wpi::UnpackStruct<frc::Rotation2d, kRotationOff>(data)};
}
static void Pack(std::span<uint8_t, kSize> data,
const frc::Transform2d& value) {
wpi::PackStruct<0>(data, value.Translation());
wpi::PackStruct<kRotationOff>(data, value.Rotation());
}
static void ForEachNested(
std::invocable<std::string_view, std::string_view> auto fn) {
wpi::ForEachStructSchema<frc::Translation2d>(fn);
wpi::ForEachStructSchema<frc::Rotation2d>(fn);
}
private:
static constexpr size_t kRotationOff = wpi::Struct<frc::Translation2d>::kSize;
};
static_assert(wpi::HasNestedStruct<frc::Transform2d>);
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);
};
#include "frc/geometry/Transform2d.inc"

View File

@@ -5,6 +5,8 @@
#pragma once
#include <wpi/SymbolExports.h>
#include <wpi/protobuf/Protobuf.h>
#include <wpi/struct/Struct.h>
#include "frc/geometry/Translation3d.h"
@@ -129,3 +131,39 @@ class WPILIB_DLLEXPORT Transform3d {
Rotation3d m_rotation;
};
} // namespace frc
template <>
struct wpi::Struct<frc::Transform3d> {
static constexpr std::string_view kTypeString = "struct:Transform3d";
static constexpr size_t kSize = wpi::Struct<frc::Translation3d>::kSize +
wpi::Struct<frc::Rotation3d>::kSize;
static constexpr std::string_view kSchema =
"Translation3d translation;Rotation3d rotation";
static frc::Transform3d Unpack(std::span<const uint8_t, kSize> data) {
return {wpi::UnpackStruct<frc::Translation3d, 0>(data),
wpi::UnpackStruct<frc::Rotation3d, kRotationOff>(data)};
}
static void Pack(std::span<uint8_t, kSize> data,
const frc::Transform3d& value) {
wpi::PackStruct<0>(data, value.Translation());
wpi::PackStruct<kRotationOff>(data, value.Rotation());
}
static void ForEachNested(
std::invocable<std::string_view, std::string_view> auto fn) {
wpi::ForEachStructSchema<frc::Translation3d>(fn);
wpi::ForEachStructSchema<frc::Rotation3d>(fn);
}
private:
static constexpr size_t kRotationOff = wpi::Struct<frc::Translation3d>::kSize;
};
static_assert(wpi::HasNestedStruct<frc::Transform3d>);
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);
};

View File

@@ -9,6 +9,8 @@
#include <wpi/SymbolExports.h>
#include <wpi/json_fwd.h>
#include <wpi/protobuf/Protobuf.h>
#include <wpi/struct/Struct.h>
#include "frc/geometry/Rotation2d.h"
#include "units/length.h"
@@ -198,4 +200,28 @@ void from_json(const wpi::json& json, Translation2d& state);
} // namespace frc
template <>
struct wpi::Struct<frc::Translation2d> {
static constexpr std::string_view kTypeString = "struct:Translation2d";
static constexpr size_t kSize = 16;
static constexpr std::string_view kSchema = "double x;double y";
static frc::Translation2d Unpack(std::span<const uint8_t, 16> data) {
return {units::meter_t{wpi::UnpackStruct<double, 0>(data)},
units::meter_t{wpi::UnpackStruct<double, 8>(data)}};
}
static void Pack(std::span<uint8_t, 16> data,
const frc::Translation2d& value) {
wpi::PackStruct<0>(data, value.X().value());
wpi::PackStruct<8>(data, value.Y().value());
}
};
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);
};
#include "frc/geometry/Translation2d.inc"

View File

@@ -6,6 +6,8 @@
#include <wpi/SymbolExports.h>
#include <wpi/json_fwd.h>
#include <wpi/protobuf/Protobuf.h>
#include <wpi/struct/Struct.h>
#include "frc/geometry/Rotation3d.h"
#include "frc/geometry/Translation2d.h"
@@ -183,4 +185,30 @@ void from_json(const wpi::json& json, Translation3d& state);
} // namespace frc
template <>
struct wpi::Struct<frc::Translation3d> {
static constexpr std::string_view kTypeString = "struct:Translation3d";
static constexpr size_t kSize = 24;
static constexpr std::string_view kSchema = "double x;double y;double z";
static frc::Translation3d Unpack(std::span<const uint8_t, 24> data) {
return {units::meter_t{wpi::UnpackStruct<double, 0>(data)},
units::meter_t{wpi::UnpackStruct<double, 8>(data)},
units::meter_t{wpi::UnpackStruct<double, 16>(data)}};
}
static void Pack(std::span<uint8_t, 24> data,
const frc::Translation3d& value) {
wpi::PackStruct<0>(data, value.X().value());
wpi::PackStruct<8>(data, value.Y().value());
wpi::PackStruct<16>(data, value.Z().value());
}
};
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);
};
#include "frc/geometry/Translation3d.inc"

View File

@@ -5,6 +5,8 @@
#pragma once
#include <wpi/SymbolExports.h>
#include <wpi/protobuf/Protobuf.h>
#include <wpi/struct/Struct.h>
#include "units/angle.h"
#include "units/length.h"
@@ -57,3 +59,28 @@ struct WPILIB_DLLEXPORT Twist2d {
}
};
} // namespace frc
template <>
struct wpi::Struct<frc::Twist2d> {
static constexpr std::string_view kTypeString = "struct:Twist2d";
static constexpr size_t kSize = 24;
static constexpr std::string_view kSchema =
"double dx;double dy;double dtheta";
static frc::Twist2d Unpack(std::span<const uint8_t, 24> data) {
return {units::meter_t{wpi::UnpackStruct<double, 0>(data)},
units::meter_t{wpi::UnpackStruct<double, 8>(data)},
units::radian_t{wpi::UnpackStruct<double, 16>(data)}};
}
static void Pack(std::span<uint8_t, 24> data, const frc::Twist2d& value) {
wpi::PackStruct<0>(data, value.dx.value());
wpi::PackStruct<8>(data, value.dy.value());
wpi::PackStruct<16>(data, value.dtheta.value());
}
};
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);
};

View File

@@ -5,6 +5,8 @@
#pragma once
#include <wpi/SymbolExports.h>
#include <wpi/protobuf/Protobuf.h>
#include <wpi/struct/Struct.h>
#include "frc/geometry/Rotation3d.h"
#include "units/angle.h"
@@ -77,3 +79,35 @@ struct WPILIB_DLLEXPORT Twist3d {
}
};
} // namespace frc
template <>
struct wpi::Struct<frc::Twist3d> {
static constexpr std::string_view kTypeString = "struct:Twist3d";
static constexpr size_t kSize = 48;
static constexpr std::string_view kSchema =
"double dx;double dy;double dz;double rx;double ry;double rz";
static frc::Twist3d Unpack(std::span<const uint8_t, 48> data) {
return {units::meter_t{wpi::UnpackStruct<double, 0>(data)},
units::meter_t{wpi::UnpackStruct<double, 8>(data)},
units::meter_t{wpi::UnpackStruct<double, 16>(data)},
units::radian_t{wpi::UnpackStruct<double, 24>(data)},
units::radian_t{wpi::UnpackStruct<double, 32>(data)},
units::radian_t{wpi::UnpackStruct<double, 40>(data)}};
}
static void Pack(std::span<uint8_t, 48> data, const frc::Twist3d& value) {
wpi::PackStruct<0>(data, value.dx.value());
wpi::PackStruct<8>(data, value.dy.value());
wpi::PackStruct<16>(data, value.dz.value());
wpi::PackStruct<24>(data, value.rx.value());
wpi::PackStruct<32>(data, value.ry.value());
wpi::PackStruct<40>(data, value.rz.value());
}
};
template <>
struct WPILIB_DLLEXPORT wpi::Protobuf<frc::Twist3d> {
static constexpr std::string_view kTypeString = "proto: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);
};

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;
}