|
|
|
![]() |
|
|||||||
|
||||||||
|
|
Thread Tools | Rate Thread | Display Modes |
|
#4
|
|||
|
|||
|
Re: CommandGroup questions
Thanks for the explanations. If I understand things correctly, when the goal is to build a command group that has the following pattern:
There are at least two ways to code this: Option A: Don't mix addParallel() and addSequential() (use nested CommandGroup objects instead): Code:
public static Command buildMyCommand() {
CommandGroup bc = new CommandGroup();
bc.addParallel(new CommandB());
bc.addParallel(new CommandC());
CommandGroup cmd = new CommandGroup();
cmd.addSequential(new CommandA());
cmd.addSequential(bc);
cmd.addSequential(new CommandD());
return cmd;
}
Code:
public static Command buildMyCommand() {
CommandGroup cmd = new CommandGroup();
// CommandA is the first command to run
cmd.addSequential(new CommandA());
// Start a command in parallel after CommandA finishes
cmd.addParallel(new CommandB());
// Start a sequential command (also starts after CommandA finishes
// runs at the same time as CommandB)
cmd.addSequential(new CommandC());
// Wait for CommandB and CommandC to finish
cmd.addSequential(new WaitForChildren());
// Now it is OK to run CommandD (both CommandB and CommandC are done)
cmd.addSequential(new CommandD());
return cmd;
}
Option C: Mix addParallel() and addSequential(), similar to Option B, but uses addParallel() for CommandB and CommandC (which might be slightly more intuitive to look at): Code:
public static Command buildMyCommand() {
CommandGroup cmd = new CommandGroup();
// CommandA is the first command to run
cmd.addSequential(new CommandA());
// Start a command in parallel after CommandA finishes
cmd.addParallel(new CommandB());
// Start a parallel command (also starts after CommandA finishes
// runs at the same time as CommandB)
cmd.addParallel(new CommandC());
// Wait for CommandB and CommandC to finish
cmd.addSequential(new WaitForChildren());
// Now it is OK to run CommandD (both CommandB and CommandC are done)
cmd.addSequential(new CommandD());
return cmd;
}
I think I prefer the nested command groups (Option A) for readability (human comprehension). Unless someone tells me this won't work, I will encourage this general rule of thumb when we introduce CommandGroups to new programmers joining the team (at least to get them started). We will also need to review our command groups and think about the different behaviors between timeouts and interrupted situations. I suspect we have some commands that need to be coded a little more defensively so we don't break things on the robot for certain time outs (if CommandA times out, we may not want to run CommandB in the sequence). Thanks again for the information, Paul Last edited by pblankenbaker : 13-02-2014 at 13:54. |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|