Go to Post instead of complaining, suck it up, think a little harder, and make the most of what you do have. - Andy Grady [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
  #3   Spotlight this post!  
Unread 24-04-2016, 11:18
Pault's Avatar
Pault Pault is offline
Registered User
FRC #0246 (Overclocked)
Team Role: College Student
 
Join Date: Jan 2013
Rookie Year: 2012
Location: Boston
Posts: 618
Pault has a reputation beyond reputePault has a reputation beyond reputePault has a reputation beyond reputePault has a reputation beyond reputePault has a reputation beyond reputePault has a reputation beyond reputePault has a reputation beyond reputePault has a reputation beyond reputePault has a reputation beyond reputePault has a reputation beyond reputePault has a reputation beyond repute
Re: JAVA Command Group Question

This is a really annoying aspect of CommandGroup. Basically, all the code that you write for a CommandGroup is in the constructor. This means that the code itself is going to run instantaneously, probably when you first turn on the robot. What addSequential() and addParallel() do is pretty much just add the commands you requested into a queue. Those commands are then iterated through later when the CommandGroup is actually started.

What this means is that if you have a 3 line command group, like such:
Code:
Robot.drivedistance = 10;
addSequential(new Command1());
addSequestial(new Command2(Robot.drivedistance));
with Command1 containing the following line in its initialize method:
Code:
Robot.drivedistance = 100;
When the robot is turned on, the 3 lines of code in your CommandGroup will be executed. This means that drivedistance will be set to 10, then a new Command1() will be created and added to the queue, then a new Command2 will be created with the current value of Robot.drivedistance (which is 10) as the parameter, and added to the queue. When this command is actually run, Command1 will change Robot.drivedistance to be 100, but that doesn't matter because Command2 has already been told the distance it is supposed to drive.

There are a few different ways to fix this, although I don't consider any of them pretty. The simplest way is probably just to create a new command that will drive the distance specified by Robot.drivedistance, and have it be separate from your normal driveRobotToDistance command. In this new command you should check what the value of Robot.drivedistance is in the initialize method, not the constructor.
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 18:10.

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