Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cmd] Command-based Template Restructuring #5939

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

AngleSideAngle
Copy link
Contributor

@AngleSideAngle AngleSideAngle commented Nov 18, 2023

#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

@sciencewhiz
Copy link
Contributor

sciencewhiz commented Nov 21, 2023

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.

@AngleSideAngle
Copy link
Contributor Author

AngleSideAngle commented Nov 22, 2023

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.

@Starlight220
Copy link
Member

Starlight220 commented Nov 22, 2023

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.

@calcmogul calcmogul added the component: command-based WPILib Command Based Library label Dec 2, 2023
@calcmogul calcmogul changed the title [commands] Command-based Template Restructuring [cmd] Command-based Template Restructuring Dec 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: command-based WPILib Command Based Library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants