[examples] Reorganize templates to use CommandsV2 (#8432)

Change Commandbased to Commandv2
Run example check on templates
This commit is contained in:
sciencewhiz
2025-11-29 20:46:32 -08:00
committed by GitHub
parent 5aa0b7afea
commit e902a98601
44 changed files with 119 additions and 115 deletions

View File

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

View File

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

View File

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

View File

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