View Single Post
  #4   Spotlight this post!  
Unread 09-02-2014, 10:30
fovea1959's Avatar
fovea1959 fovea1959 is offline
Herder of programmers
AKA: Doug Wegscheid
FRC #3620 (The Average Joes)
Team Role: Mentor
 
Join Date: Jan 2011
Rookie Year: 2011
Location: St Joseph
Posts: 330
fovea1959 will become famous soon enough
Re: whileHeld() Motor Program Issue

whileHeld() works as advertised, you just need to remember to shut down things in end() and interrupted()...

Our experience last summer was whileHeld called init() once, (execute(), getFinished()) repeatedly, and interrupted() is called when the button is released. We used whileHeld reliably with commands like this (note that we stop the motor from end() and interrupted().

We would see multiple init() if several whileHelds fired off commands that required the same subsystem(s) and those buttons were held at the same time. I don't remember the exact details.

Code:
package org.usfirst.frc3620.FRC36202013RobotRedo.commands;

import edu.wpi.first.wpilibj.command.Command;
import org.usfirst.frc3620.FRC36202013RobotRedo.Robot;

/**
*
*/
public class FlipperBackwardCommand extends Command {

    public FlipperBackwardCommand() {
        // Use requires() here to declare subsystem dependencies
        // eg. requires(chassis);

        // BEGIN AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=REQUIRES
        requires(Robot.flipperSubsystem);
        // END AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=REQUIRES
    }

    // Called just before this Command runs the first time
    protected void initialize() {
    }

    // Called repeatedly when this Command is scheduled to run
    protected void execute() {
        Robot.flipperSubsystem.flipperBackward();
    }

    // Make this return true when this Command no longer needs to run execute()
    protected boolean isFinished() {
        return false;
    }

    // Called once after isFinished returns true
    protected void end() {
        Robot.flipperSubsystem.flipperStop();
    }

    // Called when another command which requires one or more of the same
    // subsystems is scheduled to run
    protected void interrupted() {
        end();
    }
}
Reply With Quote