Class LinearPath

java.lang.Object
com.ctre.phoenix6.swerve.utility.LinearPath

public class LinearPath extends Object
A linear path for a holonomic drivetrain (i.e. swerve or mechanum). This generates profiled setpoints for the robot along a straight line based on trapezoidal velocity constraints (using TrapezoidProfile).

Initialization:


 final LinearPath path = new LinearPath(
     new TrapezoidProfile.Constraints(kMaxV, kMaxA),
     new TrapezoidProfile.Constraints(kMaxOmega, kMaxAlpha)
 );
 LinearPath.State current = new LinearPath.State(
     initialPose, initialFieldSpeeds
 );
 

Run on update:


 current = path.calculate(timeSincePreviousUpdate, current, targetPose);
 
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    Path state.
  • Constructor Summary

    Constructors
    Constructor
    Description
    LinearPath(edu.wpi.first.math.trajectory.TrapezoidProfile.Constraints linear, edu.wpi.first.math.trajectory.TrapezoidProfile.Constraints angular)
    Constructs a linear path.
  • Method Summary

    Modifier and Type
    Method
    Description
    calculate(double t, LinearPath.State current, edu.wpi.first.math.geometry.Pose2d goal)
    Calculates the pose and speeds of the path at a time t where the current state is at t = 0.
    final boolean
    isFinished(double t)
    Returns true if the profile has reached the goal.
    final double
    Returns the total time the profile takes to reach the goal.

    Methods inherited from class java.lang.Object

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

    • LinearPath

      public LinearPath(edu.wpi.first.math.trajectory.TrapezoidProfile.Constraints linear, edu.wpi.first.math.trajectory.TrapezoidProfile.Constraints angular)
      Constructs a linear path.
      Parameters:
      linear - The constraints on the profile linear motion
      angular - The constraints on the profile angular motion
  • Method Details

    • calculate

      public final LinearPath.State calculate(double t, LinearPath.State current, edu.wpi.first.math.geometry.Pose2d goal)
      Calculates the pose and speeds of the path at a time t where the current state is at t = 0.
      Parameters:
      t - How long to advance from the current state to the desired state
      current - The current state
      goal - The desired pose when the path is complete
      Returns:
      The pose and speeds of the profile at time t
    • totalTime

      public final double totalTime()
      Returns the total time the profile takes to reach the goal.
      Returns:
      The total time the profile takes to reach the goal
    • isFinished

      public final boolean isFinished(double t)
      Returns true if the profile has reached the goal.

      The profile has reached the goal if the time since the profile started has exceeded the profile's total time.

      Parameters:
      t - The time since the beginning of the profile
      Returns:
      true if the profile has reached the goal