Intake Subsystem

Now that we have the robot driving and shooting, the last thing we need is some way to pick up the ball from the ground.  The robot has two motors attached to two spinning wheels which can pick up the ball and deliver it to the shooter wheels, which, if run backwards, and deliver the ball to the plastic cup which holds it in position for shooting.

20160720_124955

We need to create a subsystem to operate those motors.  We will call this subsystem IntakeSubsystem.  Create a new class of this name under the subsystem folder in your project.  As before copy the contents of your ExampleSubsystem.java file and past it into your newly created IntakeSubsystem.java file.  Then replace all instances of ExampleSubsystem with IntakeSubsystem.  Your IntakeSubsystem.java file should now look like:

Create two new variables to control the two intake motors by adding the following lines to the beginning of the IntakeSubsystem class (be sure to import the I2CPWMMotor class:

Then initialize these in the init() function with the following two lines:

As before the I2CPWMMotor constructor requires the two pin numbers to which the motor is attached, and, as before, we are using constants here instead of the actual number.  Of course this means that we must define these constants, which we can do by adding the following lines to the top of the class:

Finally we need to create functions that will turn the motors on so that they will intake a ball.  We will also need a function that stops the motors once we have captured the ball.  Add the following two functions to your class:

The Intake() function will turn the motors on full power in the direction needed to capture the ball.  The Stop() function will turn the motors back off.

Your IntakeSubsystem.java file should now look like:

We are now ready to add an instance of this class to our Robot class.  Open Robot.java and the following line to the beginning of your Robot class (remember ti import the IntakeSubsystem class as well):

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

We now need to create a command which will operate the intake mechanism, which we will call the IntakeCommand.  Create a new class of the same name under the commands folder, and copy the contents of ExampleCommand.java into the newly created file.  Then replace all occurrences of ExampleCommand with IntakeCommand.  Your IntakeCommand.java file should now look like:

This command is a little different than the ones we created before.  In order to successfully intake a ball into the ball holder, in addition to running the intake motors, we will need to run the spinner motors backwards so the ball is sucked down into the holder.  This means that this command will need access to both the IntakeSubsystem and the SpinnerSubsystem.  We indicate this by replacing the requires(…) line with these two lines:

When this command gets executed we need to start up both the intake and spinner motors, so we add the following two lines to the execute() function:

Note that the SpinnerSubsystem does not currently have an Intake() function (only a Shoot() function), so we will need to add that in a bit to get rid of the error we are seeing.

Before we do that, however, lets finish off this command by turning the intake and spinner motors off once the command is complete.  Add the following two lines to the interrupted() function:

Your IntakeCommand.java file should now look like:

Now, let’s add the needed Intake() function to the SpinnerSubsystem class.  Open the SpinnerSubsystem.java file and add the following function:

Note that we are, once again, using a constant here which we need to define by adding the following line at the top of the class:

Note that we are not running the spinner motors full power in reverse.  We want them to spin fast enough that they can suck the ball down, but not so fast that it slams down too hard.

Your SpinnerSubsystem.java file should now look like:

Finally, we need to connect a button to execute this command.  Open the OI.java file and define the button we are going to use by inserting the following line at the beginning of your OI class definition:

As you can see we will be using button 8 for this command.  Add the following line to the OI() constructor to connect this button to our IntakeCommand.

This will set it so that the intake will run as long as we hold down the intake button (button 8).

Your OI.java file should now look like:

Now deploy and run your program and see if you can pick up the ball.

Next: Speed Control

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.