diff --git a/wpilibcExamples/src/main/cpp/templates/commandbasedskeleton/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/templates/commandbasedskeleton/cpp/Robot.cpp new file mode 100644 index 0000000000..32782b29ae --- /dev/null +++ b/wpilibcExamples/src/main/cpp/templates/commandbasedskeleton/cpp/Robot.cpp @@ -0,0 +1,55 @@ +// 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.h" + +#include + +void Robot::RobotInit() {} + +void Robot::RobotPeriodic() { + frc2::CommandScheduler::GetInstance().Run(); +} + +void Robot::DisabledInit() {} + +void Robot::DisabledPeriodic() {} + +void Robot::DisabledExit() {} + +void Robot::AutonomousInit() { + m_autonomousCommand = m_container.GetAutonomousCommand(); + + if (m_autonomousCommand) { + m_autonomousCommand->Schedule(); + } +} + +void Robot::AutonomousPeriodic() {} + +void Robot::AutonomousExit() {} + +void Robot::TeleopInit() { + if (m_autonomousCommand) { + m_autonomousCommand->Cancel(); + } +} + +void Robot::TeleopPeriodic() {} + +void Robot::TeleopExit() {} + +void Robot::TestInit() { + frc2::CommandScheduler::GetInstance().CancelAll(); +} + +void Robot::TestPeriodic() {} + +void Robot::TestExit() {} + +#ifndef RUNNING_FRC_TESTS +int main() { + return frc::StartRobot(); +} +#endif diff --git a/wpilibcExamples/src/main/cpp/templates/commandbasedskeleton/cpp/RobotContainer.cpp b/wpilibcExamples/src/main/cpp/templates/commandbasedskeleton/cpp/RobotContainer.cpp new file mode 100644 index 0000000000..e63532a8e3 --- /dev/null +++ b/wpilibcExamples/src/main/cpp/templates/commandbasedskeleton/cpp/RobotContainer.cpp @@ -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.h" + +#include + +RobotContainer::RobotContainer() { + ConfigureBindings(); +} + +void RobotContainer::ConfigureBindings() {} + +frc2::CommandPtr RobotContainer::GetAutonomousCommand() { + return frc2::cmd::Print("No autonomous command configured"); +} diff --git a/wpilibcExamples/src/main/cpp/templates/commandbasedskeleton/include/Robot.h b/wpilibcExamples/src/main/cpp/templates/commandbasedskeleton/include/Robot.h new file mode 100644 index 0000000000..6bdb217a2a --- /dev/null +++ b/wpilibcExamples/src/main/cpp/templates/commandbasedskeleton/include/Robot.h @@ -0,0 +1,35 @@ +// 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 + +#include +#include + +#include "RobotContainer.h" + +class Robot : public frc::TimedRobot { + public: + void RobotInit() override; + 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 m_autonomousCommand; + + RobotContainer m_container; +}; diff --git a/wpilibcExamples/src/main/cpp/templates/commandbasedskeleton/include/RobotContainer.h b/wpilibcExamples/src/main/cpp/templates/commandbasedskeleton/include/RobotContainer.h new file mode 100644 index 0000000000..a66653cfbc --- /dev/null +++ b/wpilibcExamples/src/main/cpp/templates/commandbasedskeleton/include/RobotContainer.h @@ -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 + +class RobotContainer { + public: + RobotContainer(); + + frc2::CommandPtr GetAutonomousCommand(); + + private: + void ConfigureBindings(); +}; diff --git a/wpilibcExamples/src/main/cpp/templates/templates.json b/wpilibcExamples/src/main/cpp/templates/templates.json index 83260a0458..67e443822f 100644 --- a/wpilibcExamples/src/main/cpp/templates/templates.json +++ b/wpilibcExamples/src/main/cpp/templates/templates.json @@ -9,6 +9,16 @@ "gradlebase": "cpp", "commandversion": 2 }, + { + "name": "Command Robot Skeleton (Advanced)", + "description": "Skeleton (stub) code for Command Robot", + "tags": [ + "Command", "Skeleton" + ], + "foldername": "commandbasedskeleton", + "gradlebase": "cpp", + "commandversion": 2 + }, { "name": "Timed Robot", "description": "Timed style", diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/commandbasedskeleton/Main.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/commandbasedskeleton/Main.java new file mode 100644 index 0000000000..efa0c2e716 --- /dev/null +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/commandbasedskeleton/Main.java @@ -0,0 +1,15 @@ +// 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. + +package edu.wpi.first.wpilibj.templates.commandbasedskeleton; + +import edu.wpi.first.wpilibj.RobotBase; + +public final class Main { + private Main() {} + + public static void main(String... args) { + RobotBase.startRobot(Robot::new); + } +} diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/commandbasedskeleton/Robot.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/commandbasedskeleton/Robot.java new file mode 100644 index 0000000000..f682ec87bd --- /dev/null +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/commandbasedskeleton/Robot.java @@ -0,0 +1,73 @@ +// 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. + +package edu.wpi.first.wpilibj.templates.commandbasedskeleton; + +import edu.wpi.first.wpilibj.TimedRobot; +import edu.wpi.first.wpilibj2.command.Command; +import edu.wpi.first.wpilibj2.command.CommandScheduler; + +public class Robot extends TimedRobot { + private Command m_autonomousCommand; + + private RobotContainer m_robotContainer; + + @Override + public void robotInit() { + m_robotContainer = new RobotContainer(); + } + + @Override + public void robotPeriodic() { + CommandScheduler.getInstance().run(); + } + + @Override + public void disabledInit() {} + + @Override + public void disabledPeriodic() {} + + @Override + public void disabledExit() {} + + @Override + public void autonomousInit() { + m_autonomousCommand = m_robotContainer.getAutonomousCommand(); + + if (m_autonomousCommand != null) { + m_autonomousCommand.schedule(); + } + } + + @Override + public void autonomousPeriodic() {} + + @Override + public void autonomousExit() {} + + @Override + public void teleopInit() { + if (m_autonomousCommand != null) { + m_autonomousCommand.cancel(); + } + } + + @Override + public void teleopPeriodic() {} + + @Override + public void teleopExit() {} + + @Override + public void testInit() { + CommandScheduler.getInstance().cancelAll(); + } + + @Override + public void testPeriodic() {} + + @Override + public void testExit() {} +} diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/commandbasedskeleton/RobotContainer.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/commandbasedskeleton/RobotContainer.java new file mode 100644 index 0000000000..d6e4d256a6 --- /dev/null +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/commandbasedskeleton/RobotContainer.java @@ -0,0 +1,20 @@ +// 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. + +package edu.wpi.first.wpilibj.templates.commandbasedskeleton; + +import edu.wpi.first.wpilibj2.command.Command; +import edu.wpi.first.wpilibj2.command.Commands; + +public class RobotContainer { + public RobotContainer() { + configureBindings(); + } + + private void configureBindings() {} + + public Command getAutonomousCommand() { + return Commands.print("No autonomous command configured"); + } +} diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/templates.json b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/templates.json index b2484cc05a..68e3bfb681 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/templates.json +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/templates.json @@ -10,6 +10,17 @@ "mainclass": "Main", "commandversion": 2 }, + { + "name": "Command Robot Skeleton (Advanced)", + "description": "Skeleton (stub) code for Command Robot", + "tags": [ + "Command", "Skeleton" + ], + "foldername": "commandbasedskeleton", + "gradlebase": "java", + "mainclass": "Main", + "commandversion": 2 + }, { "name": "Timed Robot", "description": "Timed style",