|
|
|
![]() |
|
|||||||
|
||||||||
|
|
Thread Tools | Rate Thread | Display Modes |
|
#3
|
||||
|
||||
|
Re: Help with buttons and timed sequences
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:
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);
}
}
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;
}
}
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. |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|