Help with buttons and timed sequences

I have finally figured out how to add a button in java. Now though, I am not sure how to make a timed sequence or how to add a motor that the button activates. Do I create a new subsystem? Or is it just certain commands?

Are you coming to the MN Splash tomorrow? A couple members of my team will be giving a comprehensive overview of how to do everything in Java that would probably answer all of your questions. The presentation contains just about all of the main parts of our code from last year, and would show you exactly how to get everything started, set up your subsystems, set up commands to act on those subsystems, and link all of that to your OI.

If you can’t make it to Splash (it looks like you’re a bit far north), contact us at [email protected], and our lead programmer can get you the presentation, and possibly set up a skype chat to walk through it at some point.

If you’re still looking for help on this, there are some good resources online.

It sounds like you’re using the Command Based robot project.
If so, you’re typically going to want your commands to start/stop conditionally. Typically this starts/stops based on sensor statuses (switches/encoders/etc.) or operator inputs (button presses. (based on sensor input). Alternatively you could have time stop a command as well (See below).

General info on the command based robot project: here
How to associate a command with a joystick button: here

To answer your question specifically…

I am not sure how to make a timed sequence or how to add a motor that the button activates.I am not sure how to make a timed sequence or how to add a motor that the button activates.

First you’re going to want to create a subsystem which has methods to control the motors on the subsystem in question. So if for example you have a frisbee shooter with two wheels on it… you might have some thing like this for subsystem code:

public class Shooter extends Subsystem {
        Victor shooterVictorFwd;
        Victor shooterVictorAft;

        public Shooter() {
            shooterVictorAft = new Victor(RobotMap.shooterMotorAft);
            shooterVictorFwd = new Victor(RobotMap.shooterMotorFwd);

        public void initDefaultCommand() {
             //Choose a command that should be the default.
             // In this case, probably something that sets the wheels to not spin.
             setDefaultCommand(new DriveShooterWithConstant(0,0));

        public void driveShooterWheels(double aftWheelSpeed, double fwdWheelSpeed) {

And the command for the shooter could be something like this:

public class DriveShooterWithConstant extends CommandBase {
        private double myAftWheelSpeed;
        private double myFwdWheelSpeed;
         * Method allows you to drive shooter with constant speed
        public DriveShooterWithConstant(double aftWheelSpeed, double fwdWheelSpeed){
                myAftWheelSpeed = aftWheelSpeed;
                my.FwdWheelSpeed = fwdWheelSpeed;

        protected void end() {
            // Nothing needed here in this case

        protected void execute() {

        protected void initialize() {
            // Nothing needed here in this case
        protected void interrupted() {
            // Nothing needed here in this case

        protected boolean isFinished() {
                return false;


In our code, if we want to have a command run for a duration, we call it with a timeout specified.

public class RunShooterTimed extends CommandGroup {
        public RunShooterTimed() {
                //this will run the command, and if it doesn't complete in 10 seconds, will kill it
                addSequential(new DriveShooterWithConstant(1.0,1.0), 10.0);                

Then you would just link the command group “RunShoterTimed” to a button on the joystick.

Hopefully there aren’t too many bugs in the code, I just threw the example above together, it’s not tested, but should be mostly correct.

Hope that helps.