Skip to content

Commit

Permalink
[commands, documentation] Update RapidReactCommandBot example
Browse files Browse the repository at this point in the history
  • Loading branch information
spacey-sooty committed Jul 21, 2024
1 parent 9338e64 commit 4181cbf
Show file tree
Hide file tree
Showing 7 changed files with 129 additions and 337 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,53 +4,51 @@

#include "Robot.h"

Robot::Robot() {
// Configure default commands and condition bindings on robot startup
m_robot.ConfigureBindings();
}

void Robot::RobotPeriodic() {
// Runs the Scheduler. This is responsible for polling buttons, adding
// newly-scheduled commands, running already-scheduled commands, removing
// finished or interrupted commands, and running subsystem Periodic() methods.
// This must be called from the robot's periodic block in order for anything
// in the Command-based framework to work.
frc2::CommandScheduler::GetInstance().Run();
}

void Robot::DisabledInit() {}

void Robot::DisabledPeriodic() {}

void Robot::AutonomousInit() {
m_autonomousCommand = m_robot.GetAutonomousCommand();
#include <frc2/command/Command.h>
#include <frc2/command/Commands.h>
#include <frc2/command/button/Trigger.h>

if (m_autonomousCommand) {
m_autonomousCommand->Schedule();
}
}

void Robot::AutonomousPeriodic() {}

void Robot::TeleopInit() {
// This makes sure that the autonomous stops running when
// teleop starts running. If you want the autonomous to
// continue until interrupted by another command, remove
// this line or comment it out.
if (m_autonomousCommand) {
m_autonomousCommand->Cancel();
}
}
#include "Constants.h"

void Robot::TeleopPeriodic() {}

void Robot::TestInit() {
// Cancels all running commands at the start of test mode.
frc2::CommandScheduler::GetInstance().CancelAll();
Robot::Robot() {

Check failure on line 13 in wpilibcExamples/src/main/cpp/examples/RapidReactCommandBot/cpp/Robot.cpp

View workflow job for this annotation

GitHub Actions / Build - Windows

'frc2::CommandPtr': no appropriate default constructor available
// Automatically run the storage motor whenever the ball storage is not full,
// and turn it off whenever it fills. Uses subsystem-hosted trigger to
// improve readability and make inter-subsystem communication easier.
m_storage.HasCargo.WhileFalse(m_storage.RunCommand());

// Automatically disable and retract the intake whenever the ball storage is
// full.
m_storage.HasCargo.OnTrue(m_intake.RetractCommand());

// Control the drive with split-stick arcade controls
m_drive.SetDefaultCommand(m_drive.ArcadeDriveCommand(
[this] { return -m_driverController.GetLeftY(); },
[this] { return -m_driverController.GetRightX(); }));

// Deploy the intake with the X button
m_driverController.X().OnTrue(m_intake.IntakeCommand());
// Retract the intake with the Y button
m_driverController.Y().OnTrue(m_intake.RetractCommand());

// Fire the shooter with the A button
m_driverController.A().OnTrue(
frc2::cmd::Parallel(
m_shooter.ShootCommand(ShooterConstants::kShooterTarget),
m_storage.RunCommand())
// Since we composed this inline we should give it a name
.WithName("Shoot"));

// Toggle compressor with the Start button
m_driverController.Start().ToggleOnTrue(
m_pneumatics.DisableCompressorCommand());

m_exampleAuto = m_drive
.DriveDistanceCommand(AutoConstants::kDriveDistance,
AutoConstants::kDriveSpeed)
.WithTimeout(AutoConstants::kTimeout);
m_autoChooser.SetDefaultOption("Example Auto", m_exampleAuto.get());
}

void Robot::TestPeriodic() {}

#ifndef RUNNING_FRC_TESTS
int main() {
return frc::StartRobot<Robot>();
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,32 @@

#pragma once

#include <optional>

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

#include "RapidReactCommandBot.h"
#include "Constants.h"
#include "subsystems/Drive.h"
#include "subsystems/Intake.h"
#include "subsystems/Pneumatics.h"
#include "subsystems/Shooter.h"
#include "subsystems/Storage.h"

class Robot : public frc::TimedRobot {
class Robot : public frc2::CommandRobot {
public:
Robot();
void RobotPeriodic() override;
void DisabledInit() override;
void DisabledPeriodic() override;
void AutonomousInit() override;
void AutonomousPeriodic() override;
void TeleopInit() override;
void TeleopPeriodic() override;
void TestInit() override;
void TestPeriodic() override;

private:
RapidReactCommandBot m_robot;
std::optional<frc2::CommandPtr> m_autonomousCommand;
// The robot's subsystems
Drive m_drive;
Intake m_intake;
Shooter m_shooter;
Storage m_storage;
Pneumatics m_pneumatics;

// The driver's controller
frc2::CommandXboxController m_driverController{
OIConstants::kDriverControllerPort};

frc2::CommandPtr m_exampleAuto;
};

This file was deleted.

Loading

0 comments on commit 4181cbf

Please sign in to comment.