mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-25 01:41:43 +00:00
[examples] Reorganize templates to use CommandsV2 (#8432)
Change Commandbased to Commandv2 Run example check on templates
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
// 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.
|
||||
|
||||
#include "Robot.hpp"
|
||||
|
||||
#include "wpi/commands2/CommandScheduler.hpp"
|
||||
|
||||
Robot::Robot() {}
|
||||
|
||||
void Robot::RobotPeriodic() {
|
||||
wpi::cmd::CommandScheduler::GetInstance().Run();
|
||||
}
|
||||
|
||||
void Robot::DisabledInit() {}
|
||||
|
||||
void Robot::DisabledPeriodic() {}
|
||||
|
||||
void Robot::DisabledExit() {}
|
||||
|
||||
void Robot::AutonomousInit() {
|
||||
m_autonomousCommand = m_container.GetAutonomousCommand();
|
||||
|
||||
if (m_autonomousCommand) {
|
||||
wpi::cmd::CommandScheduler::GetInstance().Schedule(
|
||||
m_autonomousCommand.value());
|
||||
}
|
||||
}
|
||||
|
||||
void Robot::AutonomousPeriodic() {}
|
||||
|
||||
void Robot::AutonomousExit() {}
|
||||
|
||||
void Robot::TeleopInit() {
|
||||
if (m_autonomousCommand) {
|
||||
m_autonomousCommand->Cancel();
|
||||
}
|
||||
}
|
||||
|
||||
void Robot::TeleopPeriodic() {}
|
||||
|
||||
void Robot::TeleopExit() {}
|
||||
|
||||
void Robot::TestInit() {
|
||||
wpi::cmd::CommandScheduler::GetInstance().CancelAll();
|
||||
}
|
||||
|
||||
void Robot::TestPeriodic() {}
|
||||
|
||||
void Robot::TestExit() {}
|
||||
|
||||
#ifndef RUNNING_WPILIB_TESTS
|
||||
int main() {
|
||||
return wpi::StartRobot<Robot>();
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,17 @@
|
||||
// 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.
|
||||
|
||||
#include "RobotContainer.hpp"
|
||||
|
||||
#include "wpi/commands2/Commands.hpp"
|
||||
|
||||
RobotContainer::RobotContainer() {
|
||||
ConfigureBindings();
|
||||
}
|
||||
|
||||
void RobotContainer::ConfigureBindings() {}
|
||||
|
||||
wpi::cmd::CommandPtr RobotContainer::GetAutonomousCommand() {
|
||||
return wpi::cmd::cmd::Print("No autonomous command configured");
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
// 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 <optional>
|
||||
|
||||
#include "RobotContainer.hpp"
|
||||
#include "wpi/commands2/CommandPtr.hpp"
|
||||
#include "wpi/framework/TimedRobot.hpp"
|
||||
|
||||
class Robot : public wpi::TimedRobot {
|
||||
public:
|
||||
Robot();
|
||||
void RobotPeriodic() override;
|
||||
void DisabledInit() override;
|
||||
void DisabledPeriodic() override;
|
||||
void DisabledExit() override;
|
||||
void AutonomousInit() override;
|
||||
void AutonomousPeriodic() override;
|
||||
void AutonomousExit() override;
|
||||
void TeleopInit() override;
|
||||
void TeleopPeriodic() override;
|
||||
void TeleopExit() override;
|
||||
void TestInit() override;
|
||||
void TestPeriodic() override;
|
||||
void TestExit() override;
|
||||
|
||||
private:
|
||||
std::optional<wpi::cmd::CommandPtr> m_autonomousCommand;
|
||||
|
||||
RobotContainer m_container;
|
||||
};
|
||||
@@ -0,0 +1,17 @@
|
||||
// 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 "wpi/commands2/CommandPtr.hpp"
|
||||
|
||||
class RobotContainer {
|
||||
public:
|
||||
RobotContainer();
|
||||
|
||||
wpi::cmd::CommandPtr GetAutonomousCommand();
|
||||
|
||||
private:
|
||||
void ConfigureBindings();
|
||||
};
|
||||
Reference in New Issue
Block a user