Feeder Subsystem

The Feeder serializes the balls and feeds them one at a time into the shooter. It is a simple mechanism which consists of a rotating spindle with slots. The balls fall into the slots and are then pushed into the shooter. So it seems that all that is required is to simply rotate the spindle as long as we wish to continue shooting. Unfortunately, as with many things, it is not quite a simple as that. The feeding mechanism will occasionally jam and to clear the jam we need to detect that and reverse the feeder motor for a short time to clear it.

The Feeder Subsystem will need to control a single motor much like the shooter subsystem. This motor is connected to the Main Arduino Board so we will need to use the constructor:

    int pwmPin,
    int dirPin 

With pins:

	private static final int k_PWMPin	= 9;
	private static final int k_DirPin	= 8;

We will not need precise control over the speed of this motor so we will not calibrate a speed and will control the motor with power only. However, we are going to need to know if the balls jam and the motor stalls. We will use the motor’s encoder for this purpose so we create an instance of Encoder using this constructor:

    EncoderType type,
    int pin1,
    int pin2 

With pins:

	private static final int k_encPin1 = 3;
	private static final int k_encPin2 = -1;

Note that, once again, we are setting pin2 to -1 because we don’t need to know the direction, only the magnitude of the speed to detect when it stalls.

Finally we need to create a public setPower function which we will use to control the speed and direction of the motor.

Now create a Feeder command to feed the balls and tie to to a button. While you hold the button, you want to rotate the spindle in a clockwise direction to feed the balls. While you are doing this you need to monitor the speed of the spindle and if it drops below a certain value for a short period of time, you need to reverse the direction of the spindle for a short period and then resume in a clockwise direction. You should probably allow for a different forward speed than a backward speed with the forward speed being faster.

There are a number of ways you can accomplish this but here is some ‘pseudo’ code which illustrates one way to achieve this.

  if (Spindle is moving forward)
    if (The speed is greater than the minimum speed) {
      Reset the timer
    else if (The timer is greater than the stall time) {
      Set the spindle to move backwards
      Reset the timer
  else {
    if (The timer is greater than the reverse time) {
      Set the spindle to move forward
      Reset the timer;

Here we are using a Timer to test both whether the spindle has stalled and to time the reversal. Remember that this timer should also be reset in the initialize() function of the command.

You can test that the reversal is working properly by using your hand to stop the rotor. It should reverse momentarily and then resume.

Once you have this command working, you should be able to shoot balls. Note that you should not run the feeder unless the shooter is running as the balls will jam. Adding a way to prevent the feeder from running when the shooter is not would be a nice optional touch.

Next Turret Subsystem