Team 1726 is programming their robot using C++ for the first time this year. We are having trouble getting commands to interrupt each other.
In our current test setup we have two commands: DriveForward and DriveBackwards, set to Joystick buttons. Each command requires the drivetrain subsystem, and has had SetInterruptable(true) called. The relevant snippets of code are:
Constructor from DriveForward.cpp:
DrivingForward::DrivingForward() : CommandBase("Foward") {
// Use Requires() here to declare subsystem dependencies
// eg. Requires(chassis.get());
Requires(drivetrain.get());
SetInterruptible(true);
}
Constructor from DriveBackwards.cpp:
DrivingBackward::DrivingBackward() : CommandBase("Backwards") {
// Use Requires() here to declare subsystem dependencies
// eg. Requires(chassis.get());
Requires(drivetrain.get());
SetInterruptible(true);
}
Class declaration from CommandBase.h:
class CommandBase: public frc::Command {
public:
CommandBase(const std::string& name);
CommandBase() = default;
// Create a single static instance of all of your subsystems
static std::unique_ptr<OI> oi;
static std::unique_ptr<DriveTrain> drivetrain;
};
Class definition from CommandBase.cpp:
std::unique_ptr<OI> CommandBase::oi = std::make_unique<OI>();
std::unique_ptr<DriveTrain> CommandBase::drivetrain = std::make_unique<DriveTrain>();
CommandBase::CommandBase(const std::string &name) :
frc::Command(name) {
}
Constructor from OI.cpp:
OI::OI() :
driver(JOY_DRIVER),
driverB(&driver, BUTTON_B),
driverA(&driver, BUTTON_A),
driverX(&driver, BUTTON_X)
{
// Process operator interface input here.
driverA.WhenPressed(new DrivingForward);
driverX.WhenPressed(new DrivingBackward);
}
The commands will execute successfully, but when a second command is started both commands will be trying to run at the same time.