mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
[examples] Update C++ examples to use CommandPtr (#5988)
Co-authored-by: Tyler Veness <calcmogul@gmail.com>
This commit is contained in:
@@ -4,9 +4,17 @@
|
||||
|
||||
#include "RobotContainer.h"
|
||||
|
||||
#include <frc/smartdashboard/SmartDashboard.h>
|
||||
|
||||
RobotContainer::RobotContainer() {
|
||||
// Initialize all of your commands and subsystems here
|
||||
|
||||
m_chooser.SetDefaultOption("ONE", CommandSelector::ONE);
|
||||
m_chooser.AddOption("TWO", CommandSelector::TWO);
|
||||
m_chooser.AddOption("THREE", CommandSelector::THREE);
|
||||
|
||||
frc::SmartDashboard::PutData("Auto Chooser", &m_chooser);
|
||||
|
||||
// Configure the button bindings
|
||||
ConfigureButtonBindings();
|
||||
}
|
||||
|
||||
@@ -4,7 +4,9 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <frc/smartdashboard/SendableChooser.h>
|
||||
#include <frc2/command/Command.h>
|
||||
#include <frc2/command/CommandPtr.h>
|
||||
#include <frc2/command/Commands.h>
|
||||
|
||||
/**
|
||||
@@ -24,10 +26,8 @@ class RobotContainer {
|
||||
// The enum used as keys for selecting the command to run.
|
||||
enum CommandSelector { ONE, TWO, THREE };
|
||||
|
||||
// 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.
|
||||
CommandSelector Select() { return ONE; }
|
||||
// An example of how command selector may be used with SendableChooser
|
||||
frc::SendableChooser<CommandSelector> m_chooser;
|
||||
|
||||
// The robot's subsystems and commands are defined here...
|
||||
|
||||
@@ -36,7 +36,7 @@ class RobotContainer {
|
||||
// takes a generic type, so the selector does not have to be an enum; it could
|
||||
// be any desired type (string, integer, boolean, double...)
|
||||
frc2::CommandPtr m_exampleSelectCommand = frc2::cmd::Select<CommandSelector>(
|
||||
[this] { return Select(); },
|
||||
[this] { return m_chooser.GetSelected(); },
|
||||
// Maps selector values to commands
|
||||
std::pair{ONE, frc2::cmd::Print("Command one was selected!")},
|
||||
std::pair{TWO, frc2::cmd::Print("Command two was selected!")},
|
||||
|
||||
Reference in New Issue
Block a user