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:
@@ -39,7 +39,7 @@ void Robot::DisabledPeriodic() {}
|
||||
void Robot::AutonomousInit() {
|
||||
m_autonomousCommand = m_container.GetAutonomousCommand();
|
||||
|
||||
if (m_autonomousCommand != nullptr) {
|
||||
if (m_autonomousCommand) {
|
||||
m_autonomousCommand->Schedule();
|
||||
}
|
||||
}
|
||||
@@ -51,9 +51,9 @@ void Robot::TeleopInit() {
|
||||
// teleop starts running. If you want the autonomous to
|
||||
// continue until interrupted by another command, remove
|
||||
// this line or comment it out.
|
||||
if (m_autonomousCommand != nullptr) {
|
||||
if (m_autonomousCommand) {
|
||||
m_autonomousCommand->Cancel();
|
||||
m_autonomousCommand = nullptr;
|
||||
m_autonomousCommand.reset();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -60,6 +60,6 @@ void RobotContainer::DisablePIDSubsystems() {
|
||||
m_arm.Disable();
|
||||
}
|
||||
|
||||
frc2::Command* RobotContainer::GetAutonomousCommand() {
|
||||
return nullptr;
|
||||
frc2::CommandPtr RobotContainer::GetAutonomousCommand() {
|
||||
return frc2::cmd::None();
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <optional>
|
||||
|
||||
#include <frc/TimedRobot.h>
|
||||
#include <frc2/command/Command.h>
|
||||
|
||||
@@ -24,7 +26,7 @@ class Robot : public frc::TimedRobot {
|
||||
private:
|
||||
// Have it null by default so that if testing teleop it
|
||||
// doesn't have undefined behavior and potentially crash.
|
||||
frc2::Command* m_autonomousCommand = nullptr;
|
||||
std::optional<frc2::CommandPtr> m_autonomousCommand;
|
||||
|
||||
RobotContainer m_container;
|
||||
};
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <frc2/command/Command.h>
|
||||
#include <frc2/command/CommandPtr.h>
|
||||
#include <frc2/command/button/CommandXboxController.h>
|
||||
|
||||
#include "Constants.h"
|
||||
@@ -28,7 +29,7 @@ class RobotContainer {
|
||||
*/
|
||||
void DisablePIDSubsystems();
|
||||
|
||||
frc2::Command* GetAutonomousCommand();
|
||||
frc2::CommandPtr GetAutonomousCommand();
|
||||
|
||||
private:
|
||||
// The driver's controller
|
||||
|
||||
Reference in New Issue
Block a user