Go to Post FIRST is supposed to be a learning experience. Learn first, win awards later. - evulish [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

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #9   Spotlight this post!  
Unread 27-01-2017, 00:02
wlogeais wlogeais is offline
Registered User
FRC #2177 (The Robettes)
Team Role: Mentor
 
Join Date: Feb 2016
Rookie Year: 2011
Location: Minnesota
Posts: 18
wlogeais is an unknown quantity at this point
Re: Building Commands at Runtime

Quote:
Originally Posted by dmelcer9 View Post
Last year, our team tried to have a modular autonomous command. The way this worked was something like this:

...

Then, in a CommandGroup created during AutonomousInit:

Code:
addSequential((Command)Robot.autoDefenseChooser.getSelected());
However, this runs into a few problems. The biggest problem was that the robot would crash if you enter Autonomous mode twice without power cycling the robot...
Here are two solutions to this: the boring way and the fun(ctional) way.
In my opion the root of this issue is from missuse of CommandGroup itself rather than alternatives which can be written for special situations like this.

Call option 3, and either boring or exciting if you like.
I'm maining use of your same 2 chooservars for this year as they are.

I'd just change the autonomousInit() to a new commandgroup-like alternative.

Code:
autonomousCommand = new MultiAutonomousStarter();
     // REPLACES ... =  chooser.getSelected();

// unchanged from wpilib default...
if (autonomousCommand != null)
	autonomousCommand.start();
And then depending on the situation any 'command' can behave like a CommandGroup with special powers too.

(such as here in my MultiAutonomousStarter example to handle your 2-choosers)

Code:
	private Command step1cmd;
	private Command step2cmd;
	
	public MultiAutonomousStarter() {
		// FOLLOWING is NOT needed because this command will work like a commandgroup.
		// requires(Robot.exampleSubsystem);
	}

	// here the chooser-setup  is locked in.
	protected void initialize() {
		step1cmd = Robot.autoStep1.getSelected();
		step2cmd = Robot.autoStep2.getSelected();
		
		step1cmd.start();
	}

	// Here a sequential-like handoff or other special control is maintained.
	protected void execute() {
		if ( step1cmd!=null && !step1cmd.isRunning())
		{
			step1cmd = null;
			step2cmd.start();
		}
			
	}

	// isFinished() { return false; } is required revised it could add its own flexibility...

	// end() {} is required but not relevant this time.

	// in this case Called when autonomous times out.
	protected void interrupted() {

		if ( step1cmd!=null && step1cmd.isRunning())
			step1cmd.cancel();

		if ( step2cmd!=null && !step2cmd.isRunning())
			step2cmd.cancel();
	}
Reply With Quote
 


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 09:50.

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