Skip to content

Commit

Permalink
Initial
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel1464 committed Jan 23, 2025
1 parent d86a2ec commit cd277f2
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 1 deletion.
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 {
/** 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";
}

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

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

0 comments on commit cd277f2

Please sign in to comment.