Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Java (http://www.chiefdelphi.com/forums/forumdisplay.php?f=184)
-   -   Updating the Dashboard (http://www.chiefdelphi.com/forums/showthread.php?t=115454)

fovea1959 26-03-2013 10:14

Updating the Dashboard
 
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:

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);
    }

Are there alternative practices?

Ginto8 26-03-2013 15:20

Re: Updating the Dashboard
 
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.

Bryce Paputa 26-03-2013 15:49

Re: Updating the Dashboard
 
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.

shindigo 26-03-2013 21:17

Re: Updating the Dashboard
 
We're very interested in this:
Quote:

Originally Posted by Ginto8 (Post 1253040)
will send data regardless of whether the robot is enabled,

Any advice on an approach to this?

Ginto8 26-03-2013 22:11

Re: Updating the Dashboard
 
Quote:

Originally Posted by shindigo (Post 1253181)
Any advice on an approach to this?

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.

Joe Ross 26-03-2013 22:56

Re: Updating the Dashboard
 
Quote:

Originally Posted by Ginto8 (Post 1253040)
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.

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.

Ginto8 26-03-2013 23:17

Re: Updating the Dashboard
 
Quote:

Originally Posted by Joe Ross (Post 1253238)
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.

I didn't even realize this functionality existed. That's pretty awesome.


All times are GMT -5. The time now is 22:32.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi