View Single Post
  #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.