allwpilib
allwpilib copied to clipboard
[cmd] Command-based Template Restructuring
#5902 added static triggers for game/robot state changes. This pr, initially #5898, seeks to refactor all command-based templates and examples to declaratively use those triggers along with command factories. Additionally, it removes the split between RobotContainer
and Robot
, replacing manually scheduling getAutonomous()
with a binding to the autonomous()
trigger. Indirectly closes #4871.
Specifically, Robot.java
in the default commandbased
template looks like this:
import static edu.wpi.first.wpilibj2.command.button.RobotModeTriggers.*;
public class Robot extends CommandRobot {
private final ExampleSubsystem m_exampleSubsystem = new ExampleSubsystem();
private final CommandXboxController m_driverController =
new CommandXboxController(OperatorConstants.kDriverControllerPort);
public Robot() {
configureBindings();
}
private void configureBindings() {
autonomous().whileTrue(Autos.exampleAuto(m_exampleSubsystem));
new Trigger(m_exampleSubsystem::exampleCondition).onTrue(m_exampleSubsystem.exampleCommand());
m_driverController.b().whileTrue(m_exampleSubsystem.anotherCommand());
}
}
and the file structure is changed to be:
├── Autos.java
├── Constants.java
├── Main.java
├── Robot.java
└── subsystems
└── ExampleSubsystem.java
- [ ] Java CommandRobot
- [ ] C++ CommandRobot
- [ ] Java Templates
- [ ] C++ Templates
- [ ] Java Examples
- [ ] C++ Examples
It seems too close to kickoff to make this kind of change. There's definitely frc-docs changes needed, and RobotBuilder, and there's limited time for beta team feedback.
Yeah that's true. I wouldn't mind merging this (and associated docs changes) next year, although I'd like to post it on CD to ask for feedback and thoughts before the season starts.
I think it'd be better to keep Autos.java
in a commands/
directory; multiple files of commands are very reasonable, and we don't want that cluttering the root package.