Go to Post If you think it is such an outrage, then be a do-er and not a talk-er. - BrianBSL [more]
Home
Go Back   Chief Delphi > Technical > Programming
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
  #4   Spotlight this post!  
Unread 22-05-2015, 21:12
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: pass a value to a command.

Quote:
Originally Posted by cpapplefamily View Post
Is what I had:
Code:
public class  DriveSpinInPlace extends Command {
	
    private static LinkedList<Double> fifo = null;
    private static double averagegyro = 0;
    private static boolean sample_gyro = false;
    private static double spin = 0;                         //Declared my "spin" Var 
    private static double spinTarget = 0;
    
    public DriveSpinInPlace(double s) {
        
        requires(Robot.driveSystem);
        spin = s;                                         //Set the spin = passed par
    }

    protected void initialize() {
    	
    	sample_gyro = false;
    	fifo = new LinkedList<Double>();
    	fifo.clear();	
    }

   
    protected void execute() {
        //Do my code
    }
 protected boolean isFinished() {
        return sample_gyro && averagegyro > spinTarget-10 && averagegyro < spinTarget+10;
    }

   
    protected void end() {
    	Robot.driveSystem.driveStraight(0,0);
    }

    // Called when another command which requires one or more of the same
    // subsystems is scheduled to run
    protected void interrupted() {
    	end();
    }
}
But all ways reacted to last addSequential(new DriveSpinInPlace(90));
If I have:

Code:
addSequential(new DriveSpinInPlace(90))
addSequential(new DriveSpinInPlace(-180))
addSequential(new DriveSpinInPlace(90))
addSequential(new DriveSpinInPlace(-95))
addSequential(new DriveSpinInPlace(-45))
Every all 5 scheduled commands will do -45.

Am I declaring the correct type of variable?
Yes. Get rid of "static" in front of every variable. That should fix your problem.

What static does is that it basically means the variable will have the same value for every command that you create. And because of the way that CommandGroups work (basically, it will call the constructor of every single command the moment it is created), the last value that you set will be the value that stays in your spin variable for the entire execution.
 


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 21:03.

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