View Single Post
  #7   Spotlight this post!  
Unread 24-04-2016, 16:28
MrRoboSteve MrRoboSteve is offline
Mentor
AKA: Steve Peterson
FRC #3081 (Kennedy RoboEagles)
Team Role: Mentor
 
Join Date: Mar 2012
Rookie Year: 2011
Location: Bloomington, MN
Posts: 570
MrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond repute
Re: JAVA Command Group Question

Quote:
Originally Posted by buckskinner1776 View Post
This command seems to execute with the initial 10" instead of the 100".
Lacking source code, both Gus and Pault's theories could easily be true. They're both theories about scoping and order of evaluation.

As an aside, I think Pault's criticism of the CommandGroup is more about the subtleties of Java's pass-by-value semantics. A statement like:

Code:
addSequestial(new Command2(Robot.drivedistance));
means "create a command with the current value of Robot.drivedistance". At the point the JVM news up a Command2, it takes whatever the value is of Robot.drivedistance, and passes it in as a parameter.

Here is an easy way to use CommandGroups to achieve what Pault is desiring, without a lot of extra code.

Suppose you have two Commands, CalculateDistanceToShootingPosition and DriveForward. You want to execute them in sequence in a CommandGroup. You could say something like this in the CommandGroup's constructor:

Code:
DriveForward df = new DriveForward();
CalculateDistanceToShootingPosition calc = 
  new CalculateDistanceToShootingPosition(df);
addSequential(calc);
addSequential(df);
Now, suppose that DriveForward has a method SetDistanceToDriveInInches(). In CalculateDistanceToShootingPosition.Execute(), you'd do the calculation and then call SetDistanceToDriveInInches(). Later, when DriveForward runs, it has the correct value to drive to. This uses the correct value, and eliminates a global variable, making DriveForward more flexible and easier to reason about.
__________________
2016-17 events: 10000 Lakes Regional, Northern Lights Regional, FTC Burnsville Qualifying Tournament

2011 - present · FRC 3081 Kennedy RoboEagles mentor
2013 - present · event volunteer at 10000 Lakes Regional, Northern Lights Regional, North Star Regional, Lake Superior Regional, Minnesota State Tournament, PNW District 4 Glacier Peak, MN FTC, CMP
http://twitter.com/MrRoboSteve · www.linkedin.com/in/speterson
Reply With Quote