|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
|||
|
|||
|
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();
}
}
If I have: Code:
addSequential(new DriveSpinInPlace(90)) addSequential(new DriveSpinInPlace(-180)) addSequential(new DriveSpinInPlace(90)) addSequential(new DriveSpinInPlace(-95)) addSequential(new DriveSpinInPlace(-45)) Am I declaring the correct type of variable? |
|
#2
|
||||
|
||||
|
Re: pass a value to a command.
Quote:
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
|
|||
|
|||
|
Re: pass a value to a command.
Thank you I'll give it a go. The Static was added automatically.
|
|
#4
|
|||
|
|||
|
That worked thanks. But you knew that already didn't you?
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|