So here’s the problem, we’re trying to make a command in where the robot drive forward for a short time, and then stops. Mainly just for testing purposes, but we ran into an issue.
Depending on which wait command we use, the robot displays different behaviour, none of which is intended. If frc2::cmd::Wait();
is used then the robot never stops waiting and continues to drive. If frc2::WaitCommand();
is used then the robot instantly skips to being finished, and does not move.
Its probably something simple which I’m just missing, any help would be greatly appreciated, all relevant files I can think of are below.
TestAuto.cpp :
#include "commands/TestAuto.h"
TestAuto::TestAuto(units::second_t time, double speed, DriveSubsystem* subsystem)
: m_drive(subsystem), m_time(time), m_speed(speed) {
AddRequirements({subsystem});
}
void TestAuto::Initialize() {
m_drive->ResetEncoders();
m_drive->ArcadeDrive(m_speed, 0.5);
// This Wait command causes the robot to never stop moving
frc2::cmd::Wait(m_time);
//This Wait command, just doesn't work, and gets skipped over instantly
frc2::WaitCommand(m_time);
m_isFinished = true;
}
void TestAuto::Execute() { m_drive->ArcadeDrive(m_speed, 0); }
void TestAuto::End(bool interrupted) { m_drive->ArcadeDrive(0, 0); }
bool TestAuto::IsFinished() { return m_isFinished; }
TestAuto.h :
#pragma once
#include <frc2/command/CommandBase.h>
#include <frc2/command/CommandHelper.h>
#include <frc2/command/Commands.h>
#include <frc2/command/WaitCommand.h>
#include <frc2/command/CommandPtr.h>
#include "subsystems/DriveSubsystem.h"
class TestAuto : public frc2::CommandHelper<frc2::CommandBase, BalanceAuto> {
public:
/**
* Creates a new TestAuto.
*
* @param time The amount of seconds that 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
*/
explicit TestAuto (units::second_t time, double speed, DriveSubsystem* subsystem);
void Initialize() override;
void Execute() override;
void End(bool interrupted) override;
bool IsFinished() override;
private:
DriveSubsystem* m_drive;
units::second_t m_time;
double m_speed;
bool m_isFinished = false;
bool m_isComposed = true;
};
And here’s the relevant RobotContainer file that runs the actual command:
#include "RobotContainer.h"
RobotContainer::RobotContainer() { ConfigureBindings(); }
void RobotContainer::ConfigureBindings() {
m_drive.SetDefaultCommand(
frc2::cmd::Run([this] { m_drive.ArcadeDrive(-m_driverController.GetLeftY(), m_driverController.GetRightX()); },
{&m_drive}));
}
frc2::CommandPtr RobotContainer::GetAutonomousCommand() {
TestAuto testAuto = TestAuto(0.3_s, 0.5, &m_drive);
//The print is mainly for logging reasons, but it does confirm that testAuto is being run,
//at least we think it is.
return frc2::CommandPtr(testAuto).AsProxy().AndThen(frc2::cmd::Print("ahoy-hoy"));
};