Go to Post We're all human, we all make mistakes. How you deal with mistakes and problems, is what really elevates successful people, robotics teams, organizations, etc. above the rest. - artdutra04 [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

 
Closed Thread
 
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 22-05-2015, 20:22
cpapplefamily cpapplefamily is offline
Registered User
FRC #3244 (Granite City Gearheads)
Team Role: Mentor
 
Join Date: May 2015
Rookie Year: 2015
Location: Minnesota
Posts: 250
cpapplefamily has a spectacular aura aboutcpapplefamily has a spectacular aura about
Re: pass a value to a command.

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?
  #2   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.
  #3   Spotlight this post!  
Unread 22-05-2015, 21:54
cpapplefamily cpapplefamily is offline
Registered User
FRC #3244 (Granite City Gearheads)
Team Role: Mentor
 
Join Date: May 2015
Rookie Year: 2015
Location: Minnesota
Posts: 250
cpapplefamily has a spectacular aura aboutcpapplefamily has a spectacular aura about
Re: pass a value to a command.

Thank you I'll give it a go. The Static was added automatically.
  #4   Spotlight this post!  
Unread 23-05-2015, 21:02
cpapplefamily cpapplefamily is offline
Registered User
FRC #3244 (Granite City Gearheads)
Team Role: Mentor
 
Join Date: May 2015
Rookie Year: 2015
Location: Minnesota
Posts: 250
cpapplefamily has a spectacular aura aboutcpapplefamily has a spectacular aura about
Thumbs up Re: pass a value to a command.

That worked thanks. But you knew that already didn't you?
Closed Thread


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 01:39.

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