We are trying to implement pathplannerlib pathfinding on our robot. Currently when we try to schedule a pathfinding path generated by pathfinding, the robot does not execute it. We are currently using the AutoBuilder.pathfindToPose()
to generate a path and then using the .schedule()
to attempt to execute it.
All the code for our robot can be found here: GitHub - Team4169/Swerve2024: Git Repo for the 2023 - 2024 season. Here is the most relevant sections of code:
Path generation and attempted execution:
def getObjectDetectionPathfinding(self) -> commands2.Command:
"""Returns the pathfinding command from position"""
# changeHorizontal = self.datatable.getEntry("objHorizontal").getValue()
# changeDistance = self.datatable.getEntry("objDistance").getValue()
changeHorizontal = 1000
changeDistance = 1000
changeRot = math.atan2(changeHorizontal, changeDistance)
print(f"Change Rot: {changeRot}")
targetPose = Pose2d(changeDistance, changeHorizontal, Rotation2d.fromRotations(changeRot / (math.pi * 2)))
print(f"Target Pose: {targetPose}")
pathfindingCommand = AutoBuilder.pathfindToPose(
targetPose,
AutoConstants.constraints,
goal_end_vel=0.0,
rotation_delay_distance=0.0
)
if pathfindingCommand:
print(pathfindingCommand)
pathfindingCommand.schedule()
Pathplanner initialization in swerve subsystem:
AutoBuilder.configureHolonomic(
self.getPose,
self.resetOdometry,
self.getChassisSpeeds,
self.driveChassisSpeeds,
AutoConstants.pathFollowerConfig,
self.shouldFlipPath,
self
)
Note: When we print the pathfindingCommand
we get a <pathplannerlib.commands.PathfindHolonomic object>
. In addition, our pathplanner auto works and uses the .schedule()
command, but uses a <pathplannerlib.auto.PathPlannerAuto object>
.