Shooter Subsystem

Now that we have a way to spin up the shooter wheels, we need a way to raise the ball up so that it engages with the wheels and actually shoots.  The robot has a plastic cup which holds the ball below the spinning wheels.  This cup is attached to a servo motor which can raise and lower it.


We will now create a new subsystem which will control that servo, and we will call it the ShooterSubsystem.  In Eclipse, create a new class in the subsystem folder named ShooterSubsystem.  Then copy the contents of into the newly created file.  Then, as before, replace all occurrences of ExampleSubsystem with ShooterSubsystem.  At this point your file should look like:

The first thing we need to do is to declare a variable which will allow us to control the servo motor that moves the ball.  Add the following line to the beginning of your ShooterSubsystem class:

ServoMotor is the class that we need to use to handle the type of servo we are using on the robot (remember that you will probably need to import the ServoMotor class).  We now need to initialize this variable.  Looking at the documentation for the ServoMotor class, we see that the constructor takes one integer parameter which specifies the pin number to which the servo is connected.  For this robot, the shooter servo is connected to pin 5, however, like before, rather than using that number directly in the code, we are going to define a constant at the beginning of the class and use that.  Insert the following line at the beginning of the ShooterSubsystem class:

We can then initialize our m_shooter in the init() function as follows.

We need to add functions that will allow us to position the shooter in either the Release position, where the ball is not in contact with the shooter wheels, or the Shoot position where the ball is in contact with the shooter position.

Looking at the documentation for the ServoMotor class, we see that the set(,..) function is used to position the servo and it takes a floating point number between -1.0 and +1.0. which will move the servo from it’s minimum position to it’s maximum position.  We have determined that the position represented by +1.0 is the position where the ball is not in contact with the wheels, and the position represented by -1.0 is the position where the ball is in contact.

As we have done previously, rather than using those values directly in our code, we are going to create some constants which define their values and then used those constants in our code. At the top of the ShooterSubsystem class add the following two lines:

We can then add the two following functions to control the shooter position as follows:

At this point, your file should look like this:

Now that we have the ShooterSubsystem defined, we need to add it to our Robot class.  Add the following line to the top of the Robot class definition (and import the ShooterSubsystem class).

Then initialize this subsystem by adding the following line to the robotInit() function:

At this point, your file should look like:

We are going to want to create a command that will activate the shooter when we press the trigger.  However before we do that we need to create a ShootReleaseCommand that we can set as the default command for the ShooterSubsystem.  We want to do this to ensure that the shooter is in the release position, whenever it is not being used to shoot.  Create a new class ShootReleaseCommand under the commands folder.  Copy the contents of into this new file and replace all occurrences of ExampleCommand with ShootReleaseCommand.  Your file should now look like:

Since this command will use the ShooterSubsystem, we need replace the requires(…) line in the constructor with:

When this command is executed, we want to release the shooter.  We do this by adding the following line to the execute() function:

At this point your file should look like:

Now we need to edit the file and add the following line to the initDefaultCommand() function:

Your file should now look like

We are now ready to create a command to operate the shooter which we will tie to the trigger button on the joystick.  We will call this command ShootCommand.  Create a new class ShootCommand underneath the commands folder.  As before, copy the contents of the file into the new file, and replace all the occurrences of ExampleCommand with ShootCommand.  Your file should now look like:

This command will need to use the ShooterSubsystem, so replace the requires(…) line with the following,  Remember to import the Robot class.

When this command is activated, we want to move the shooter into the shoot position, so add the following line to the initialize() function:

We will be tying this command to execute as long as the trigger button is pressed, so we always want to return false from the isFinished() routine.  However, when we release the trigger, the interrupted() function will be called, and we need to move the shooter back to the released position.  Do this by adding the following line to the interrupted() function:

Your file should now look like:

Finally, we need to attach the trigger button of the joystick to this command.  Open the file.  We see that there already exists a declaration for the trigger (i.e. m_trigger), so all we need to do is connect that to the ShootCommand.  Add the following line to the OI() constructor (you will need to also import the ShootCommand class):

Your file should now look like:

We can now test our program.  To shoot the ball, place the ball in the shooter, hold the spinup button until the spinners are running at full speed, and then press the trigger.  The ball should fire.

Try and position the robot and make a shot into the tower.

Next: Intake Subsystem

Pierre Pierre, who replica handbag 185cm tall, gucci replica handbags the "Diamond King" in his hermes replica handbags . He has been selected as one of the handbag replica most beautiful 50 people in the "People" magazine. It is also known as replica handbags most elegant and quiet in the world. Unforgettable prince.