Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make TrapezoidProfile.State and ExponentialProfile.State implement StructSerializable #7720

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

package edu.wpi.first.math.trajectory;

import edu.wpi.first.math.trajectory.struct.ExponentialProfileStateStruct;

import java.util.Objects;

/**
Expand Down Expand Up @@ -129,6 +131,9 @@ public static Constraints fromStateSpace(double maxInput, double A, double B) {

/** Profile state. */
public static class State {
Daniel1464 marked this conversation as resolved.
Show resolved Hide resolved
/** The struct used for serializing this class. */
public static final ExponentialProfileStateStruct struct = new ExponentialProfileStateStruct();

/** The position at this state. */
public double position;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
@@ -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<ExponentialProfile.State> {
@Override
public Class<ExponentialProfile.State> getTypeClass() {
return ExponentialProfile.State.class;
}

@Override
public String getTypeName() {
return "TrapezoidProfile.State";
Daniel1464 marked this conversation as resolved.
Show resolved Hide resolved
}

@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);
}
}
Original file line number Diff line number Diff line change
@@ -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<TrapezoidProfile.State> {
@Override
public Class<TrapezoidProfile.State> getTypeClass() {
return TrapezoidProfile.State.class;
}

@Override
public String getTypeName() {
return "TrapezoidProfile.State";
Daniel1464 marked this conversation as resolved.
Show resolved Hide resolved
}

@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);
}
}
Loading