[wpimath] Add structs for TrapezoidProfile.State and ExponentialProfile.State (#8163)

This commit is contained in:
Daniel Chen
2025-08-10 14:45:36 -04:00
committed by GitHub
parent 78fa67099e
commit f209ecb0cb
7 changed files with 145 additions and 1 deletions

View File

@@ -4,6 +4,8 @@
package edu.wpi.first.math.trajectory;
import edu.wpi.first.math.trajectory.struct.ExponentialProfileStateStruct;
import edu.wpi.first.util.struct.StructSerializable;
import java.util.Objects;
/**
@@ -128,7 +130,10 @@ public class ExponentialProfile {
}
/** Profile state. */
public static class State {
public static class State implements StructSerializable {
/** The struct that serializes this class. */
public static final ExponentialProfileStateStruct struct = new ExponentialProfileStateStruct();
/** The position at this state. */
public double position;

View File

@@ -6,6 +6,7 @@ package edu.wpi.first.math.trajectory;
import edu.wpi.first.math.MathSharedStore;
import edu.wpi.first.math.MathUsageId;
import edu.wpi.first.math.trajectory.struct.TrapezoidProfileStateStruct;
import java.util.Objects;
/**
@@ -76,6 +77,9 @@ public class TrapezoidProfile {
/** Profile state. */
public static class State {
/** The struct used to serialize this class. */
public static final TrapezoidProfileStateStruct struct = new TrapezoidProfileStateStruct();
/** The position at this state. */
public double position;

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.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<ExponentialProfile.State> {
@Override
public Class<ExponentialProfile.State> getTypeClass() {
return ExponentialProfile.State.class;
}
@Override
public String getTypeName() {
return "ExponentialProfileState";
}
@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);
}
}

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.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<TrapezoidProfile.State> {
@Override
public Class<TrapezoidProfile.State> getTypeClass() {
return TrapezoidProfile.State.class;
}
@Override
public String getTypeName() {
return "TrapezoidProfileState";
}
@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);
}
}