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:
@@ -4,8 +4,10 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <optional>
|
||||
|
||||
#include <frc/TimedRobot.h>
|
||||
#include <frc2/command/Command.h>
|
||||
#include <frc2/command/CommandPtr.h>
|
||||
|
||||
#include "RobotContainer.h"
|
||||
|
||||
@@ -24,9 +26,9 @@ class Robot : public frc::TimedRobot {
|
||||
void SimulationPeriodic() override;
|
||||
|
||||
private:
|
||||
// Have it null by default so that if testing teleop it
|
||||
// Have it empty 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;
|
||||
};
|
||||
|
||||
@@ -4,9 +4,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <frc2/command/Command.h>
|
||||
#include <frc2/command/CommandPtr.h>
|
||||
|
||||
#include "commands/ExampleCommand.h"
|
||||
#include "subsystems/ExampleSubsystem.h"
|
||||
|
||||
/**
|
||||
@@ -20,12 +19,11 @@ class RobotContainer {
|
||||
public:
|
||||
RobotContainer();
|
||||
|
||||
frc2::Command* GetAutonomousCommand();
|
||||
frc2::CommandPtr GetAutonomousCommand();
|
||||
|
||||
private:
|
||||
// The robot's subsystems and commands are defined here...
|
||||
// The robot's subsystems are defined here...
|
||||
ExampleSubsystem m_subsystem;
|
||||
ExampleCommand m_autonomousCommand;
|
||||
|
||||
void ConfigureButtonBindings();
|
||||
void ConfigureBindings();
|
||||
};
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
// 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.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <frc2/command/CommandPtr.h>
|
||||
|
||||
#include "subsystems/ExampleSubsystem.h"
|
||||
|
||||
namespace autos {
|
||||
/**
|
||||
* Example static factory for an autonomous command.
|
||||
*/
|
||||
frc2::CommandPtr ExampleAuto(ExampleSubsystem* subsystem);
|
||||
} // namespace autos
|
||||
@@ -4,12 +4,18 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <frc2/command/CommandPtr.h>
|
||||
#include <frc2/command/SubsystemBase.h>
|
||||
|
||||
class ExampleSubsystem : public frc2::SubsystemBase {
|
||||
public:
|
||||
ExampleSubsystem();
|
||||
|
||||
/**
|
||||
* Example command factory method.
|
||||
*/
|
||||
frc2::CommandPtr ExampleMethodCommand();
|
||||
|
||||
/**
|
||||
* Will be called periodically whenever the CommandScheduler runs.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user