Skip to content

Commit

Permalink
[documentation] Remove RobotContainer from templates
Browse files Browse the repository at this point in the history
  • Loading branch information
spacey-sooty committed Sep 8, 2024
1 parent cd9922a commit 2a1b85a
Show file tree
Hide file tree
Showing 12 changed files with 43 additions and 204 deletions.
13 changes: 11 additions & 2 deletions wpilibcExamples/src/main/cpp/templates/commandbased/cpp/Robot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,16 @@

#include <frc2/command/CommandScheduler.h>

Robot::Robot() {}
Robot::Robot() {
// Schedule `ExampleCommand` when `exampleCondition` changes to `true`
frc2::Trigger([this] {
return m_subsystem.ExampleCondition();
}).OnTrue(ExampleCommand(&m_subsystem).ToPtr());

// Schedule `ExampleMethodCommand` when the Xbox controller's B button is
// pressed, cancelling on release.
m_driverController.B().WhileTrue(m_subsystem.ExampleMethodCommand());
}

/**
* This function is called every 20 ms, no matter the mode. Use
Expand Down Expand Up @@ -34,7 +43,7 @@ void Robot::DisabledPeriodic() {}
* RobotContainer} class.
*/
void Robot::AutonomousInit() {
m_autonomousCommand = m_container.GetAutonomousCommand();
m_autonomousCommand = return autos::ExampleAuto(&m_subsystem);

if (m_autonomousCommand) {
m_autonomousCommand->Schedule();
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@

#include <frc/TimedRobot.h>
#include <frc2/command/CommandPtr.h>
#include <frc2/command/button/CommandXboxController.h>

#include "RobotContainer.h"
#include "Constants.h"
#include "subsystems/ExampleSubsystem.h"

class Robot : public frc::TimedRobot {
public:
Expand All @@ -30,5 +32,10 @@ class Robot : public frc::TimedRobot {
// doesn't have undefined behavior and potentially crash.
std::optional<frc2::CommandPtr> m_autonomousCommand;

RobotContainer m_container;
// Replace with CommandPS4Controller or CommandJoystick if needed
frc2::CommandXboxController m_driverController{
OperatorConstants::kDriverControllerPort};

// The robot's subsystems are defined here...
ExampleSubsystem m_subsystem;
};

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ void Robot::DisabledPeriodic() {}
void Robot::DisabledExit() {}

void Robot::AutonomousInit() {
m_autonomousCommand = m_container.GetAutonomousCommand();
m_autonomousCommand = frc2::cmd::Print("No autonomous command configured");

if (m_autonomousCommand) {
m_autonomousCommand->Schedule();
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
#include <frc/TimedRobot.h>
#include <frc2/command/CommandPtr.h>

#include "RobotContainer.h"

class Robot : public frc::TimedRobot {
public:
Robot();
Expand All @@ -30,6 +28,4 @@ class Robot : public frc::TimedRobot {

private:
std::optional<frc2::CommandPtr> m_autonomousCommand;

RobotContainer m_container;
};

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,15 @@
package edu.wpi.first.wpilibj.templates.commandbased;

import edu.wpi.first.wpilibj.TimedRobot;
import edu.wpi.first.wpilibj.templates.commandbased.subsystems.ExampleSubsystem;
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.CommandScheduler;
import edu.wpi.first.wpilibj2.command.button.CommandXboxController;
import edu.wpi.first.wpilibj2.command.button.Trigger;

import edu.wpi.first.wpilibj.templates.commandbased.Constants.OperatorConstants;
import edu.wpi.first.wpilibj.templates.commandbased.subsystems.ExampleSubsystem;
import edu.wpi.first.wpilibj.templates.commandbased.commands.ExampleCommand;

/**
* The methods in this class are called automatically corresponding to each mode, as described in
Expand All @@ -16,16 +23,25 @@
public class Robot extends TimedRobot {
private Command m_autonomousCommand;

private final RobotContainer m_robotContainer;
// The robot's subsystems and commands are defined here...
private final ExampleSubsystem m_exampleSubsystem = new ExampleSubsystem();

// Replace with CommandPS4Controller or CommandJoystick if needed
private final CommandXboxController m_driverController =
new CommandXboxController(OperatorConstants.kDriverControllerPort);

/**
* This function is run when the robot is first started up and should be used for any
* initialization code.
*/
public Robot() {
// Instantiate our RobotContainer. This will perform all our button bindings, and put our
// autonomous chooser on the dashboard.
m_robotContainer = new RobotContainer();
// Schedule `ExampleCommand` when `exampleCondition` changes to `true`
new Trigger(m_exampleSubsystem::exampleCondition)
.onTrue(new ExampleCommand(m_exampleSubsystem));

// Schedule `exampleMethodCommand` when the Xbox controller's B button is pressed,
// cancelling on release.
m_driverController.b().whileTrue(m_exampleSubsystem.exampleMethodCommand());
}

/**
Expand Down Expand Up @@ -54,7 +70,7 @@ public void disabledPeriodic() {}
/** This autonomous runs the autonomous command selected by your {@link RobotContainer} class. */
@Override
public void autonomousInit() {
m_autonomousCommand = m_robotContainer.getAutonomousCommand();
m_autonomousCommand = Autos.exampleAuto(m_exampleSubsystem);

// schedule the autonomous command (example)
if (m_autonomousCommand != null) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
public class Robot extends TimedRobot {
private Command m_autonomousCommand;

private final RobotContainer m_robotContainer;

public Robot() {
m_robotContainer = new RobotContainer();
}
Expand All @@ -33,7 +31,7 @@ public void disabledExit() {}

@Override
public void autonomousInit() {
m_autonomousCommand = m_robotContainer.getAutonomousCommand();
m_autonomousCommand = Commands.print("No autonomous command configured");

if (m_autonomousCommand != null) {
m_autonomousCommand.schedule();
Expand Down

This file was deleted.

0 comments on commit 2a1b85a

Please sign in to comment.