mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
Add new C++ Command framework (#1785)
This is the C++ version of #1682. The old command framework is still available, but will be deprecated. Due to name conflicts, the new framework is in the frc2 namespace. Eventually (after the old command framework is removed in a future year) it will be moved into the main frc namespace.
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2019 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <frc2/command/CommandHelper.h>
|
||||
#include <frc2/command/SequentialCommandGroup.h>
|
||||
|
||||
#include "Constants.h"
|
||||
#include "commands/DriveDistance.h"
|
||||
#include "commands/ReleaseHatch.h"
|
||||
|
||||
/**
|
||||
* A complex auto command that drives forward, releases a hatch, and then drives
|
||||
* backward.
|
||||
*/
|
||||
class ComplexAuto
|
||||
: public frc2::CommandHelper<frc2::SequentialCommandGroup, ComplexAuto> {
|
||||
public:
|
||||
/**
|
||||
* Creates a new ComplexAuto.
|
||||
*
|
||||
* @param drive The drive subsystem this command will run on
|
||||
* @param hatch The hatch subsystem this command will run on
|
||||
*/
|
||||
ComplexAuto(DriveSubsystem* drive, HatchSubsystem* hatch);
|
||||
};
|
||||
@@ -0,0 +1,41 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2019 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <frc2/command/CommandBase.h>
|
||||
#include <frc2/command/CommandHelper.h>
|
||||
|
||||
#include "subsystems/DriveSubsystem.h"
|
||||
|
||||
/**
|
||||
* A command to drive the robot with joystick input passed in through lambdas.
|
||||
* Written explicitly for pedagogical purposes - actual code should inline a
|
||||
* command this simple with RunCommand.
|
||||
*
|
||||
* @see RunCommand
|
||||
*/
|
||||
class DefaultDrive
|
||||
: public frc2::CommandHelper<frc2::CommandBase, DefaultDrive> {
|
||||
public:
|
||||
/**
|
||||
* Creates a new DefaultDrive.
|
||||
*
|
||||
* @param subsystem The drive subsystem this command wil run on.
|
||||
* @param forward The control input for driving forwards/backwards
|
||||
* @param rotation The control input for turning
|
||||
*/
|
||||
DefaultDrive(DriveSubsystem* subsystem, std::function<double()> forward,
|
||||
std::function<double()> rotation);
|
||||
|
||||
void Execute() override;
|
||||
|
||||
private:
|
||||
DriveSubsystem* m_drive;
|
||||
std::function<double()> m_forward;
|
||||
std::function<double()> m_rotation;
|
||||
};
|
||||
@@ -0,0 +1,37 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2019 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <frc2/command/CommandBase.h>
|
||||
#include <frc2/command/CommandHelper.h>
|
||||
|
||||
#include "subsystems/DriveSubsystem.h"
|
||||
|
||||
class DriveDistance
|
||||
: public frc2::CommandHelper<frc2::CommandBase, DriveDistance> {
|
||||
public:
|
||||
/**
|
||||
* Creates a new DriveDistance.
|
||||
*
|
||||
* @param inches The number of inches the robot will drive
|
||||
* @param speed The speed at which the robot will drive
|
||||
* @param drive The drive subsystem on which this command will run
|
||||
*/
|
||||
DriveDistance(double inches, double speed, DriveSubsystem* subsystem);
|
||||
|
||||
void Initialize() override;
|
||||
|
||||
void End(bool interrupted) override;
|
||||
|
||||
bool IsFinished() override;
|
||||
|
||||
private:
|
||||
DriveSubsystem* m_drive;
|
||||
double m_distance;
|
||||
double m_speed;
|
||||
};
|
||||
@@ -0,0 +1,32 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2019 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <frc2/command/CommandBase.h>
|
||||
#include <frc2/command/CommandHelper.h>
|
||||
|
||||
#include "subsystems/HatchSubsystem.h"
|
||||
|
||||
/**
|
||||
* A simple command that grabs a hatch with the HatchSubsystem. Written
|
||||
* explicitly for pedagogical purposes. Actual code should inline a command
|
||||
* this simple with InstantCommand.
|
||||
*
|
||||
* @see InstantCommand
|
||||
*/
|
||||
class GrabHatch : public frc2::CommandHelper<frc2::CommandBase, GrabHatch> {
|
||||
public:
|
||||
explicit GrabHatch(HatchSubsystem* subsystem);
|
||||
|
||||
void Initialize() override;
|
||||
|
||||
bool IsFinished() override;
|
||||
|
||||
private:
|
||||
HatchSubsystem* m_hatch;
|
||||
};
|
||||
@@ -0,0 +1,26 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2019 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <frc2/command/CommandBase.h>
|
||||
#include <frc2/command/CommandHelper.h>
|
||||
|
||||
#include "subsystems/DriveSubsystem.h"
|
||||
|
||||
class HalveDriveSpeed
|
||||
: public frc2::CommandHelper<frc2::CommandBase, HalveDriveSpeed> {
|
||||
public:
|
||||
explicit HalveDriveSpeed(DriveSubsystem* subsystem);
|
||||
|
||||
void Initialize() override;
|
||||
|
||||
void End(bool interrupted) override;
|
||||
|
||||
private:
|
||||
DriveSubsystem* m_drive;
|
||||
};
|
||||
@@ -0,0 +1,33 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2019 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <frc2/command/CommandBase.h>
|
||||
#include <frc2/command/CommandHelper.h>
|
||||
|
||||
#include "subsystems/HatchSubsystem.h"
|
||||
|
||||
/**
|
||||
* A simple command that releases a hatch with the HatchSubsystem. Written
|
||||
* explicitly for pedagogical purposes. Actual code should inline a command
|
||||
* this simple with InstantCommand.
|
||||
*
|
||||
* @see InstantCommand
|
||||
*/
|
||||
class ReleaseHatch
|
||||
: public frc2::CommandHelper<frc2::CommandBase, ReleaseHatch> {
|
||||
public:
|
||||
explicit ReleaseHatch(HatchSubsystem* subsystem);
|
||||
|
||||
void Initialize() override;
|
||||
|
||||
bool IsFinished() override;
|
||||
|
||||
private:
|
||||
HatchSubsystem* m_hatch;
|
||||
};
|
||||
Reference in New Issue
Block a user