Go to Post Once you try hex you'll never go back. - IndySam [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
 
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 14-02-2014, 13:03
feverittm's Avatar
feverittm feverittm is offline
Registered User
FRC #0997 (Spartans)
Team Role: Mentor
 
Join Date: Apr 2010
Rookie Year: 2010
Location: Corvallis, OR
Posts: 121
feverittm will become famous soon enoughfeverittm will become famous soon enough
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
__________________
Floyd Moore
Mentor Electrical and Pneumatics
Team 997 - Spartan Robotics
Corvallis High School, Corvallis Oregon
Reply With Quote
  #2   Spotlight this post!  
Unread 14-02-2014, 13:07
notmattlythgoe's Avatar
notmattlythgoe notmattlythgoe is offline
Flywheel Police
AKA: Matthew Lythgoe
FRC #2363 (Triple Helix)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2009
Location: Newport News, VA
Posts: 1,717
notmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond repute
Re: Java Commandbase Subsystems: Init vs DefaultCommand

Quote:
Originally Posted by feverittm View Post
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.
Reply With Quote
  #3   Spotlight this post!  
Unread 14-02-2014, 13:13
Joe Ross's Avatar Unsung FIRST Hero
Joe Ross Joe Ross is offline
Registered User
FRC #0330 (Beachbots)
Team Role: Engineer
 
Join Date: Jun 2001
Rookie Year: 1997
Location: Los Angeles, CA
Posts: 8,567
Joe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond repute
Re: Java Commandbase Subsystems: Init vs DefaultCommand

Quote:
Originally Posted by feverittm View Post
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.
Reply With Quote
  #4   Spotlight this post!  
Unread 14-02-2014, 13:14
notmattlythgoe's Avatar
notmattlythgoe notmattlythgoe is offline
Flywheel Police
AKA: Matthew Lythgoe
FRC #2363 (Triple Helix)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2009
Location: Newport News, VA
Posts: 1,717
notmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond repute
Re: Java Commandbase Subsystems: Init vs DefaultCommand

Quote:
Originally Posted by Joe Ross View Post
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.
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


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

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


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