[examples] Update Command-based starter project (#4778)

This commit is contained in:
Starlight220
2022-12-15 19:40:14 +02:00
committed by GitHub
parent bf7068ac27
commit 701995d6cc
12 changed files with 104 additions and 26 deletions

View File

@@ -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;
};

View File

@@ -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();
};

View File

@@ -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

View File

@@ -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.
*/