Class MotionProfile
- Direct Known Subclasses:
AsymmetricTrapezoidProfile
A motion profile provides a trajectory, most often used as the setpoint for a PID (or similar) controller.
This can be useful to avoid control effort saturation, or to decrease the initial large input from a PID's P term. Can also be useful to remain within physical constraints of a mechanism.
This class only contains constructors out of user-defined and user-calculated phases, but
AsymmetricTrapezoidProfile and TrapezoidProfile extend this to create profiles
out of constraints and desired states.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classHolds the velocity and position states of a MotionProfile at a time in its span. -
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedMotionProfile(MotionProfile.State initialState) Constructs a MotionProfile with no phases and a defined initial state.MotionProfile(MotionProfile.State initialState, ProfilePhase... phases) Constructs a MotionProfile with arbitrary phases.MotionProfile(ProfilePhase... phases) Constructs a MotionProfile of arbitrary phases with an initial state of zero displacement and zero velocity. -
Method Summary
Modifier and TypeMethodDescriptioncalculate(double time) Calculates the current State of the profile at a given time.Gets all the phases in the profile.booleanisFinished(double time) Returns true if the provided time is greater than the length of the profile.doubleReturns the total timespan of the profile.
-
Field Details
-
phases
-
initialState
-
-
Constructor Details
-
MotionProfile
Constructs a MotionProfile with arbitrary phases.- Parameters:
initialState- The initial state of the motion profile.phases- The ProfilePhases of the motion profile.
-
MotionProfile
Constructs a MotionProfile with no phases and a defined initial state.This constructor is protected because it encourages users to create empty profiles and then add phases to the (also protected)
phases, when this can cause undefined behavior. This needs to exist, however, for certain subclasses of this to work properly.- Parameters:
initialState- The initial state of the motion profile.
-
MotionProfile
Constructs a MotionProfile of arbitrary phases with an initial state of zero displacement and zero velocity.- Parameters:
phases- The ProfilePhases of the profile.
-
-
Method Details
-
getPhases
Gets all the phases in the profile.- Returns:
- An ordered list of ProfilePhases.
-
totalTime
public double totalTime()Returns the total timespan of the profile.- Returns:
- The duration of the profile, in seconds.
-
isFinished
public boolean isFinished(double time) Returns true if the provided time is greater than the length of the profile.- Parameters:
time- The time since the beginning of the profile, in seconds.- Returns:
- True if the profile has finished all its phases.
-
calculate
Calculates the current State of the profile at a given time.If the time sampled is less than 0, returns a State of 0 position and velocity. If it is greater than the timespan of the profile, returns a State of the aggregated position and zero velocity.
- Parameters:
time- The time since the beginning of the profile.- Returns:
- The position and velocity of the profile at that time.
-