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. We will need to use the constructor:

With pins:

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:

With pins:

Once again, we don’t need to know the direction, only when the motor 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.

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.

Before we move on, you are probably going to want to have a way to shoot a specific number of balls when you work on the final challenge. There are a couple of ways you can do this. One would be to run the feeder for a fixed amount of time, or alternately, for a fixed number of degrees using the encoder.

The best way, however, would be to actually count the balls as they are shot. The robot is equipped with a Beam Break Sensor that the balls pass through which can be used to count the balls. To use this sensor you should use the DigitalCounter class. Note that the sensor is connected to pin Device.IO_2. You should only create one instance of the DigitalCounter in your RobotContainer and pass this instance into whatever commands that need it.

Also note that the counter counts the number of transitions. Since the ball will generate two transitions (one when it blocks the sensor and a second when it clears it), the count you get will be twice the number of balls shot.

Next: Turret Subsystem