Skip to content

Commit

Permalink
Update RobotBuilder docs for Trigger change (#2013)
Browse files Browse the repository at this point in the history
  • Loading branch information
sciencewhiz authored Nov 27, 2022
1 parent 8b33fcc commit 9e67ee4
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 58 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ RobotContainer
.. code-block:: java
:linenos:
:lineno-start: 11
:emphasize-lines: 32-35, 38, 61, 80, 88, 108
:emphasize-lines: 33-36, 39, 62, 81, 92, 112
// ROBOTBUILDER TYPE: RobotContainer.
Expand All @@ -316,6 +316,7 @@ RobotContainer
import frc.robot.subsystems.*;
import edu.wpi.first.wpilibj.smartdashboard.SendableChooser;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import edu.wpi.first.wpilibj2.command.Command.InterruptionBehavior;
// BEGIN AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=IMPORTS
import edu.wpi.first.wpilibj2.command.Command;
Expand All @@ -339,13 +340,13 @@ RobotContainer
// BEGIN AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=DECLARATIONS
// The robot's subsystems
public final Wrist m_wrist = new Wrist(); // {1}
public final Wrist m_wrist = new Wrist(); // (1)
public final Elevator m_elevator = new Elevator();
public final Claw m_claw = new Claw();
public final Drivetrain m_drivetrain = new Drivetrain();
// Joysticks
private final Joystick joystick2 = new Joystick(2); // {3}
private final Joystick joystick2 = new Joystick(2); // (3)
private final Joystick joystick1 = new Joystick(1);
private final Joystick logitechController = new Joystick(0);
Expand All @@ -361,14 +362,14 @@ RobotContainer
private RobotContainer() {
// BEGIN AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=SMARTDASHBOARD
// Smartdashboard Subsystems
SmartDashboard.putData(m_wrist);
SmartDashboard.putData(m_wrist); // (6)
SmartDashboard.putData(m_elevator);
SmartDashboard.putData(m_claw);
SmartDashboard.putData(m_drivetrain);
// SmartDashboard Buttons
SmartDashboard.putData("Close Claw", new CloseClaw( m_claw )); // {6}
SmartDashboard.putData("Close Claw", new CloseClaw( m_claw )); // (6)
SmartDashboard.putData("Open Claw: OpenTime", new OpenClaw(1.0, m_claw));
SmartDashboard.putData("Pickup", new Pickup());
SmartDashboard.putData("Place", new Place());
Expand All @@ -387,15 +388,18 @@ RobotContainer
// Configure default commands
// BEGIN AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=SUBSYSTEM_DEFAULT_COMMAND
m_drivetrain.setDefaultCommand(new TankDrive( m_drivetrain ) ); // {5}
m_drivetrain.setDefaultCommand(new TankDrive(() -> getJoystick1().getY(), () -> getJoystick2().getY(), m_drivetrain)); // (5)
// END AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=SUBSYSTEM_DEFAULT_COMMAND
// Configure autonomous sendable chooser
// BEGIN AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=AUTONOMOUS
m_chooser.setDefaultOption("Autonomous", new Autonomous()); // {2}
m_chooser.addOption("Set Elevator Setpoint: Bottom", new SetElevatorSetpoint(0, m_elevator));
m_chooser.addOption("Set Elevator Setpoint: Platform", new SetElevatorSetpoint(0.2, m_elevator));
m_chooser.addOption("Set Elevator Setpoint: Top", new SetElevatorSetpoint(0.3, m_elevator));
m_chooser.setDefaultOption("Autonomous", new Autonomous()); // (2)
// END AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=AUTONOMOUS
Expand All @@ -415,37 +419,29 @@ RobotContainer
private void configureButtonBindings() {
// BEGIN AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=BUTTONS
// Create some buttons
final JoystickButton r1 = new JoystickButton(logitechController, 12); // {4}
r1.whenPressed(new Autonomous() ,true);
SmartDashboard.putData("R1",new Autonomous() );
final JoystickButton r1 = new JoystickButton(logitechController, 12); // (4)
r1.onTrue(new Autonomous().withInterruptBehavior(InterruptionBehavior.kCancelSelf));
final JoystickButton l1 = new JoystickButton(logitechController, 11);
l1.whenPressed(new Place() ,true);
SmartDashboard.putData("L1",new Place() );
l1.onTrue(new Place().withInterruptBehavior(InterruptionBehavior.kCancelSelf));
final JoystickButton r2 = new JoystickButton(logitechController, 10);
r2.whenPressed(new Pickup() ,true);
SmartDashboard.putData("R2",new Pickup() );
r2.onTrue(new Pickup().withInterruptBehavior(InterruptionBehavior.kCancelSelf));
final JoystickButton l2 = new JoystickButton(logitechController, 9);
l2.whenPressed(new PrepareToPickup() ,true);
SmartDashboard.putData("L2",new PrepareToPickup() );
l2.onTrue(new PrepareToPickup().withInterruptBehavior(InterruptionBehavior.kCancelSelf));
final JoystickButton dpadLeft = new JoystickButton(logitechController, 8);
dpadLeft.whenPressed(new OpenClaw(1.0, m_claw) ,true);
SmartDashboard.putData("Dpad Left",new OpenClaw(1.0, m_claw) );
dpadLeft.onTrue(new OpenClaw(1.0, m_claw).withInterruptBehavior(InterruptionBehavior.kCancelSelf));
final JoystickButton dpadRight = new JoystickButton(logitechController, 6);
dpadRight.whenPressed(new CloseClaw( m_claw ) ,true);
SmartDashboard.putData("Dpad Right",new CloseClaw( m_claw ) );
dpadRight.onTrue(new CloseClaw( m_claw ).withInterruptBehavior(InterruptionBehavior.kCancelSelf));
final JoystickButton dpadDown = new JoystickButton(logitechController, 7);
dpadDown.whenPressed(new SetElevatorSetpoint(0, m_elevator) ,true);
SmartDashboard.putData("Dpad Down",new SetElevatorSetpoint(0, m_elevator) );
dpadDown.onTrue(new SetElevatorSetpoint(0, m_elevator).withInterruptBehavior(InterruptionBehavior.kCancelSelf));
final JoystickButton dpadUp = new JoystickButton(logitechController, 5);
dpadUp.whenPressed(new SetElevatorSetpoint(0.3, m_elevator) ,true);
SmartDashboard.putData("Dpad Up",new SetElevatorSetpoint(0.3, m_elevator) );
dpadUp.onTrue(new SetElevatorSetpoint(0.3, m_elevator).withInterruptBehavior(InterruptionBehavior.kCancelSelf));
Expand Down Expand Up @@ -515,7 +511,7 @@ RobotContainer
#include <frc/Joystick.h>
#include <frc2/command/button/JoystickButton.h>

// END AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=INCLUDES
// END AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=INCLUDES

class RobotContainer {

Expand All @@ -526,7 +522,7 @@ RobotContainer

// BEGIN AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=PROTOTYPES
// The robot's subsystems
Drivetrain m_drivetrain; // {1}
Drivetrain m_drivetrain; // (1)
Claw m_claw;
Elevator m_elevator;
Wrist m_wrist;
Expand All @@ -544,9 +540,9 @@ RobotContainer

// BEGIN AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=DECLARATIONS
// Joysticks
frc::Joystick m_joystick2{2}; // {3}
frc::Joystick m_logitechController{0}; // (3)
frc::Joystick m_joystick1{1};
frc::Joystick m_logitechController{0};
frc::Joystick m_joystick2{2};

frc::SendableChooser<frc2::Command*> m_chooser;

Expand All @@ -563,7 +559,7 @@ RobotContainer
.. code-block:: cpp
:linenos:
:lineno-start: 11
:emphasize-lines: 28, 46, 53, 71
:emphasize-lines: 28, 46, 56, 74
// ROBOTBUILDER TYPE: RobotContainer.
Expand All @@ -585,39 +581,42 @@ RobotContainer
// BEGIN AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=SMARTDASHBOARD
// Smartdashboard Subsystems
frc::SmartDashboard::PutData(&m_wrist);
frc::SmartDashboard::PutData(&m_elevator);
frc::SmartDashboard::PutData(&m_claw);
frc::SmartDashboard::PutData(&m_drivetrain);
frc::SmartDashboard::PutData(&m_claw);
frc::SmartDashboard::PutData(&m_elevator);
frc::SmartDashboard::PutData(&m_wrist);
// SmartDashboard Buttons
frc::SmartDashboard::PutData("Close Claw", new CloseClaw( &m_claw )); // {6}
frc::SmartDashboard::PutData("Open Claw: OpenTime", new OpenClaw(1.0_s, &m_claw));
frc::SmartDashboard::PutData("Pickup", new Pickup());
frc::SmartDashboard::PutData("Place", new Place());
frc::SmartDashboard::PutData("Prepare To Pickup", new PrepareToPickup());
frc::SmartDashboard::PutData("Drive: Straight3Meters", new Drive(3, 0, &m_drivetrain)); // (6)
frc::SmartDashboard::PutData("Drive: Place", new Drive(Drivetrain::PlaceDistance, Drivetrain::BackAwayDistance, &m_drivetrain));
frc::SmartDashboard::PutData("Set Wrist Setpoint: Horizontal", new SetWristSetpoint(0, &m_wrist));
frc::SmartDashboard::PutData("Set Wrist Setpoint: Raise Wrist", new SetWristSetpoint(-45, &m_wrist));
frc::SmartDashboard::PutData("Set Elevator Setpoint: Bottom", new SetElevatorSetpoint(0, &m_elevator));
frc::SmartDashboard::PutData("Set Elevator Setpoint: Platform", new SetElevatorSetpoint(0.2, &m_elevator));
frc::SmartDashboard::PutData("Set Elevator Setpoint: Top", new SetElevatorSetpoint(0.3, &m_elevator));
frc::SmartDashboard::PutData("Set Wrist Setpoint: Horizontal", new SetWristSetpoint(0, &m_wrist));
frc::SmartDashboard::PutData("Set Wrist Setpoint: Raise Wrist", new SetWristSetpoint(-45, &m_wrist));
frc::SmartDashboard::PutData("Drive: Straight3Meters", new Drive(3, 0, &m_drivetrain));
frc::SmartDashboard::PutData("Drive: Place", new Drive(Drivetrain::PlaceDistance, Drivetrain::BackAwayDistance, &m_drivetrain));
frc::SmartDashboard::PutData("Prepare To Pickup", new PrepareToPickup());
frc::SmartDashboard::PutData("Place", new Place());
frc::SmartDashboard::PutData("Pickup", new Pickup());
frc::SmartDashboard::PutData("Open Claw: OpenTime", new OpenClaw(1.0_s, &m_claw));
frc::SmartDashboard::PutData("Close Claw", new CloseClaw( &m_claw ));
// END AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=SMARTDASHBOARD
ConfigureButtonBindings();
// BEGIN AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=DEFAULT-COMMANDS
m_drivetrain.SetDefaultCommand(TankDrive( &m_drivetrain )); // {5}
m_drivetrain.SetDefaultCommand(TankDrive([this] {return getJoystick1()->GetY();}, [this] {return getJoystick2()->GetY();}, &m_drivetrain)); // (5)
// END AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=DEFAULT-COMMANDS
// BEGIN AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=AUTONOMOUS
m_chooser.AddOption("Set Elevator Setpoint: Bottom", new SetElevatorSetpoint(0, &m_elevator));
m_chooser.AddOption("Set Elevator Setpoint: Platform", new SetElevatorSetpoint(0.2, &m_elevator));
m_chooser.AddOption("Set Elevator Setpoint: Top", new SetElevatorSetpoint(0.3, &m_elevator));
m_chooser.SetDefaultOption("Autonomous", new Autonomous()); // {2}
m_chooser.SetDefaultOption("Autonomous", new Autonomous()); // (2)
// END AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=AUTONOMOUS
Expand All @@ -635,7 +634,7 @@ RobotContainer
void RobotContainer::ConfigureButtonBindings() {
// BEGIN AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=BUTTONS
frc2::JoystickButton m_dpadUp{&m_logitechController, 5}; // {4}
frc2::JoystickButton m_dpadUp{&m_logitechController, 5}; // (4)
frc2::JoystickButton m_dpadDown{&m_logitechController, 7};
frc2::JoystickButton m_dpadRight{&m_logitechController, 6};
frc2::JoystickButton m_dpadLeft{&m_logitechController, 8};
Expand All @@ -644,31 +643,39 @@ RobotContainer
frc2::JoystickButton m_l1{&m_logitechController, 11};
frc2::JoystickButton m_r1{&m_logitechController, 12};
m_dpadUp.WhenPressed(SetElevatorSetpoint(0.3, &m_elevator), true);
m_dpadDown.WhenPressed(SetElevatorSetpoint(0, &m_elevator), true);
m_dpadRight.WhenPressed(CloseClaw( &m_claw ), true);
m_dpadLeft.WhenPressed(OpenClaw(1.0_s, &m_claw), true);
m_l2.WhenPressed(PrepareToPickup(), true);
m_r2.WhenPressed(Pickup(), true);
m_l1.WhenPressed(Place(), true);
m_r1.WhenPressed(Autonomous(), true);
m_dpadUp.OnTrue(SetElevatorSetpoint(0.3, &m_elevator).WithInterruptBehavior(frc2::Command::InterruptionBehavior::kCancelSelf));
m_dpadDown.OnTrue(SetElevatorSetpoint(0, &m_elevator).WithInterruptBehavior(frc2::Command::InterruptionBehavior::kCancelSelf));
m_dpadRight.OnTrue(CloseClaw( &m_claw ).WithInterruptBehavior(frc2::Command::InterruptionBehavior::kCancelSelf));
m_dpadLeft.OnTrue(OpenClaw(1.0_s, &m_claw).WithInterruptBehavior(frc2::Command::InterruptionBehavior::kCancelSelf));
m_l2.OnTrue(PrepareToPickup().WithInterruptBehavior(frc2::Command::InterruptionBehavior::kCancelSelf));
m_r2.OnTrue(Pickup().WithInterruptBehavior(frc2::Command::InterruptionBehavior::kCancelSelf));
m_l1.OnTrue(Place().WithInterruptBehavior(frc2::Command::InterruptionBehavior::kCancelSelf));
m_r1.OnTrue(Autonomous().WithInterruptBehavior(frc2::Command::InterruptionBehavior::kCancelSelf));
// END AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=BUTTONS
}
// BEGIN AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=FUNCTIONS
frc::Joystick* RobotContainer::getJoystick2() {
return &m_joystick2;
frc::Joystick* RobotContainer::getLogitechController() {
return &m_logitechController;
}
frc::Joystick* RobotContainer::getJoystick1() {
return &m_joystick1;
}
frc::Joystick* RobotContainer::getLogitechController() {
return &m_logitechController;
frc::Joystick* RobotContainer::getJoystick2() {
return &m_joystick2;
}
// END AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=FUNCTIONS
// END AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=FUNCTIONS
frc2::Command* RobotContainer::GetAutonomousCommand() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ Linking a Button to the "Move Elevator" Command
Add the button that should be pressed to the program

1. Drag the joystick button to the Joystick (Logitech Controller) so that it's under the joystick
2. Set the properties for the button: the button number, the command to run when the button is pressed, parameters the command takes, and the "When to run" property to "whenPressed" to indicate that the command should run whenever the joystick button is pressed.
2. Set the properties for the button: the button number, the command to run when the button is pressed, parameters the command takes, and the :guilabel:`When to run` property to :guilabel:`onTrue` to indicate that the command should run whenever the joystick button is pressed.

.. note:: Joystick buttons must be dragged to (under) a Joystick. You must have a joystick in the Operator Interface folder before adding buttons.

0 comments on commit 9e67ee4

Please sign in to comment.