I’m using this link as a guide to create an autopilot algorithm for teleoperated period.
I’m trying to make a code that when a button is pressed, the robot moves to its (0, 0) position as long as I keep pressing the button.
The problem is that when I press it, the robot doesn’t do anything.
I want to make it so that
it doesn’t matter the position, the robot will automatically create a path to the desired point.
I coded it as a sequential command group that is later called in the robot container.
Hmm, I can’t see the entire file, but I don’t think you want to use a sequential command group in this case, rather do something along the lines of creating the pathfindingCommand command inside of a factory, then bind it to a button with button.whileTrue(pathfindingCommand). Additionally, the path finding algorithm might not like that you are trying to path find “out of bounds”.
No clue about the content of your addCommands method, but I note that the way you called it is not consistent with the comments provided by someone in your code. If you call it the way the comments suggest as:
addCommands(new pathfindingCommand())
does it make any difference?
Note also that pathfindToPose will only get you to somewhere in the pathplanner grid node that contains your target translation. You will likely need something additional to get precisely to your target.
We do have a pose estimator using odometry (which is not completely precise) but for the moment, we want to use that estimation to make the robot move to a certain position, (any position for the moment) for as long as a button is held pressed (and stop right when the button is not being pressed). How do we make the robot move to a position using odometry pose estimation?
Regarding the pose estimator, as long as you are passing in the correct object to Autobuilder (the pose estimator object) you should be all set.
Here’s the second part of your question:
I would have a function that returns the command inside either a helper file or the drivetrain subsystem:
public Command pathFindToPose(Pose2d pose) {
PathConstraints constraints = new PathConstraints(10.0, 4.0, 9.42478, 12.5664);
return AutoBuilder.pathfindToPose(pose, constraints, 0.0, 0.0);
}
Then bind it to a button with whileTrue (so that it gets canceled when the button is released:
controller.b().whileTrue(DriveCommands.pathFindToPose(new Pose2d())); // choose whatever pose you want
Of course this is just an example and implement it however you would like.
Does this command go in the subsystem file or in the autopilot command file? and if it’s in the command file, would it go in the initialize or execute method?