Skip to content

Commit

Permalink
[wpimath] Clean up profile classes (wpilibsuite#6311)
Browse files Browse the repository at this point in the history
* Reorder functions so they match between languages
* Copy more complete JavaDocs to C++
* Fix incorrect description for time parameter of
  TrapezoidProfile.calculate()
  • Loading branch information
calcmogul authored Jan 26, 2024
1 parent d895a0c commit 68736d8
Show file tree
Hide file tree
Showing 5 changed files with 159 additions and 87 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public static class Constraints {
public final double B;

/**
* Construct constraints for an ExponentialProfile.
* Constructs constraints for an ExponentialProfile.
*
* @param maxInput maximum unsigned input voltage
* @param A The State-Space 1x1 system matrix.
Expand All @@ -103,7 +103,7 @@ public double maxVelocity() {
}

/**
* Construct constraints for an ExponentialProfile from characteristics.
* Constructs constraints for an ExponentialProfile from characteristics.
*
* @param maxInput maximum unsigned input voltage
* @param kV The velocity gain.
Expand All @@ -115,7 +115,7 @@ public static Constraints fromCharacteristics(double maxInput, double kV, double
}

/**
* Construct constraints for an ExponentialProfile from State-Space parameters.
* Constructs constraints for an ExponentialProfile from State-Space parameters.
*
* @param maxInput maximum unsigned input voltage
* @param A The State-Space 1x1 system matrix.
Expand All @@ -139,7 +139,7 @@ public static class State {
public State() {}

/**
* Construct a state within an exponential profile.
* Constructs a state within an exponential profile.
*
* @param position The position at this state.
* @param velocity The velocity at this state.
Expand All @@ -166,7 +166,7 @@ public int hashCode() {
}

/**
* Construct an ExponentialProfile.
* Constructs an ExponentialProfile.
*
* @param constraints The constraints on the profile, like maximum input.
*/
Expand All @@ -175,10 +175,10 @@ public ExponentialProfile(Constraints constraints) {
}

/**
* Calculate the correct position and velocity for the profile at a time t where the current state
* is at time t = 0.
* Calculates the position and velocity for the profile at a time t where the current state is at
* time t = 0.
*
* @param t The time since the beginning of the profile.
* @param t How long to advance from the current state toward the desired state.
* @param current The current state.
* @param goal The desired state when the profile is complete.
* @return The position and velocity of the profile at time t.
Expand All @@ -205,7 +205,7 @@ public State calculate(double t, State current, State goal) {
}

/**
* Calculate the point after which the fastest way to reach the goal state is to apply input in
* Calculates the point after which the fastest way to reach the goal state is to apply input in
* the opposite direction.
*
* @param current The current state.
Expand All @@ -220,7 +220,7 @@ public State calculateInflectionPoint(State current, State goal) {
}

/**
* Calculate the point after which the fastest way to reach the goal state is to apply input in
* Calculates the point after which the fastest way to reach the goal state is to apply input in
* the opposite direction.
*
* @param current The current state.
Expand All @@ -242,7 +242,7 @@ private State calculateInflectionPoint(State current, State goal, double input)
}

/**
* Calculate the time it will take for this profile to reach the goal state.
* Calculates the time it will take for this profile to reach the goal state.
*
* @param current The current state.
* @param goal The desired state when the profile is complete.
Expand All @@ -255,8 +255,8 @@ public double timeLeftUntil(State current, State goal) {
}

/**
* Calculate the time it will take for this profile to reach the inflection point, and the time it
* will take for this profile to reach the goal state.
* Calculates the time it will take for this profile to reach the inflection point, and the time
* it will take for this profile to reach the goal state.
*
* @param current The current state.
* @param goal The desired state when the profile is complete.
Expand All @@ -271,8 +271,8 @@ public ProfileTiming calculateProfileTiming(State current, State goal) {
}

/**
* Calculate the time it will take for this profile to reach the inflection point, and the time it
* will take for this profile to reach the goal state.
* Calculates the time it will take for this profile to reach the inflection point, and the time
* it will take for this profile to reach the goal state.
*
* @param current The current state.
* @param inflectionPoint The inflection point of this profile.
Expand Down Expand Up @@ -332,7 +332,7 @@ private ProfileTiming calculateProfileTiming(
}

/**
* Calculate the position reached after t seconds when applying an input from the initial state.
* Calculates the position reached after t seconds when applying an input from the initial state.
*
* @param t The time since the initial state.
* @param input The signed input applied to this profile from the initial state.
Expand All @@ -349,7 +349,7 @@ private double computeDistanceFromTime(double t, double input, State initial) {
}

/**
* Calculate the velocity reached after t seconds when applying an input from the initial state.
* Calculates the velocity reached after t seconds when applying an input from the initial state.
*
* @param t The time since the initial state.
* @param input The signed input applied to this profile from the initial state.
Expand All @@ -365,7 +365,7 @@ private double computeVelocityFromTime(double t, double input, State initial) {
}

/**
* Calculate the time required to reach a specified velocity given the initial velocity.
* Calculates the time required to reach a specified velocity given the initial velocity.
*
* @param velocity The goal velocity.
* @param input The signed input applied to this profile from the initial state.
Expand All @@ -381,7 +381,7 @@ private double computeTimeFromVelocity(double velocity, double input, double ini
}

/**
* Calculate the distance reached at the same time as the given velocity when applying the given
* Calculates the distance reached at the same time as the given velocity when applying the given
* input from the initial state.
*
* @param velocity The velocity reached by this profile
Expand All @@ -400,7 +400,7 @@ private double computeDistanceFromVelocity(double velocity, double input, State
}

/**
* Calculate the velocity at which input should be reversed in order to reach the goal state from
* Calculates the velocity at which input should be reversed in order to reach the goal state from
* the current state.
*
* @param input The signed input applied to this profile from the current state.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public static class Constraints {
public final double maxAcceleration;

/**
* Construct constraints for a TrapezoidProfile.
* Constructs constraints for a TrapezoidProfile.
*
* @param maxVelocity maximum velocity
* @param maxAcceleration maximum acceleration
Expand All @@ -75,7 +75,7 @@ public Constraints(double maxVelocity, double maxAcceleration) {
}

/**
* Construct constraints for a TrapezoidProfile.
* Constructs constraints for a TrapezoidProfile.
*
* @param <U> Unit type.
* @param maxVelocity maximum velocity
Expand Down Expand Up @@ -137,7 +137,7 @@ public int hashCode() {
}

/**
* Construct a TrapezoidProfile.
* Constructs a TrapezoidProfile.
*
* @param constraints The constraints on the profile, like maximum velocity.
*/
Expand All @@ -147,7 +147,7 @@ public TrapezoidProfile(Constraints constraints) {
}

/**
* Construct a TrapezoidProfile.
* Constructs a TrapezoidProfile.
*
* @param constraints The constraints on the profile, like maximum velocity.
* @param goal The desired state when the profile is complete.
Expand Down Expand Up @@ -197,7 +197,7 @@ public TrapezoidProfile(Constraints constraints, State goal, State initial) {
}

/**
* Construct a TrapezoidProfile.
* Constructs a TrapezoidProfile.
*
* @param constraints The constraints on the profile, like maximum velocity.
* @param goal The desired state when the profile is complete.
Expand All @@ -210,10 +210,10 @@ public TrapezoidProfile(Constraints constraints, State goal) {
}

/**
* Calculate the correct position and velocity for the profile at a time t where the beginning of
* the profile was at time t = 0.
* Calculates the position and velocity for the profile at a time t where the current state is at
* time t = 0.
*
* @param t The time since the beginning of the profile.
* @param t How long to advance from the current state toward the desired state.
* @return The position and velocity of the profile at time t.
* @deprecated Pass the desired and current state into calculate instead of constructing a new
* TrapezoidProfile with the desired and current state
Expand Down Expand Up @@ -247,10 +247,10 @@ public State calculate(double t) {
}

/**
* Calculate the correct position and velocity for the profile at a time t where the beginning of
* the profile was at time t = 0.
* Calculates the position and velocity for the profile at a time t where the current state is at
* time t = 0.
*
* @param t The time since the beginning of the profile.
* @param t How long to advance from the current state toward the desired state.
* @param current The current state.
* @param goal The desired state when the profile is complete.
* @return The position and velocity of the profile at time t.
Expand Down
Loading

0 comments on commit 68736d8

Please sign in to comment.