Using test mode

It is important to verify the operation of the robot before using it for a match, demonstration or other task. So often wires can be pulled lose, circuit breakers are left out, or other issues that might cause the robot to not operate as expected. There are a number of strategies for testing your robot code. You might have a checklist where each subsystem is manually verified using the operator controls. You can also test the autonomous operation this way when the robot is off the ground can the operation can be observed.

Test mode is designed to enable programmers to have a place to put code to verify that all systems on the robot are functioning. In each of the robot program templates there is a place to add test code to the robot. If you use the IterativeRobot template, or use command-based programming you can easily see the operation of all the motors and sensors through the LiveWindow.

Enabling Test mode

Enabling Test mode

Test mode on the robot can be enabled from the Driver Station just like autonomous or teleop. When in test mode, the test() methods run. To enable test mode in the Driver Station, select the "Test" button and enable the robot. The test mode code will then run.

Adding Test mode code to your SimpleRobot template

Adding Test mode code to your SimpleRobot template

The SimpleRobot template is the easiest way to get started with robot programming, but it is somewhat limited when you try to add more features to the program. To add test code to a SimpleRobot based program add a method called test() (or Test() in C++). The test method will be called by the SimpleRobot base class when the robot is put into test mode from the Driver Station. Here you can add code to automatically test sensors and motors or send LiveWindow data to the SmartDashboard. In this Java example, we are:

  1. Adding all the sensors and actuators for the robot to the LiveWindow so that they can be displayed or manipulated
  2. Calling LiveWindow.run() periodically when in test mode to cause the values to update.

Additional robot test code can be added in the test method as well. For example, you might want to run some motors and verify that encoders are operating. Code could be easily written to slowly turn a motor and check the encoder values. This would verify that the motor and the encoder are both working properly.

Test mode in the SmartDashboard

Test mode in the SmartDashboard

The above sample code produces the following output when the Driver Station is put into Test mode then enabled. YOu can operate the motors by moving the sliders and read the values of sensors such as the wrist potentiometer.

Notice that the values are grouped by the subsystem names to group related actuators and sensors for easy testing. The subsystem names are suppled in the AddActuator() and AddSensor() method calls as shown in the code examples. This grouping, while not required, makes it much easier to test one subsystem at a time and have all the values next to each other on the screen.

Using Test mode with the IterativeRobot template

Using Test mode with the IterativeRobot template

The IterativeRobot template lends itself quite nicely to testing since it will periodically call the test() method (or Test() in C++) in your robot program. The test() method will be called with each DriverStation update, about every 20ms, and it is a good place to do whatever testing commands or LiveWindow updates are desired for testing. The LiveWindow updating is built into the IterativeRobot template so there is very little that is necessary to do in the program to get LiveWindow updates. Note: this works even if you are using the IterativeRobot template and not doing Command-based programming.

In this example the sensors are registered with the LiveWindow and during the testPeriodic method, simply update all the values by calling the LiveWindow run() method. If you're program is causing too much network traffic you can call the run method less frequently by, for example, only calling it every 5 updates for a 100ms update rate.

PID Tuning in Test mode

PID Tuning in Test mode

Tuning PID loops is often a challenging prospect with frequent recompiles of the program to get the correct values. When using the command based programming model, writing PID subsystems to the robot displays and allows adjustment of PID constants with immediate feedback of the results. See more information about PID Tuning using the SmartDashboard in this section from the SmartDashboard manual.