probably moving from LV to Java for 2014, starting to think about how we did some things in LV, and what the corresponding analogs in Java would be. Can’t start slinging code for a while, no cRIOs to practice with (all are on bots), so asking questions right now instead of trying.
If one has put together a command based Java robot, and one wants to have continuous updates in the dashboard of critical sensors, is creating and scheduling a TimerTask to do the updates a good practice? I’m looking at Frog Force’ 2013 code:
private static final TimerTask SpeedTask = new TimerTask(){
// ..
public void run() {
if(isOn()&& DriverStation.getInstance().isEnabled()){
SmartDashboard.putNumber("Shooter Output", output);
SmartDashboard.putNumber("gear tooth speed graph", speed);
SmartDashboard.putNumber("gear tooth speed view", speed);
// ...
}
}
};
private static final long SPEED_TASK_PERIOD = 60;
private static final Timer timer = new Timer();
static{
timer.schedule(SpeedTask, 0, SPEED_TASK_PERIOD);
}
We actually use a Command to update values to the dashboard, which, if you’re calling Scheduler.getInstance().run() in both Periodic() methods, has the same effect as that TimerTask (though a different frequency). I have considered changing it to something that will send data regardless of whether the robot is enabled, but I’m loathe to change working code any more than I have to. Maybe next year.
We used the timer task so we could change the frame rate of the speed control without effecting everything else, for most of the sensor stuff we either put it where the sensor was being used, or in the main file’s teleopPeriodic. Either way works, however, putting them in teleopPeriodic is probably a bit more organized.
Well, NetworkTables, SmartDashboard and sensors don’t depend on the robot being enabled; as far as I know, the only things hardware-wise that are really disabled by disabled mode are PWMs (and possibly normal digital outputs, but I have only know PWMs for certain). So if you have a TimerTask like in the original post, but remove the condition checking for an on/enabled state, it should continue sending data even in disabled mode.
If you call the setRunWhileDisabled method for your command and add the scheduler run to disabledPeriodic, you can run your command while disabled with minimal code changes.