[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:
PJ Reiniger
2023-11-21 13:14:06 -05:00
committed by GitHub
parent 35744a036e
commit bb05e20247
158 changed files with 4266 additions and 4 deletions

View File

@@ -11,6 +11,8 @@ import static edu.wpi.first.units.Units.Seconds;
import edu.wpi.first.math.geometry.Pose2d;
import edu.wpi.first.math.geometry.Rotation2d;
import edu.wpi.first.math.geometry.Translation2d;
import edu.wpi.first.math.kinematics.proto.ChassisSpeedsProto;
import edu.wpi.first.math.kinematics.struct.ChassisSpeedsStruct;
import edu.wpi.first.units.Angle;
import edu.wpi.first.units.Distance;
import edu.wpi.first.units.Measure;
@@ -36,6 +38,9 @@ public class ChassisSpeeds {
/** Represents the angular velocity of the robot frame. (CCW is +) */
public double omegaRadiansPerSecond;
public static final ChassisSpeedsProto proto = new ChassisSpeedsProto();
public static final ChassisSpeedsStruct struct = new ChassisSpeedsStruct();
/** Constructs a ChassisSpeeds with zeros for dx, dy, and theta. */
public ChassisSpeeds() {}

View File

@@ -9,6 +9,8 @@ import static edu.wpi.first.units.Units.Meters;
import edu.wpi.first.math.MathSharedStore;
import edu.wpi.first.math.MathUsageId;
import edu.wpi.first.math.geometry.Twist2d;
import edu.wpi.first.math.kinematics.proto.DifferentialDriveKinematicsProto;
import edu.wpi.first.math.kinematics.struct.DifferentialDriveKinematicsStruct;
import edu.wpi.first.units.Distance;
import edu.wpi.first.units.Measure;
@@ -24,6 +26,11 @@ public class DifferentialDriveKinematics
implements Kinematics<DifferentialDriveWheelSpeeds, DifferentialDriveWheelPositions> {
public final double trackWidthMeters;
public static final DifferentialDriveKinematicsProto proto =
new DifferentialDriveKinematicsProto();
public static final DifferentialDriveKinematicsStruct struct =
new DifferentialDriveKinematicsStruct();
/**
* Constructs a differential drive kinematics object.
*

View File

@@ -6,6 +6,8 @@ package edu.wpi.first.math.kinematics;
import static edu.wpi.first.units.Units.MetersPerSecond;
import edu.wpi.first.math.kinematics.proto.DifferentialDriveWheelSpeedsProto;
import edu.wpi.first.math.kinematics.struct.DifferentialDriveWheelSpeedsStruct;
import edu.wpi.first.units.Distance;
import edu.wpi.first.units.Measure;
import edu.wpi.first.units.Velocity;
@@ -18,6 +20,11 @@ public class DifferentialDriveWheelSpeeds {
/** Speed of the right side of the robot. */
public double rightMetersPerSecond;
public static final DifferentialDriveWheelSpeedsProto proto =
new DifferentialDriveWheelSpeedsProto();
public static final DifferentialDriveWheelSpeedsStruct struct =
new DifferentialDriveWheelSpeedsStruct();
/** Constructs a DifferentialDriveWheelSpeeds with zeros for left and right speeds. */
public DifferentialDriveWheelSpeeds() {}

View File

@@ -8,6 +8,8 @@ import edu.wpi.first.math.MathSharedStore;
import edu.wpi.first.math.MathUsageId;
import edu.wpi.first.math.geometry.Translation2d;
import edu.wpi.first.math.geometry.Twist2d;
import edu.wpi.first.math.kinematics.proto.MecanumDriveKinematicsProto;
import edu.wpi.first.math.kinematics.struct.MecanumDriveKinematicsStruct;
import org.ejml.simple.SimpleMatrix;
/**
@@ -42,6 +44,9 @@ public class MecanumDriveKinematics
private Translation2d m_prevCoR = new Translation2d();
public static final MecanumDriveKinematicsProto proto = new MecanumDriveKinematicsProto();
public static final MecanumDriveKinematicsStruct struct = new MecanumDriveKinematicsStruct();
/**
* Constructs a mecanum drive kinematics object.
*
@@ -207,4 +212,20 @@ public class MecanumDriveKinematics
m_inverseKinematics.setRow(2, 0, 1, 1, rl.getX() - rl.getY());
m_inverseKinematics.setRow(3, 0, 1, -1, -(rr.getX() + rr.getY()));
}
public Translation2d getFrontLeft() {
return m_frontLeftWheelMeters;
}
public Translation2d getFrontRight() {
return m_frontRightWheelMeters;
}
public Translation2d getRearLeft() {
return m_rearLeftWheelMeters;
}
public Translation2d getRearRight() {
return m_rearRightWheelMeters;
}
}

View File

@@ -7,6 +7,8 @@ package edu.wpi.first.math.kinematics;
import static edu.wpi.first.units.Units.Meters;
import edu.wpi.first.math.MathUtil;
import edu.wpi.first.math.kinematics.proto.MecanumDriveWheelPositionsProto;
import edu.wpi.first.math.kinematics.struct.MecanumDriveWheelPositionsStruct;
import edu.wpi.first.units.Distance;
import edu.wpi.first.units.Measure;
import java.util.Objects;
@@ -24,6 +26,10 @@ public class MecanumDriveWheelPositions implements WheelPositions<MecanumDriveWh
/** Distance measured by the rear right wheel. */
public double rearRightMeters;
public static final MecanumDriveWheelPositionsStruct struct =
new MecanumDriveWheelPositionsStruct();
public static final MecanumDriveWheelPositionsProto proto = new MecanumDriveWheelPositionsProto();
/** Constructs a MecanumDriveWheelPositions with zeros for all member fields. */
public MecanumDriveWheelPositions() {}

View File

@@ -6,6 +6,8 @@ package edu.wpi.first.math.kinematics;
import static edu.wpi.first.units.Units.MetersPerSecond;
import edu.wpi.first.math.kinematics.proto.MecanumDriveWheelSpeedsProto;
import edu.wpi.first.math.kinematics.struct.MecanumDriveWheelSpeedsStruct;
import edu.wpi.first.units.Distance;
import edu.wpi.first.units.Measure;
import edu.wpi.first.units.Velocity;
@@ -24,6 +26,9 @@ public class MecanumDriveWheelSpeeds {
/** Speed of the rear right wheel. */
public double rearRightMetersPerSecond;
public static final MecanumDriveWheelSpeedsStruct struct = new MecanumDriveWheelSpeedsStruct();
public static final MecanumDriveWheelSpeedsProto proto = new MecanumDriveWheelSpeedsProto();
/** Constructs a MecanumDriveWheelSpeeds with zeros for all member fields. */
public MecanumDriveWheelSpeeds() {}

View File

@@ -9,6 +9,8 @@ import static edu.wpi.first.units.Units.Meters;
import edu.wpi.first.math.MathUtil;
import edu.wpi.first.math.geometry.Rotation2d;
import edu.wpi.first.math.interpolation.Interpolatable;
import edu.wpi.first.math.kinematics.proto.SwerveModulePositionProto;
import edu.wpi.first.math.kinematics.struct.SwerveModulePositionStruct;
import edu.wpi.first.units.Distance;
import edu.wpi.first.units.Measure;
import java.util.Objects;
@@ -22,6 +24,9 @@ public class SwerveModulePosition
/** Angle of the module. */
public Rotation2d angle = Rotation2d.fromDegrees(0);
public static final SwerveModulePositionStruct struct = new SwerveModulePositionStruct();
public static final SwerveModulePositionProto proto = new SwerveModulePositionProto();
/** Constructs a SwerveModulePosition with zeros for distance and angle. */
public SwerveModulePosition() {}

View File

@@ -7,6 +7,8 @@ package edu.wpi.first.math.kinematics;
import static edu.wpi.first.units.Units.MetersPerSecond;
import edu.wpi.first.math.geometry.Rotation2d;
import edu.wpi.first.math.kinematics.proto.SwerveModuleStateProto;
import edu.wpi.first.math.kinematics.struct.SwerveModuleStateStruct;
import edu.wpi.first.units.Distance;
import edu.wpi.first.units.Measure;
import edu.wpi.first.units.Velocity;
@@ -20,6 +22,9 @@ public class SwerveModuleState implements Comparable<SwerveModuleState> {
/** Angle of the module. */
public Rotation2d angle = Rotation2d.fromDegrees(0);
public static final SwerveModuleStateStruct struct = new SwerveModuleStateStruct();
public static final SwerveModuleStateProto proto = new SwerveModuleStateProto();
/** Constructs a SwerveModuleState with zeros for speed and angle. */
public SwerveModuleState() {}

View File

@@ -0,0 +1,39 @@
// 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.
package edu.wpi.first.math.kinematics.proto;
import edu.wpi.first.math.kinematics.ChassisSpeeds;
import edu.wpi.first.math.proto.Kinematics.ProtobufChassisSpeeds;
import edu.wpi.first.util.protobuf.Protobuf;
import us.hebi.quickbuf.Descriptors.Descriptor;
public class ChassisSpeedsProto implements Protobuf<ChassisSpeeds, ProtobufChassisSpeeds> {
@Override
public Class<ChassisSpeeds> getTypeClass() {
return ChassisSpeeds.class;
}
@Override
public Descriptor getDescriptor() {
return ProtobufChassisSpeeds.getDescriptor();
}
@Override
public ProtobufChassisSpeeds createMessage() {
return ProtobufChassisSpeeds.newInstance();
}
@Override
public ChassisSpeeds unpack(ProtobufChassisSpeeds msg) {
return new ChassisSpeeds(msg.getVx(), msg.getVy(), msg.getOmega());
}
@Override
public void pack(ProtobufChassisSpeeds msg, ChassisSpeeds value) {
msg.setVx(value.vxMetersPerSecond);
msg.setVy(value.vyMetersPerSecond);
msg.setOmega(value.omegaRadiansPerSecond);
}
}

View File

@@ -0,0 +1,38 @@
// 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.
package edu.wpi.first.math.kinematics.proto;
import edu.wpi.first.math.kinematics.DifferentialDriveKinematics;
import edu.wpi.first.math.proto.Kinematics.ProtobufDifferentialDriveKinematics;
import edu.wpi.first.util.protobuf.Protobuf;
import us.hebi.quickbuf.Descriptors.Descriptor;
public class DifferentialDriveKinematicsProto
implements Protobuf<DifferentialDriveKinematics, ProtobufDifferentialDriveKinematics> {
@Override
public Class<DifferentialDriveKinematics> getTypeClass() {
return DifferentialDriveKinematics.class;
}
@Override
public Descriptor getDescriptor() {
return ProtobufDifferentialDriveKinematics.getDescriptor();
}
@Override
public ProtobufDifferentialDriveKinematics createMessage() {
return ProtobufDifferentialDriveKinematics.newInstance();
}
@Override
public DifferentialDriveKinematics unpack(ProtobufDifferentialDriveKinematics msg) {
return new DifferentialDriveKinematics(msg.getTrackWidth());
}
@Override
public void pack(ProtobufDifferentialDriveKinematics msg, DifferentialDriveKinematics value) {
msg.setTrackWidth(value.trackWidthMeters);
}
}

View File

@@ -0,0 +1,39 @@
// 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.
package edu.wpi.first.math.kinematics.proto;
import edu.wpi.first.math.kinematics.DifferentialDriveWheelSpeeds;
import edu.wpi.first.math.proto.Kinematics.ProtobufDifferentialDriveWheelSpeeds;
import edu.wpi.first.util.protobuf.Protobuf;
import us.hebi.quickbuf.Descriptors.Descriptor;
public class DifferentialDriveWheelSpeedsProto
implements Protobuf<DifferentialDriveWheelSpeeds, ProtobufDifferentialDriveWheelSpeeds> {
@Override
public Class<DifferentialDriveWheelSpeeds> getTypeClass() {
return DifferentialDriveWheelSpeeds.class;
}
@Override
public Descriptor getDescriptor() {
return ProtobufDifferentialDriveWheelSpeeds.getDescriptor();
}
@Override
public ProtobufDifferentialDriveWheelSpeeds createMessage() {
return ProtobufDifferentialDriveWheelSpeeds.newInstance();
}
@Override
public DifferentialDriveWheelSpeeds unpack(ProtobufDifferentialDriveWheelSpeeds msg) {
return new DifferentialDriveWheelSpeeds(msg.getLeft(), msg.getRight());
}
@Override
public void pack(ProtobufDifferentialDriveWheelSpeeds msg, DifferentialDriveWheelSpeeds value) {
msg.setLeft(value.leftMetersPerSecond);
msg.setRight(value.rightMetersPerSecond);
}
}

View File

@@ -0,0 +1,51 @@
// 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.
package edu.wpi.first.math.kinematics.proto;
import edu.wpi.first.math.geometry.Translation2d;
import edu.wpi.first.math.kinematics.MecanumDriveKinematics;
import edu.wpi.first.math.proto.Kinematics.ProtobufMecanumDriveKinematics;
import edu.wpi.first.util.protobuf.Protobuf;
import us.hebi.quickbuf.Descriptors.Descriptor;
public class MecanumDriveKinematicsProto
implements Protobuf<MecanumDriveKinematics, ProtobufMecanumDriveKinematics> {
@Override
public Class<MecanumDriveKinematics> getTypeClass() {
return MecanumDriveKinematics.class;
}
@Override
public Descriptor getDescriptor() {
return ProtobufMecanumDriveKinematics.getDescriptor();
}
@Override
public Protobuf<?, ?>[] getNested() {
return new Protobuf<?, ?>[] {Translation2d.proto};
}
@Override
public ProtobufMecanumDriveKinematics createMessage() {
return ProtobufMecanumDriveKinematics.newInstance();
}
@Override
public MecanumDriveKinematics unpack(ProtobufMecanumDriveKinematics msg) {
return new MecanumDriveKinematics(
Translation2d.proto.unpack(msg.getFrontLeft()),
Translation2d.proto.unpack(msg.getFrontRight()),
Translation2d.proto.unpack(msg.getRearLeft()),
Translation2d.proto.unpack(msg.getRearRight()));
}
@Override
public void pack(ProtobufMecanumDriveKinematics msg, MecanumDriveKinematics value) {
Translation2d.proto.pack(msg.getMutableFrontLeft(), value.getFrontLeft());
Translation2d.proto.pack(msg.getMutableFrontRight(), value.getFrontRight());
Translation2d.proto.pack(msg.getMutableRearLeft(), value.getRearLeft());
Translation2d.proto.pack(msg.getMutableRearRight(), value.getRearRight());
}
}

View File

@@ -0,0 +1,42 @@
// 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.
package edu.wpi.first.math.kinematics.proto;
import edu.wpi.first.math.kinematics.MecanumDriveWheelPositions;
import edu.wpi.first.math.proto.Kinematics.ProtobufMecanumDriveWheelPositions;
import edu.wpi.first.util.protobuf.Protobuf;
import us.hebi.quickbuf.Descriptors.Descriptor;
public class MecanumDriveWheelPositionsProto
implements Protobuf<MecanumDriveWheelPositions, ProtobufMecanumDriveWheelPositions> {
@Override
public Class<MecanumDriveWheelPositions> getTypeClass() {
return MecanumDriveWheelPositions.class;
}
@Override
public Descriptor getDescriptor() {
return ProtobufMecanumDriveWheelPositions.getDescriptor();
}
@Override
public ProtobufMecanumDriveWheelPositions createMessage() {
return ProtobufMecanumDriveWheelPositions.newInstance();
}
@Override
public MecanumDriveWheelPositions unpack(ProtobufMecanumDriveWheelPositions msg) {
return new MecanumDriveWheelPositions(
msg.getFrontLeft(), msg.getFrontRight(), msg.getRearLeft(), msg.getRearRight());
}
@Override
public void pack(ProtobufMecanumDriveWheelPositions msg, MecanumDriveWheelPositions value) {
msg.setFrontLeft(value.frontLeftMeters);
msg.setFrontRight(value.frontRightMeters);
msg.setRearLeft(value.rearLeftMeters);
msg.setRearRight(value.rearRightMeters);
}
}

View File

@@ -0,0 +1,42 @@
// 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.
package edu.wpi.first.math.kinematics.proto;
import edu.wpi.first.math.kinematics.MecanumDriveWheelSpeeds;
import edu.wpi.first.math.proto.Kinematics.ProtobufMecanumDriveWheelSpeeds;
import edu.wpi.first.util.protobuf.Protobuf;
import us.hebi.quickbuf.Descriptors.Descriptor;
public class MecanumDriveWheelSpeedsProto
implements Protobuf<MecanumDriveWheelSpeeds, ProtobufMecanumDriveWheelSpeeds> {
@Override
public Class<MecanumDriveWheelSpeeds> getTypeClass() {
return MecanumDriveWheelSpeeds.class;
}
@Override
public Descriptor getDescriptor() {
return ProtobufMecanumDriveWheelSpeeds.getDescriptor();
}
@Override
public ProtobufMecanumDriveWheelSpeeds createMessage() {
return ProtobufMecanumDriveWheelSpeeds.newInstance();
}
@Override
public MecanumDriveWheelSpeeds unpack(ProtobufMecanumDriveWheelSpeeds msg) {
return new MecanumDriveWheelSpeeds(
msg.getFrontLeft(), msg.getFrontRight(), msg.getRearLeft(), msg.getRearRight());
}
@Override
public void pack(ProtobufMecanumDriveWheelSpeeds msg, MecanumDriveWheelSpeeds value) {
msg.setFrontLeft(value.frontLeftMetersPerSecond);
msg.setFrontRight(value.frontRightMetersPerSecond);
msg.setRearLeft(value.rearLeftMetersPerSecond);
msg.setRearRight(value.rearRightMetersPerSecond);
}
}

View File

@@ -0,0 +1,45 @@
// 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.
package edu.wpi.first.math.kinematics.proto;
import edu.wpi.first.math.geometry.Rotation2d;
import edu.wpi.first.math.kinematics.SwerveModulePosition;
import edu.wpi.first.math.proto.Kinematics.ProtobufSwerveModulePosition;
import edu.wpi.first.util.protobuf.Protobuf;
import us.hebi.quickbuf.Descriptors.Descriptor;
public class SwerveModulePositionProto
implements Protobuf<SwerveModulePosition, ProtobufSwerveModulePosition> {
@Override
public Class<SwerveModulePosition> getTypeClass() {
return SwerveModulePosition.class;
}
@Override
public Descriptor getDescriptor() {
return ProtobufSwerveModulePosition.getDescriptor();
}
@Override
public Protobuf<?, ?>[] getNested() {
return new Protobuf<?, ?>[] {Rotation2d.proto};
}
@Override
public ProtobufSwerveModulePosition createMessage() {
return ProtobufSwerveModulePosition.newInstance();
}
@Override
public SwerveModulePosition unpack(ProtobufSwerveModulePosition msg) {
return new SwerveModulePosition(msg.getDistance(), Rotation2d.proto.unpack(msg.getAngle()));
}
@Override
public void pack(ProtobufSwerveModulePosition msg, SwerveModulePosition value) {
msg.setDistance(value.distanceMeters);
Rotation2d.proto.pack(msg.getMutableAngle(), value.angle);
}
}

View File

@@ -0,0 +1,45 @@
// 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.
package edu.wpi.first.math.kinematics.proto;
import edu.wpi.first.math.geometry.Rotation2d;
import edu.wpi.first.math.kinematics.SwerveModuleState;
import edu.wpi.first.math.proto.Kinematics.ProtobufSwerveModuleState;
import edu.wpi.first.util.protobuf.Protobuf;
import us.hebi.quickbuf.Descriptors.Descriptor;
public class SwerveModuleStateProto
implements Protobuf<SwerveModuleState, ProtobufSwerveModuleState> {
@Override
public Class<SwerveModuleState> getTypeClass() {
return SwerveModuleState.class;
}
@Override
public Descriptor getDescriptor() {
return ProtobufSwerveModuleState.getDescriptor();
}
@Override
public Protobuf<?, ?>[] getNested() {
return new Protobuf<?, ?>[] {Rotation2d.proto};
}
@Override
public ProtobufSwerveModuleState createMessage() {
return ProtobufSwerveModuleState.newInstance();
}
@Override
public SwerveModuleState unpack(ProtobufSwerveModuleState msg) {
return new SwerveModuleState(msg.getSpeed(), Rotation2d.proto.unpack(msg.getAngle()));
}
@Override
public void pack(ProtobufSwerveModuleState msg, SwerveModuleState value) {
msg.setSpeed(value.speedMetersPerSecond);
Rotation2d.proto.pack(msg.getMutableAngle(), value.angle);
}
}

View File

@@ -0,0 +1,46 @@
// 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.
package edu.wpi.first.math.kinematics.struct;
import edu.wpi.first.math.kinematics.ChassisSpeeds;
import edu.wpi.first.util.struct.Struct;
import java.nio.ByteBuffer;
public class ChassisSpeedsStruct implements Struct<ChassisSpeeds> {
@Override
public Class<ChassisSpeeds> getTypeClass() {
return ChassisSpeeds.class;
}
@Override
public String getTypeString() {
return "struct:ChassisSpeeds";
}
@Override
public int getSize() {
return kSizeDouble * 3;
}
@Override
public String getSchema() {
return "double vx;double vy;double omega";
}
@Override
public ChassisSpeeds unpack(ByteBuffer bb) {
double vx = bb.getDouble();
double vy = bb.getDouble();
double omega = bb.getDouble();
return new ChassisSpeeds(vx, vy, omega);
}
@Override
public void pack(ByteBuffer bb, ChassisSpeeds value) {
bb.putDouble(value.vxMetersPerSecond);
bb.putDouble(value.vyMetersPerSecond);
bb.putDouble(value.omegaRadiansPerSecond);
}
}

View File

@@ -0,0 +1,42 @@
// 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.
package edu.wpi.first.math.kinematics.struct;
import edu.wpi.first.math.kinematics.DifferentialDriveKinematics;
import edu.wpi.first.util.struct.Struct;
import java.nio.ByteBuffer;
public class DifferentialDriveKinematicsStruct implements Struct<DifferentialDriveKinematics> {
@Override
public Class<DifferentialDriveKinematics> getTypeClass() {
return DifferentialDriveKinematics.class;
}
@Override
public String getTypeString() {
return "struct:DifferentialDriveKinematics";
}
@Override
public int getSize() {
return kSizeDouble;
}
@Override
public String getSchema() {
return "double track_width";
}
@Override
public DifferentialDriveKinematics unpack(ByteBuffer bb) {
double trackWidth = bb.getDouble();
return new DifferentialDriveKinematics(trackWidth);
}
@Override
public void pack(ByteBuffer bb, DifferentialDriveKinematics value) {
bb.putDouble(value.trackWidthMeters);
}
}

View File

@@ -0,0 +1,44 @@
// 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.
package edu.wpi.first.math.kinematics.struct;
import edu.wpi.first.math.kinematics.DifferentialDriveWheelSpeeds;
import edu.wpi.first.util.struct.Struct;
import java.nio.ByteBuffer;
public class DifferentialDriveWheelSpeedsStruct implements Struct<DifferentialDriveWheelSpeeds> {
@Override
public Class<DifferentialDriveWheelSpeeds> getTypeClass() {
return DifferentialDriveWheelSpeeds.class;
}
@Override
public String getTypeString() {
return "struct:DifferentialDriveWheelSpeeds";
}
@Override
public int getSize() {
return kSizeDouble * 2;
}
@Override
public String getSchema() {
return "double left;double right";
}
@Override
public DifferentialDriveWheelSpeeds unpack(ByteBuffer bb) {
double left = bb.getDouble();
double right = bb.getDouble();
return new DifferentialDriveWheelSpeeds(left, right);
}
@Override
public void pack(ByteBuffer bb, DifferentialDriveWheelSpeeds value) {
bb.putDouble(value.leftMetersPerSecond);
bb.putDouble(value.rightMetersPerSecond);
}
}

View File

@@ -0,0 +1,55 @@
// 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.
package edu.wpi.first.math.kinematics.struct;
import edu.wpi.first.math.geometry.Translation2d;
import edu.wpi.first.math.kinematics.MecanumDriveKinematics;
import edu.wpi.first.util.struct.Struct;
import java.nio.ByteBuffer;
public class MecanumDriveKinematicsStruct implements Struct<MecanumDriveKinematics> {
@Override
public Class<MecanumDriveKinematics> getTypeClass() {
return MecanumDriveKinematics.class;
}
@Override
public String getTypeString() {
return "struct:MecanumDriveKinematics";
}
@Override
public int getSize() {
return 4 * Translation2d.struct.getSize();
}
@Override
public String getSchema() {
return "Translation2d front_left;Translation2d front_right;Translation2d rear_left;"
+ "Translation2d rear_right";
}
@Override
public Struct<?>[] getNested() {
return new Struct<?>[] {Translation2d.struct};
}
@Override
public MecanumDriveKinematics unpack(ByteBuffer bb) {
Translation2d frontLeft = Translation2d.struct.unpack(bb);
Translation2d frontRight = Translation2d.struct.unpack(bb);
Translation2d rearLeft = Translation2d.struct.unpack(bb);
Translation2d rearRight = Translation2d.struct.unpack(bb);
return new MecanumDriveKinematics(frontLeft, frontRight, rearLeft, rearRight);
}
@Override
public void pack(ByteBuffer bb, MecanumDriveKinematics value) {
Translation2d.struct.pack(bb, value.getFrontLeft());
Translation2d.struct.pack(bb, value.getFrontRight());
Translation2d.struct.pack(bb, value.getRearLeft());
Translation2d.struct.pack(bb, value.getRearRight());
}
}

View File

@@ -0,0 +1,48 @@
// 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.
package edu.wpi.first.math.kinematics.struct;
import edu.wpi.first.math.kinematics.MecanumDriveWheelPositions;
import edu.wpi.first.util.struct.Struct;
import java.nio.ByteBuffer;
public class MecanumDriveWheelPositionsStruct implements Struct<MecanumDriveWheelPositions> {
@Override
public Class<MecanumDriveWheelPositions> getTypeClass() {
return MecanumDriveWheelPositions.class;
}
@Override
public String getTypeString() {
return "struct:MecanumDriveWheelPositions";
}
@Override
public int getSize() {
return kSizeDouble * 4;
}
@Override
public String getSchema() {
return "double front_left;double front_right;double rear_left;double rear_right";
}
@Override
public MecanumDriveWheelPositions unpack(ByteBuffer bb) {
double frontLeft = bb.getDouble();
double frontRight = bb.getDouble();
double rearLeft = bb.getDouble();
double rearRight = bb.getDouble();
return new MecanumDriveWheelPositions(frontLeft, frontRight, rearLeft, rearRight);
}
@Override
public void pack(ByteBuffer bb, MecanumDriveWheelPositions value) {
bb.putDouble(value.frontLeftMeters);
bb.putDouble(value.frontRightMeters);
bb.putDouble(value.rearLeftMeters);
bb.putDouble(value.rearRightMeters);
}
}

View File

@@ -0,0 +1,48 @@
// 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.
package edu.wpi.first.math.kinematics.struct;
import edu.wpi.first.math.kinematics.MecanumDriveWheelSpeeds;
import edu.wpi.first.util.struct.Struct;
import java.nio.ByteBuffer;
public class MecanumDriveWheelSpeedsStruct implements Struct<MecanumDriveWheelSpeeds> {
@Override
public Class<MecanumDriveWheelSpeeds> getTypeClass() {
return MecanumDriveWheelSpeeds.class;
}
@Override
public String getTypeString() {
return "struct:MecanumDriveWheelSpeeds";
}
@Override
public int getSize() {
return kSizeDouble * 4;
}
@Override
public String getSchema() {
return "double front_left;double front_right;double rear_left;double rear_right";
}
@Override
public MecanumDriveWheelSpeeds unpack(ByteBuffer bb) {
double frontLeft = bb.getDouble();
double frontRight = bb.getDouble();
double rearLeft = bb.getDouble();
double rearRight = bb.getDouble();
return new MecanumDriveWheelSpeeds(frontLeft, frontRight, rearLeft, rearRight);
}
@Override
public void pack(ByteBuffer bb, MecanumDriveWheelSpeeds value) {
bb.putDouble(value.frontLeftMetersPerSecond);
bb.putDouble(value.frontRightMetersPerSecond);
bb.putDouble(value.rearLeftMetersPerSecond);
bb.putDouble(value.rearRightMetersPerSecond);
}
}

View File

@@ -0,0 +1,50 @@
// 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.
package edu.wpi.first.math.kinematics.struct;
import edu.wpi.first.math.geometry.Rotation2d;
import edu.wpi.first.math.kinematics.SwerveModulePosition;
import edu.wpi.first.util.struct.Struct;
import java.nio.ByteBuffer;
public class SwerveModulePositionStruct implements Struct<SwerveModulePosition> {
@Override
public Class<SwerveModulePosition> getTypeClass() {
return SwerveModulePosition.class;
}
@Override
public String getTypeString() {
return "struct:SwerveModulePosition";
}
@Override
public int getSize() {
return kSizeDouble + Rotation2d.struct.getSize();
}
@Override
public String getSchema() {
return "double distance;Rotation2d angle";
}
@Override
public Struct<?>[] getNested() {
return new Struct<?>[] {Rotation2d.struct};
}
@Override
public SwerveModulePosition unpack(ByteBuffer bb) {
double distance = bb.getDouble();
Rotation2d angle = Rotation2d.struct.unpack(bb);
return new SwerveModulePosition(distance, angle);
}
@Override
public void pack(ByteBuffer bb, SwerveModulePosition value) {
bb.putDouble(value.distanceMeters);
Rotation2d.struct.pack(bb, value.angle);
}
}

View File

@@ -0,0 +1,50 @@
// 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.
package edu.wpi.first.math.kinematics.struct;
import edu.wpi.first.math.geometry.Rotation2d;
import edu.wpi.first.math.kinematics.SwerveModuleState;
import edu.wpi.first.util.struct.Struct;
import java.nio.ByteBuffer;
public class SwerveModuleStateStruct implements Struct<SwerveModuleState> {
@Override
public Class<SwerveModuleState> getTypeClass() {
return SwerveModuleState.class;
}
@Override
public String getTypeString() {
return "struct:SwerveModuleState";
}
@Override
public int getSize() {
return kSizeDouble + Rotation2d.struct.getSize();
}
@Override
public String getSchema() {
return "double speed;Rotation2d angle";
}
@Override
public Struct<?>[] getNested() {
return new Struct<?>[] {Rotation2d.struct};
}
@Override
public SwerveModuleState unpack(ByteBuffer bb) {
double speed = bb.getDouble();
Rotation2d angle = Rotation2d.struct.unpack(bb);
return new SwerveModuleState(speed, angle);
}
@Override
public void pack(ByteBuffer bb, SwerveModuleState value) {
bb.putDouble(value.speedMetersPerSecond);
Rotation2d.struct.pack(bb, value.angle);
}
}