diff --git a/wpimath/src/main/java/edu/wpi/first/math/trajectory/ExponentialProfile.java b/wpimath/src/main/java/edu/wpi/first/math/trajectory/ExponentialProfile.java index db6f8f7a1cb..5deb7d1be88 100644 --- a/wpimath/src/main/java/edu/wpi/first/math/trajectory/ExponentialProfile.java +++ b/wpimath/src/main/java/edu/wpi/first/math/trajectory/ExponentialProfile.java @@ -4,6 +4,8 @@ package edu.wpi.first.math.trajectory; +import edu.wpi.first.math.trajectory.struct.ExponentialProfileStateStruct; + import java.util.Objects; /** @@ -129,6 +131,9 @@ public static Constraints fromStateSpace(double maxInput, double A, double B) { /** Profile state. */ public static class State { + /** The struct used for serializing this class. */ + public static final ExponentialProfileStateStruct struct = new ExponentialProfileStateStruct(); + /** The position at this state. */ public double position; diff --git a/wpimath/src/main/java/edu/wpi/first/math/trajectory/TrapezoidProfile.java b/wpimath/src/main/java/edu/wpi/first/math/trajectory/TrapezoidProfile.java index 448c8384cf9..cfcc5d86c92 100644 --- a/wpimath/src/main/java/edu/wpi/first/math/trajectory/TrapezoidProfile.java +++ b/wpimath/src/main/java/edu/wpi/first/math/trajectory/TrapezoidProfile.java @@ -6,6 +6,9 @@ import edu.wpi.first.math.MathSharedStore; import edu.wpi.first.math.MathUsageId; +import edu.wpi.first.math.trajectory.struct.TrapezoidProfileStateStruct; +import edu.wpi.first.util.struct.StructSerializable; + import java.util.Objects; /** @@ -71,7 +74,10 @@ public Constraints(double maxVelocity, double maxAcceleration) { } /** Profile state. */ - public static class State { + public static class State implements StructSerializable { + /** The struct used for serializing this class. */ + public static final TrapezoidProfileStateStruct struct = new TrapezoidProfileStateStruct(); + /** The position at this state. */ public double position; diff --git a/wpimath/src/main/java/edu/wpi/first/math/trajectory/struct/ExponentialProfileStateStruct.java b/wpimath/src/main/java/edu/wpi/first/math/trajectory/struct/ExponentialProfileStateStruct.java new file mode 100644 index 00000000000..ab3924afacd --- /dev/null +++ b/wpimath/src/main/java/edu/wpi/first/math/trajectory/struct/ExponentialProfileStateStruct.java @@ -0,0 +1,39 @@ +package edu.wpi.first.math.trajectory.struct; + +import edu.wpi.first.math.trajectory.ExponentialProfile; +import edu.wpi.first.util.struct.Struct; + +import java.nio.ByteBuffer; + +public class ExponentialProfileStateStruct implements Struct { + @Override + public Class getTypeClass() { + return ExponentialProfile.State.class; + } + + @Override + public String getTypeName() { + return "TrapezoidProfile.State"; + } + + @Override + public int getSize() { + return kSizeDouble * 2; + } + + @Override + public String getSchema() { + return "double position;double velocity"; + } + + @Override + public ExponentialProfile.State unpack(ByteBuffer bb) { + return new ExponentialProfile.State(bb.getDouble(), bb.getDouble()); + } + + @Override + public void pack(ByteBuffer bb, ExponentialProfile.State value) { + bb.putDouble(value.position); + bb.putDouble(value.velocity); + } +} diff --git a/wpimath/src/main/java/edu/wpi/first/math/trajectory/struct/TrapezoidProfileStateStruct.java b/wpimath/src/main/java/edu/wpi/first/math/trajectory/struct/TrapezoidProfileStateStruct.java new file mode 100644 index 00000000000..90b928d46ed --- /dev/null +++ b/wpimath/src/main/java/edu/wpi/first/math/trajectory/struct/TrapezoidProfileStateStruct.java @@ -0,0 +1,39 @@ +package edu.wpi.first.math.trajectory.struct; + +import edu.wpi.first.math.trajectory.TrapezoidProfile; +import edu.wpi.first.util.struct.Struct; + +import java.nio.ByteBuffer; + +public class TrapezoidProfileStateStruct implements Struct { + @Override + public Class getTypeClass() { + return TrapezoidProfile.State.class; + } + + @Override + public String getTypeName() { + return "TrapezoidProfile.State"; + } + + @Override + public int getSize() { + return kSizeDouble * 2; + } + + @Override + public String getSchema() { + return "double position;double velocity"; + } + + @Override + public TrapezoidProfile.State unpack(ByteBuffer bb) { + return new TrapezoidProfile.State(bb.getDouble(), bb.getDouble()); + } + + @Override + public void pack(ByteBuffer bb, TrapezoidProfile.State value) { + bb.putDouble(value.position); + bb.putDouble(value.velocity); + } +}