Shooter/FlyWheels

We will learn how to program an Shooter!

Intro

At the end of this tutorial you will have an Shooter that will work in both real life and simulation with the same code!

Details

This Shooter will be using the following hardware specs and control details

  • SparkMax controlling the Shooter

  • 12:1 GearBox on the Shooter

  • Pressing A will make the Shooter go to 60 RPM

  • Pressing B will make the Shooter go to 300 RPM

  • Pressing X will make the Shooter speed up.

  • Pressing Y will make the Shooter slow down.

Lets create a WPILib Command-Based Project!

Setup our Command-Based Project

Here we will follow WPILib's tutorial on how to create a Command-Based project.

Bring up the Visual Studio Code command palette with Ctrl+Shift+P. Then, type “WPILib” into the prompt. Since all WPILib commands start with “WPILib”, this will bring up the list of WPILib-specific VS Code commands. Now, select the “Create a new project” command:

This will bring up the “New Project Creator Window:”

  1. Click on Select a project type (Example or Template)

  2. Select Template then Java then Command Robot

  3. Click on Select a new project folder and select a folder to store your robot project in.

  4. Fill in Project Name with the name of your robot code project.

  5. Enter your Team Number in so you can deploy to your robot.

  6. Be sure to check Enable Desktop Support so we can run simulations!

If you followed these instructions it should look something like whats filled out below.

Congratulations! You now have a Command Based robot project!

Install YAMS!

Click on the WPILib logo on the left pane. Scroll down to Yet Another Mechanism System and click Install!

Congratulations you have now installed YAMS! 🎉

Lets make a Shooter move!

1

Create a SmartMotorControllerConfig

We are going to start by configuring out motor controller.

2

Create our motor controller

To control our FlyWheel motor we will create the vendor motor controller object.

First we install REVLib by clicking on the WPILib logo in the left bar.

Now we add it to the ExampleSubsystem.java

3

Create our SmartMotorController

Our SmartMotorController will easily configure and interface with the vendor motor controller object.

4

Create and Configure our FlyWheel

Our FlyWheel will easily configure the SmartMotorController and create a simple and intuitive interface.

5

Create Commands with our FlyWheel

We use the FlyWheel class as a interface to create commands!

6

Bind buttons to our FlyWheel

We bind buttons to use the Commands from our FlyWheel

7

Simulate our FlyWheel!

We can use our FlyWheel in simulation, with the exact same code that will control the real robot!

Connect an Xbox controller to your system and drag and drop from System Joysticks to Joystick[0]

Open up the Simulated mechanism with NetworkTables -> SmartDashboard -> Shooter-> mechanism

Resize ShooterMech/mechanism to your liking

Press Teleoperated in Robot State then you can use your controller like its controlling the real robot!

Congratulations on successfully programming your Shooter!! 🎉🎉

Last updated