Skip to content

Commit

Permalink
Allow use of the PathPlannerTrajectory constructor with choreo paths
Browse files Browse the repository at this point in the history
  • Loading branch information
mjansen4857 committed Jan 30, 2024
1 parent 6abcadb commit c4c3bb6
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
5 changes: 4 additions & 1 deletion pathplannerlib-python/pathplannerlib/trajectory.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,10 @@ def __init__(self, path: Union[PathPlannerPath, None], starting_speeds: Union[Ch
if states is not None:
self._states = states
else:
self._states = PathPlannerTrajectory._generateStates(path, starting_speeds, starting_rotation)
if path.isChoreoPath():
self._states = path.getTrajectory(starting_speeds, starting_rotation).getStates()
else:
self._states = PathPlannerTrajectory._generateStates(path, starting_speeds, starting_rotation)

def getStates(self) -> List[State]:
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ public class PathPlannerTrajectory {
*/
public PathPlannerTrajectory(
PathPlannerPath path, ChassisSpeeds startingSpeeds, Rotation2d startingRotation) {
this.states = generateStates(path, startingSpeeds, startingRotation);
if (path.isChoreoPath()) {
this.states = path.getTrajectory(startingSpeeds, startingRotation).getStates();
} else {
this.states = generateStates(path, startingSpeeds, startingRotation);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@

using namespace pathplanner;

PathPlannerTrajectory::PathPlannerTrajectory(
std::shared_ptr<PathPlannerPath> path,
const frc::ChassisSpeeds &startingSpeeds,
const frc::Rotation2d &startingRotation) {
if (path->isChoreoPath()) {
m_states =
path->getTrajectory(startingSpeeds, startingRotation).getStates();
} else {
m_states = generateStates(path, startingSpeeds, startingRotation);
}
}

PathPlannerTrajectory::State PathPlannerTrajectory::sample(
const units::second_t time) {
if (time <= getInitialState().time)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,7 @@ class PathPlannerTrajectory {
*/
PathPlannerTrajectory(std::shared_ptr<PathPlannerPath> path,
const frc::ChassisSpeeds &startingSpeeds,
const frc::Rotation2d &startingRotation) : m_states(
generateStates(path, startingSpeeds, startingRotation)) {
}
const frc::Rotation2d &startingRotation);

/**
* Get the target state at the given point in time along the trajectory
Expand Down

0 comments on commit c4c3bb6

Please sign in to comment.