jfitz0807
18-01-2013, 22:50
I created a Drive1 command class as follows:
public class Drive1 extends Command {
public Drive1() {
// Use requires() here to declare subsystem dependencies
// eg. requires(chassis);
requires(Robot.driveTrain);
// BEGIN AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=REQUIRES
// END AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=REQUIRES
}
private Timer timer;
private boolean running;
// Called just before this Command runs the first time
protected void initialize() {
timer.start();
timer.reset();
}
// Called repeatedly when this Command is scheduled to run
protected void execute() {
if (running != true) {
running = true;
timer.reset() ;
}
Robot.driveTrain.runMotor1( 0.5 );
}
// Make this return true when this Command no longer needs to run execute()
protected boolean isFinished() {
return timer.get() > 3.0e6;
}
// Called once after isFinished returns true
protected void end() {
Robot.driveTrain.runMotor1( 0 );
}
// Called when another command which requires one or more of the same
// subsystems is scheduled to run
protected void interrupted() {
end();
}
I would expect this command to run the motor connected to jaguar1 for 3 seconds at half speed. It's not doing anything.
I put numerous System.out.println calls throughout my code to try to see what's happening. Maybe some of this is my lack of java proficiency, but I'm having trouble understanding how this is behaving.
In my Oi constructor, I have the following:
joystickButton2 = new JoystickButton(joystick1, 2);
joystickButton2.whenPressed(new Drive1());
I expected this to construct a new Drive1() command when button2 on joystick1 is pressed. My printlns indicate that the constructor of Drive1 is being called in Disabled mode. I would not have expected this constructor to be called until the button was pressed.
Any thoughts?
The next thing I did was to construct a Drive1() command in the disabledInit() method. I expected this to construct a Drive1 command. In any case, how does this newly constructed command become runnable? Do I have to do anything else to make it's execute() method get called on every iteration?
public class Drive1 extends Command {
public Drive1() {
// Use requires() here to declare subsystem dependencies
// eg. requires(chassis);
requires(Robot.driveTrain);
// BEGIN AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=REQUIRES
// END AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=REQUIRES
}
private Timer timer;
private boolean running;
// Called just before this Command runs the first time
protected void initialize() {
timer.start();
timer.reset();
}
// Called repeatedly when this Command is scheduled to run
protected void execute() {
if (running != true) {
running = true;
timer.reset() ;
}
Robot.driveTrain.runMotor1( 0.5 );
}
// Make this return true when this Command no longer needs to run execute()
protected boolean isFinished() {
return timer.get() > 3.0e6;
}
// Called once after isFinished returns true
protected void end() {
Robot.driveTrain.runMotor1( 0 );
}
// Called when another command which requires one or more of the same
// subsystems is scheduled to run
protected void interrupted() {
end();
}
I would expect this command to run the motor connected to jaguar1 for 3 seconds at half speed. It's not doing anything.
I put numerous System.out.println calls throughout my code to try to see what's happening. Maybe some of this is my lack of java proficiency, but I'm having trouble understanding how this is behaving.
In my Oi constructor, I have the following:
joystickButton2 = new JoystickButton(joystick1, 2);
joystickButton2.whenPressed(new Drive1());
I expected this to construct a new Drive1() command when button2 on joystick1 is pressed. My printlns indicate that the constructor of Drive1 is being called in Disabled mode. I would not have expected this constructor to be called until the button was pressed.
Any thoughts?
The next thing I did was to construct a Drive1() command in the disabledInit() method. I expected this to construct a Drive1 command. In any case, how does this newly constructed command become runnable? Do I have to do anything else to make it's execute() method get called on every iteration?