The Shooter Subsystem will control the spinning wheel that shoots the Nerf ball. The design of this subsystem is similar to that of the Drive Subsystem except that there is only one motor involved.
robotCore.PWMMotor.PWMMotor( int pwmPin, int dirPin )
You will, of course, need the pin numbers:
private static final int k_PWMPin = 5; private static final int k_DirPin = 4;
We will also need to control the speed of this motor so we will need to use the motor’s built in encoder. We will use the Encoder class to read these encoders with the type set to EncoderType.Quadrature. The constructor to use is:
robotCore.Encoder.Encoder( EncoderType type, int pin1, int pin2 )
And the pin numbers are:
private static final int k_encoderPin1 = 2; private static final int k_encoderPin2 = -1;
Note that by setting the second pin number to -1 we are telling the encoder that we only care about the absolute speed and do not need to encode the direction. This is because we will only ever spin the shooter wheel in one direction.
After creating the instance for the Encoder, be sure to set that Encoder instance as the feedback device for the motor using the PWMMotor’s SetFeedbackDevice function, which PWMMotor inherits from SmartMotor.
Finally, create setPower and setSpeed functions to control the motor via power and speed. You can look back to the Drive Subsystem to refresh you memory of how to do that.
Now we are ready to tune the shooter. The technique for doing this is the same as for tuning the drive motors:
- You should create a Calibrate Shooter command and tie it to a button.
- Using this command, drive the shooter at full power (using setPower) and log the speed. This will tell you the maximum possible speed for the shooter.
- First set the F term of the PID controller for each of the motors so that it is running at about 75% of the maximum speed (using setSpeed).
- Next add a P term and increase it until you see the speed becoming unstable, and then back off a bit.
- Finally add an I term and increase it until you see the speed becoming unstable, and then back off a bit. Remember to set an appropriate IZone.
- Once you have it tuned for 75% speed, check the tuning at 60% and 90%. Only change the P and I terms if there are significant problems at those speeds.
In my case I found the max speed to be about 1550 and the final calibration graphs were as follows:
Now create a Spinup Command which will toggle the shooter motor on and off at a specific speed, and tie it to a button. Once you get the feeder working, you will be able to experiment with different speeds and use the speed you find works best. In my case I settled on 1400.
The Shooter wheel will now shoot balls that are fed into it, but we still need a way to do the feeding.