Class MotionProfile

  • Direct Known Subclasses:
    AsymmetricTrapezoidProfile

    public class MotionProfile
    extends java.lang.Object
    A group of ProfilePhases that represents an arbitrary trajectory of compound accelerations, coasts, and decelerations.

    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 Classes 
      Modifier and Type Class Description
      static class  MotionProfile.State
      Holds the velocity and position states of a MotionProfile at a time in its span.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      MotionProfile.State calculate​(double time)
      Calculates the current State of the profile at a given time.
      java.util.List<ProfilePhase> getPhases()
      Gets all the phases in the profile.
      boolean isFinished​(double time)
      Returns true if the provided time is greater than the length of the profile.
      double totalTime()
      Returns the total timespan of the profile.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • MotionProfile

        public MotionProfile​(MotionProfile.State initialState,
                             ProfilePhase... phases)
        Constructs a MotionProfile with arbitrary phases.
        Parameters:
        initialState - The initial state of the motion profile.
        phases - The ProfilePhases of the motion profile.
      • MotionProfile

        protected MotionProfile​(MotionProfile.State initialState)
        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

        public MotionProfile​(ProfilePhase... phases)
        Constructs a MotionProfile of arbitrary phases with an initial state of zero displacement and zero velocity.
        Parameters:
        phases - The ProfilePhases of the profile.
    • Method Detail

      • getPhases

        public java.util.List<ProfilePhase> 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

        public MotionProfile.State calculate​(double time)
        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.