Package com.ctre.phoenix6.swerve.utility
Class LinearPath
java.lang.Object
com.ctre.phoenix6.swerve.utility.LinearPath
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 -
Constructor Summary
ConstructorsConstructorDescriptionLinearPath(edu.wpi.first.math.trajectory.TrapezoidProfile.Constraints linear, edu.wpi.first.math.trajectory.TrapezoidProfile.Constraints angular) Constructs a linear path. -
Method Summary
Modifier and TypeMethodDescriptionfinal LinearPath.Statecalculate(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 booleanisFinished(double t) Returns true if the profile has reached the goal.final doubleReturns the total time the profile takes to reach the goal.
-
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 motionangular- 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 statecurrent- The current stategoal- 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
-