Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Java (http://www.chiefdelphi.com/forums/forumdisplay.php?f=184)
-   -   Java Commandbase Subsystems: Init vs DefaultCommand (http://www.chiefdelphi.com/forums/showthread.php?t=126442)

feverittm 14-02-2014 13:03

Java Commandbase Subsystems: Init vs DefaultCommand
 
Here is a question for all you Java types:

Which (if either) way is 'better' (less intensive on the cRIO, easier to understand, etc).

In a command based template we have a compressor subsystem.

We could start the compressor (using the standard compressor.start() method) in the subsystems initialization call. We could also just create a simple command that just does a compressor.start() in its execute function and then call this as the compressor subsystem's default command.

Code:

    public subcompressor(int compressorSwitchSlot, int compressorSpikeSlot) {
        myCompressor = new Compressor(compressorSwitchSlot, compressorSpikeSlot);
        LiveWindow.addActuator("compressor", "compressor", myCompressor);
        myCompressor.start();
    }

or

Code:

    public subcompressor(int compressorSwitchSlot, int compressorSpikeSlot) {
        myCompressor = new Compressor(compressorSwitchSlot, compressorSpikeSlot);
        LiveWindow.addActuator("compressor", "compressor", myCompressor);
    }

    /**
    * Default command is to start the compressor.  Doing it this way instead
    * of in the initializer will put it in a separate thread and not lock the
    * main control thread.
    */

    public void initDefaultCommand() {
        setDefaultCommand(new StartCompressor());
    }

Is one way better then the other? Do both ways use separate threads from the main thread?

Just cleaning up code and wondering.

Thanks

notmattlythgoe 14-02-2014 13:07

Re: Java Commandbase Subsystems: Init vs DefaultCommand
 
Quote:

Originally Posted by feverittm (Post 1343078)
Here is a question for all you Java types:

Which (if either) way is 'better' (less intensive on the cRIO, easier to understand, etc).

In a command based template we have a compressor subsystem.

We could start the compressor (using the standard compressor.start() method) in the subsystems initialization call. We could also just create a simple command that just does a compressor.start() in its execute function and then call this as the compressor subsystem's default command.

Code:

    public subcompressor(int compressorSwitchSlot, int compressorSpikeSlot) {
        myCompressor = new Compressor(compressorSwitchSlot, compressorSpikeSlot);
        LiveWindow.addActuator("compressor", "compressor", myCompressor);
        myCompressor.start();
    }

or

Code:

    public subcompressor(int compressorSwitchSlot, int compressorSpikeSlot) {
        myCompressor = new Compressor(compressorSwitchSlot, compressorSpikeSlot);
        LiveWindow.addActuator("compressor", "compressor", myCompressor);
    }

    /**
    * Default command is to start the compressor.  Doing it this way instead
    * of in the initializer will put it in a separate thread and not lock the
    * main control thread.
    */

    public void initDefaultCommand() {
        setDefaultCommand(new StartCompressor());
    }

Is one way better then the other? Do both ways use separate threads from the main thread?

Just cleaning up code and wondering.

Thanks

We actually just create and start the compressor either in RobotTemplate or in CommandBase. But neither of those will use separate threads, the Command Based structure uses a Scheduler that runs on a single thread to execute all of the commands.

Joe Ross 14-02-2014 13:13

Re: Java Commandbase Subsystems: Init vs DefaultCommand
 
Quote:

Originally Posted by feverittm (Post 1343078)
We could start the compressor (using the standard compressor.start() method) in the subsystems initialization call.

This is the slightly less intensive option. It doesn't make the scheduler do anything extra.

Quote:

Do both ways use separate threads from the main thread?
They both use separate threads, because the Compressor class creates a separate thread.

notmattlythgoe 14-02-2014 13:14

Re: Java Commandbase Subsystems: Init vs DefaultCommand
 
Quote:

Originally Posted by Joe Ross (Post 1343083)
This is the slightly less intensive option. It doesn't make the scheduler do anything extra.



They both use separate threads, because the Compressor class creates a separate thread.

Ahh, my fault.


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

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