oGuizim
January 24, 2024, 12:11am
1
Hi, I’m programming my robot’s autonomous function, but I got stuck at the stage of inserting named Path Planner commands into my Robot Container, the code is below.
nstrike
January 24, 2024, 12:17am
2
You configure pathplanner in the constructor of the swerve subsystem which is done here.
import edu.wpi.first.wpilibj.XboxController;
import edu.wpi.first.wpilibj.smartdashboard.SendableChooser;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.InstantCommand;
import edu.wpi.first.wpilibj2.command.PrintCommand;
import edu.wpi.first.wpilibj2.command.button.JoystickButton;
public class RobotContainer {
// Aqui iniciamos o swerve
private SwerveSubsystem swerve = new SwerveSubsystem(new File(Filesystem.getDeployDirectory(), "swerve"));
// Aqui é onde chamamos o subsystem de cada parte do intake
public static final Coletor cSubsystem = new Coletor();
public static final Gancho gSubsystem = new Gancho();
public static final Lancador lSubsystem = new Lancador();
// Aqui é onde chamaremos os commands de cada parte do intake
public static final ColetorCmd cCommand = new ColetorCmd(cSubsystem);
public static final GanchoCmd gCommand = new GanchoCmd(gSubsystem);
public static final LancadorCmd lCommand = new LancadorCmd(lSubsystem);
public void setupPathPlanner()
{
AutoBuilder.configureHolonomic(
swerve::getPose, // Robot pose supplier
swerve::resetOdometry, // Method to reset odometry (will be called if your auto has a starting pose)
swerve::getRobotVelocity, // ChassisSpeeds supplier. MUST BE ROBOT RELATIVE
swerve::setChassisSpeeds, // Method that will drive the robot given ROBOT RELATIVE ChassisSpeeds
new HolonomicPathFollowerConfig( // HolonomicPathFollowerConfig, this should likely live in your Constants class
new PIDConstants(5.0, 0.0, 0.0),
// Translation PID constants
new PIDConstants(swerve.getSwerveController().config.headingPIDF.p,
swerve.getSwerveController().config.headingPIDF.i,
swerve.getSwerveController().config.headingPIDF.d),
// Rotation PID constants
4.5,
// Max module speed, in m/s
swerve.getSwerveDriveConfiguration().getDriveBaseRadiusMeters(),
// Drive base radius in meters. Distance from robot center to furthest module.
new ReplanningConfig()
// Default path replanning config. See the API for the options here
This file has been truncated. show original
and you register the named command here.
* Controle.DEADBAND),
* () -> MathUtil.applyDeadband(driverXbox.getRightX(),
* Controle.DEADBAND),
* driverXbox::getYButtonPressed,
* driverXbox::getAButtonPressed,
* driverXbox::getXButtonPressed,
* driverXbox::getBButtonPressed);
*/
// Colocar os comandos definidos no PathPlanner 2024 da seguinte forma
NamedCommands.registerCommand("Intake", new PrintCommand("Intake"));
// NamedCommands.registerCommand("invertForward", new InvertMotors(driveTrain, true));
// NamedCommands.registerCommand("autoBalance", swerve.autoBalanceCommand());
// NamedCommands.registerCommand("exampleCommand",
// Lancador.shooterMax(RobotContainer.operatorControl, Tracao.lancadorMax));
// NamedCommands.registerCommand("someOtherCommand", new SomeOtherCommand());
cCommand.addRequirements(cSubsystem);
cSubsystem.setDefaultCommand(cCommand);
gCommand.addRequirements(gSubsystem);
You need to register the named command before setupPathPlanner
is called. So just call it afterwards in the RobotContainer
constructor!
oGuizim
January 24, 2024, 12:07pm
3
Alright, so i need to put de register named command inside setupPathPlanner
, because i don’t understand how i can register named command before setupPathPlanner
.
1 Like