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.
The class which controls this motor is once again PWMMotor and you should use the following constructor:
1 2 3 4 |
robotCore.PWMMotor.PWMMotor( int pwmPin, int dirPin ) |
You will, of course, need the pin numbers:
1 2 |
private static final int k_PWMPin = Device.M2_2_PWM; private static final int k_DirPin = Device.M2_2_DIR; |
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:
1 2 3 4 5 |
robotCore.Encoder.Encoder( EncoderType type, int pin1, int pin2 ) |
And the pin numbers are:
1 2 |
private static final int k_encoderPin1 = Device.Q5_INT; 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 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. In my case I found the max speed to be about 1450.
- Since we will be running the shooter motor near full power, set the F term of the PID controller for the motor running at a speed of 1300 (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 a speed of 1300, check the tuning at 1400 and 1200. Only change the P and I terms if there are significant problems at those speeds.
The following were the results of my calibration:
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.