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...
Quote:
|
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:
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) {
shooterVictorFwd.set(fwdWheelSpeed);
shooterVictorAft.set(aftWheelSpeed);
}
}
And the command for the shooter could be something like this:
Code:
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){
requires(shooter);
myAftWheelSpeed = aftWheelSpeed;
my.FwdWheelSpeed = fwdWheelSpeed;
}
protected void end() {
// Nothing needed here in this case
}
protected void execute() {
shooter.driveShooterWheels(aftWheelSpeed,fwdWheelSpeed);
}
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.
Code:
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.