Elevator

We will learn how to program an Elevator!

Intro

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

Simulation

Real Life

Details

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

  • SparkMax controlling the Elevator

  • 12:1 GearBox on the Elevator

  • Pressing A will make the Elevator go to 0.5m

  • Pressing B will make the Elevator go to 1

  • Pressing X will make the Elevator go up.

  • Pressing Y will make the Elevator go 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 an Elevator move!

1

Create a SmartMotorControllerConfig

We are going to start by configuring out motor controller.

2

Create our motor controller

To control our Elevator 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 Elevator

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

5

Create Commands with our Elevator

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

6

Bind buttons to our Elevator

We bind buttons to use the Command from our Elevator

7

Simulate our Elevator!

We can use our Elevator 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 -> Elevator-> mechanism

Resize Elevator/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 Elevator!! 🎉🎉

Last updated