Spinner Subsystem

Now that we have the robot driving, it it time to make it shoot as well.  The shooting mechanism (shown below) is composed for four wheels which are attached to two motors, with two wheels on the left and two on the right.  The wheels are then spun at high speed and once the motors are up to speed, a separate mechanism is used to raise the ball to engage with the spinning wheels, causing the ball to be propelled outward at a high rate of speed.


This new subsystem will be designed to operate the two motors that spin the wheels.

The first step is to create our new SpinnerSubsystem class.  Right click on the subsystem folder in the Package Explorer of Eclipse and add a new class named SpinnerSubsystem.  Then as before, open the ExampleSubsystem.java file and copy all of the lines and paste them into the newly created SpinnerSubsystem.java file, replacing the existing text.  Then in the SpinnerSubsystem.java file, replace all instances of ExampleSubsystem with SpinnerSubsystem.  Your SpinnerSubsystem.java file should now look like:

First we need to create two variables that will be used to control the two motors operating the spinners.  Add the following two lines at the beginning of your SpinnerSubsystem class, and remember to import the I2CPWMMotor class.

Note that, once again, we are not initializing these variables in the constructor.  We need to do that by adding the following lines to the Init() function:

Once again, the I2CPWMMotor class takes two integers in it’s constructor which specify the PWM pins to which the motor is attached.  For our robot, the right motor is attached to pins 6 and 7, and the left motor is attached to pins 10 and 11. As before, we use constants which are defined as follows:

For this subsystem, we will do not have a default command to run, so we will leave the initDefaultCommand() function unchanged.

Now we need to add a functions that will turn the spinner motors on when we want to shoot and turn them back off when we are done.  Add the following functions to your SpinnerSubsystem class:

The Spinup() function will run the spinner motors at full power, and the Stop() function will turn them back off.

Your SpinnerSubsystem.java file should now look like:

The next step is to add an instance of this class to our main Robot class.  Open the Robot.java file and add the following line to the beginning of the Robot class.  Remember to import the SpinnerSubsystem class.

Next we need to call the Init() function of our new class.  Add the following line to the robotInit() function:

Now your Robot.java file should look like:

Now that we have our SpinnerSubsystem in place, we want to create a command which will start the spinner motors spinning to prepare for a shot.

We will call this new command SpinupCommand. As we did with the ArcadeDriveCommand, create a new class called SpinupCommand under the commands folder of the project.  Then copy the ExampleCommand.java file into the newly created SpinupCommand.java file.  Finally replace all instances of ExampleCommand with SpinupCommand.  The resulting SpinupCommand.java file should look like:

Now this command will use the new SpinnerSubsystem, so change the requires(…) call to the following.  Note that you will need to import your Robot class.

Now when this command is started, we want to start the spinner motors spinning, so add the following line to the initialize() function:

We don’t need to do anything else in the execute() function so we will leave that alone.  Also, we want run this command as long a button on the joystick is held, so we always want to return false from the isFinished() function.

However, when this command is terminated by releasing the button on the joystick, the interrupted() function will be called, and we will want to turn the motors back off, so add the following line to that function:

Your SpinupCommand.java file should now look like:

The last thing we need to do is make it so that pressing one of the buttons on the joystick will cause this command to be executed.  We do this using the OI.java file.  Open this file.

First we define which button we are going to use to control the spinner.  Add the following line right after the Button m_trigger … line:

This allows us to access button 2 of the joystick.  Now we need to tell the program what to do when that button is pressed.  Add the following line to the OI() constructor:

This line tells the system to run the SpinupCommand whenever button 2 on the joystick is being held down, and to terminate the command once it is released.

At this point, your OI.java should look like:

Now run your program, and you should be able to start the spinner motors by pressing button 2 on the joystick, and stop them again by releasing that button.

Next: Shooter 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.