Running a command in test mode

I have a command that I used putData to put it on the smartdashboard.

 this.subsystem = subsystem;
// Use addRequirements() here to declare subsystem dependencies.

When I run my robot under the Desktop Simulator, the simulator GUI shows a box with the command name and a button that says “run”. If the robot is in auto or teleop mode and I click run, the button changes to “cancel” and the command runs. But if I click the run button when the robot is in test mode it sort of flashes and immediately goes back to run. In the NT telemetry output it shows the command “running” state going from false, to true and immediately back to false. The command never runs.

Why doesn’t the command run in test mode? I thought test mode was specifically designed to be able to run command manually like this. Did I miss a step somewhere?

Add CommandScheduler.getInstance().run() to Robot.testPeriodic

The default behavior of test mode in WPILib is LiveWindow, which is designed for accessing motors/sensors from a dashboard (bypassing code entirely). You can run commands manually in “normal” teleop mode.

We used Test mode to run a command to reset our shooter hood and climber this year. Done similarly to autonomous

   public void testInit() { 
     // Cancels all running commands at the start of test mode. 
     m_testCommand = m_robotContainer.getTest(); 
     // schedule the test command (example) 
     if (m_testCommand != null) { 
1 Like

This wouldn’t work, run is a no-op when the scheduler is disabled.

Two options:

  • You can disable LiveWindow using LiveWindow.setEnabled(false). This will enable the scheduler automatically.
  • Directly enable the scheduler using CommandScheduler.getInstance().enable(). Note that this might cause issues if hardware is accessed from LiveWindow while commands are running.

Some relevant GH Issues are and

1 Like