I was trying to make a way for drivers to change drive mode through the shuffleboard. I tried getting a Boolean from the shuffleboard using a button widget however if I press the button it does not change the drive mode. I used the Boolean in an if statement in the drivetrain command with the different drive modes. How would I instead go about implementing this feature. Thanks for any help.
This way may largely different than how you might want to do it:
You can do this with the SendableChooser. That article goes into how you could do it for an auto program but it is very similar for choosing a teleop drive command. Instead of using the getSelected
in getAutonomousCommand
you can create a similar updateTeleopCommand
that is called in teleopInit
of Robot.java and sets the default drivetrain command.
public void updateTeleopCommand() {
driveTrain.setDefaultCommand(driveCommandChooser.getSelected());
}
This will update the drive command to the chosen one every time the robot is changed to teleop mode. I haven’t personally tested this but it should work.
I would highly recommend looking at the SelectCommand: Convenience Features — FIRST Robotics Competition documentation. You could combine this with the input from the Shuffleboard to run two (or more) different drive commands based on what has been selected.
i’ll try both of these on monday when i will be with the robot again. Thanks both of you.
how would i select which command I want through shuffleboard. This is the code I have right now.
private enum CommandSelector {
arcade,
tank
}
// An example selector method for the selectcommand. Returns the selector that will select
// which command to run. Can base this choice on logical conditions evaluated at runtime.
private CommandSelector select() {
return CommandSelector.arcade;
}
// An example selectcommand. Will select from the three commands based on the value returned
// by the selector method at runtime. Note that selectcommand works on Object(), so the
// selector does not have to be an enum; it could be any desired type (string, integer,
// boolean, double...)
private final Command m_exampleSelectCommand = new SelectCommand(
// Maps selector values to commands
Map.ofEntries(
Map.entry(CommandSelector.arcade, drivearcade),
Map.entry(CommandSelector.tank, drivetank)),
this::select);
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.