Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add method to get holonomic path start pose if ideal starting state is present #892

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions pathplannerlib-python/pathplannerlib/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,21 @@ def getStartingDifferentialPose(self) -> Pose2d:

return Pose2d(startPos, heading)

def getStartingHolonomicPose(self) -> Union[Pose2d, None]:
"""
Get the holonomic pose for the start point of this path. If the path does not have an ideal
starting state, this will return None.

:return: The ideal starting pose if an ideal starting state is present, None otherwise
"""
if self._idealStartingState is None:
return None

startPos = self.getPoint(0).position
rotation = self._idealStartingState.rotation

return Pose2d(startPos, rotation)

def isChoreoPath(self) -> bool:
"""
Check if this path is loaded from a Choreo trajectory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ public Rotation2d getInitialHeading() {
}

/**
* Get the differential pose for the start point of this path
* Get the differential pose for the start point of this path.
*
* @return Pose at the path's starting point
*/
Expand All @@ -687,6 +687,23 @@ public Pose2d getStartingDifferentialPose() {
return new Pose2d(startPos, heading);
}

/**
* Get the holonomic pose for the start point of this path. If the path does not have an ideal
* starting state, this will return an empty optional.
*
* @return The ideal starting pose if an ideal starting state is present, empty optional otherwise
*/
public Optional<Pose2d> getStartingHolonomicPose() {
if (idealStartingState == null) {
return Optional.empty();
}

Translation2d startPos = getPoint(0).position;
Rotation2d rotation = idealStartingState.rotation();

return Optional.of(new Pose2d(startPos, rotation));
}

private PathConstraints constraintsForWaypointPos(double pos) {
for (ConstraintsZone z : constraintZones) {
if (pos >= z.minPosition() && pos <= z.maxPosition()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,17 @@ frc::Pose2d PathPlannerPath::getStartingDifferentialPose() {
return frc::Pose2d(startPos, heading);
}

std::optional<frc::Pose2d> PathPlannerPath::getStartingHolonomicPose() {
if (!m_idealStartingState.has_value()) {
return std::nullopt;
}

frc::Translation2d startPos = getPoint(0).position;
frc::Rotation2d rotation = m_idealStartingState.value().getRotation();

return frc::Pose2d(startPos, rotation);
}

std::optional<PathPlannerTrajectory> PathPlannerPath::getIdealTrajectory(
RobotConfig robotConfig) {
if (!m_idealTrajectory.has_value() && m_idealStartingState.has_value()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,14 @@ class PathPlannerPath: public std::enable_shared_from_this<PathPlannerPath> {
*/
frc::Pose2d getStartingDifferentialPose();

/**
* Get the holonomic pose for the start point of this path. If the path does not have an ideal
* starting state, this will return nullopt.
*
* @return The ideal starting pose if an ideal starting state is present, nullopt otherwise
*/
std::optional<frc::Pose2d> getStartingHolonomicPose();

/**
* Create a path planner path from pre-generated path points. This is used internally, and you
* likely should not use this
Expand Down
Loading