mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
[examples] Update Command-based starter project (#4778)
This commit is contained in:
@@ -6,7 +6,7 @@ package edu.wpi.first.wpilibj.templates.commandbased;
|
||||
|
||||
import edu.wpi.first.wpilibj.GenericHID;
|
||||
import edu.wpi.first.wpilibj.XboxController;
|
||||
import edu.wpi.first.wpilibj.templates.commandbased.commands.ExampleCommand;
|
||||
import edu.wpi.first.wpilibj.templates.commandbased.commands.Autos;
|
||||
import edu.wpi.first.wpilibj.templates.commandbased.subsystems.ExampleSubsystem;
|
||||
import edu.wpi.first.wpilibj2.command.Command;
|
||||
|
||||
@@ -20,12 +20,10 @@ public class RobotContainer {
|
||||
// The robot's subsystems and commands are defined here...
|
||||
private final ExampleSubsystem m_exampleSubsystem = new ExampleSubsystem();
|
||||
|
||||
private final ExampleCommand m_autoCommand = new ExampleCommand(m_exampleSubsystem);
|
||||
|
||||
/** The container for the robot. Contains subsystems, OI devices, and commands. */
|
||||
public RobotContainer() {
|
||||
// Configure the button bindings
|
||||
configureButtonBindings();
|
||||
configureBindings();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -34,7 +32,7 @@ public class RobotContainer {
|
||||
* edu.wpi.first.wpilibj.Joystick} or {@link XboxController}), and then passing it to a {@link
|
||||
* edu.wpi.first.wpilibj2.command.button.JoystickButton}.
|
||||
*/
|
||||
private void configureButtonBindings() {}
|
||||
private void configureBindings() {}
|
||||
|
||||
/**
|
||||
* Use this to pass the autonomous command to the main {@link Robot} class.
|
||||
@@ -42,7 +40,7 @@ public class RobotContainer {
|
||||
* @return the command to run in autonomous
|
||||
*/
|
||||
public Command getAutonomousCommand() {
|
||||
// An ExampleCommand will run in autonomous
|
||||
return m_autoCommand;
|
||||
// An example command will be run in autonomous
|
||||
return Autos.exampleAuto(m_exampleSubsystem);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
package edu.wpi.first.wpilibj.templates.commandbased.commands;
|
||||
|
||||
import edu.wpi.first.wpilibj.templates.commandbased.subsystems.ExampleSubsystem;
|
||||
import edu.wpi.first.wpilibj2.command.CommandBase;
|
||||
import edu.wpi.first.wpilibj2.command.Commands;
|
||||
|
||||
public final class Autos {
|
||||
/** Example static factory for an autonomous command. */
|
||||
public static CommandBase exampleAuto(ExampleSubsystem subsystem) {
|
||||
return Commands.sequence(subsystem.exampleMethodCommand(), new ExampleCommand(subsystem));
|
||||
}
|
||||
|
||||
private Autos() {
|
||||
throw new UnsupportedOperationException("This is a utility class!");
|
||||
}
|
||||
}
|
||||
@@ -4,12 +4,27 @@
|
||||
|
||||
package edu.wpi.first.wpilibj.templates.commandbased.subsystems;
|
||||
|
||||
import edu.wpi.first.wpilibj2.command.CommandBase;
|
||||
import edu.wpi.first.wpilibj2.command.SubsystemBase;
|
||||
|
||||
public class ExampleSubsystem extends SubsystemBase {
|
||||
/** Creates a new ExampleSubsystem. */
|
||||
public ExampleSubsystem() {}
|
||||
|
||||
/**
|
||||
* Example command factory method.
|
||||
*
|
||||
* @return a command
|
||||
*/
|
||||
public CommandBase exampleMethodCommand() {
|
||||
// Inline construction of command goes here.
|
||||
// Subsystem::RunOnce implicitly requires `this` subsystem.
|
||||
return runOnce(
|
||||
() -> {
|
||||
/* one-time action goes here */
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void periodic() {
|
||||
// This method will be called once per scheduler run
|
||||
|
||||
Reference in New Issue
Block a user