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);
 
  • Constructor Details

  • Method Details

    • calculate

      public final LinearPath.State calculate(double t, LinearPath.State current, 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