In the Subsystem objects you want to include all the methods which control the hardware of that subsystem.
So for instance in the Shooter subsystem you would want a method that would drive the shooter wheel:
i.e.
Code:
//drives the left motor and the right motor with the same value
public void spinMotor(double speed)
{
leftMotor.set(speed);
RightMotor.set(speed);
}
You don't need the shootBall method. And can safely delete it.
Also Delete the defaultCommand, because that will cause that command to run, even without pushing a button (it runs by default).
Once you have that method in your Shooter Subsystem, you create a command that requires that subsystem and calls the "drive" method in the execute method.
In this case, since you are using a button, you will not have variable control of the motor, but on off control. So the idea is everytime the button is pressed, drive the shooter wheel with a constant value between -1 and 1.
Your execute method in the ShootBall command should look something like this:
Code:
protected void execute() {
shooter.spinMotor(1);
/*change value, you should really use the RobotMap class to control
constants so this call should look more like
shooter.spinMotor(RobotMap.motorVal), where in RobotMap.java you
declare a public static int motorVal =1;
*/
}
I also trust in the CommandBase.java definition you instantiate a Shooter object called "shooter".
Lastly, now that you have your subsystem and command set up, in OI map all you need to do is:
Code:
public OI()
{
stick = new Joystick(JOYSTICK_PORT);
a = new JoystickButton(stick, 1);
a.whileHeld(new shootBall());
}
You should add methods to the OI.java class which return the joystick values of your joystick
i.e one method could be
Code:
public double getRightStickVal()
{
return stick.getRaw(3);
}
You should do this for all joysticks, pots, etc.
You could then create another command call shootBallWithJoystick, have it require shooter as well and in the execute method of that command do something like this:
Code:
protected void execute() {
shooter.spinMotor(OI.getRightStickVal());
}
You could make the command ShootBallWithJoystick your default command of your subsystem, so now when the robot starts-up you have default control of the motors with your joystick for maintaining manual control, but when you press the button it will drive the wheel with the constant speed. A very nice way to maintain automated, and manual control at all times.
We used the CommandBase Robot template for our 2012 robot in Java, and find it to be an extremely nice way to control the robot.
Hope that helps,
Kevin