Skip to content

WPI Library Simulation

Adrian Patterson edited this page Feb 7, 2021 · 1 revision

WPI Library Simulation Workshop

  • In this workshop, we'll discuss the use of WPI Library simulation and why it's useful
  • In short, today we'll cover:
    1. Discuss why simulating your code is useful
    2. The download/installation of the WPI Framework
    3. Creating a simple WPI Project
    4. Simulating the project and exploring different tools

Before we start...

  • Make sure you have the following:
    • A computer with Windows 10
    • An xbox/ps4 controller (optional)

Why Simulate Your Robot?

  • Simulating our robot allows us to test the functionality of our code without even touching a robot
  • Using the WPI simulator, we can validate that our code can:
    • Compile and run without error
    • Test the logic of our code -- Does it make sense?
    • Apply tele-operated inputs and observe code output
  • Overall we get a better sense of what our code is doing and whether it works the way we want it to

WPI Library Installation

  • Before we can get started, we need to make sure we have all the necessary dependencies downloaded
    • Skip this section if already done
  1. Downloading the WPI Installer
    • Visit the official WPI Library release page on GitHub
    • Scroll to the bottom and download the WPILib_Windows64-2021.2.2.iso
  2. Find the .iso disc image file where you downloaded it to
    • Right click the file and select mount
  3. Run the installer by clicking on strong text
  4. Install VS code (if not already installed)
  5. Leave all boxes checked and finish installation

Opening WPI VS Code and Starting a New Project

  • Open up 2021 WPILib VS Code by either searching "WPI" or double-clicking the application on your desktop
  • On the top right corner of the IDE, you'll see a "W" symbol -- this is used to run features and tools of the WPI framework
    • We'll be using this button to:
      1. Create a project from the given examples
      2. Simulate a robot
      3. Explore other WPI tools

Creating a New Project

  • From the WPI command line, type "Create a new project" and select the search result
    • From here, a page will open prompting us to configure our project
    • To start a new project, follow the following steps:
      1. Select an Select a Project Type
        • Click on example
        • Select Language as java
        • Choose any project you'd like!
          • Read the description and keep it in mind as we simulate the robot
      2. Choose a base folder, i.e. a directory where your project will be stored
      3. Name your project under Project Name
      4. Leave Create a new folder? checked
      5. Enter 296 under Team Number
      6. Check Enable Desktop Support
      7. Select Generate Project
  • You'll then get a message saying your project was generated. Select Yes to open your project in a new window
  • What happened?
    • The WPI Library framework generated all the necessary files and code for your project. Take a look at some of the java code under the /src directory on the left

Simulating our Project

  • To simulate the robot project, type "Simulate Robot Code on Desktop" and select the search result
    • Select both extensions when asked, and click "OK" to launch the GUI
  • A GUI will now pop up, with a variety of information about our build

Simulation GUI Breakdown

  • A few boxes are open by default when a project is initialized, including:
    • Robot State
      • What type of operation?
    • Other Devices
      • Devices connected to your robot, not seen under the "Hardware" tab
    • System Joysticks
      • Displays your connected robot controllers
        • Plug in your controller -- You should see it pop up in this box!
    • Joysticks
      • Displays what joysticks are active

Connecting Your Controller for Testing

  • By connecting your controller (via bluetooth or wired in), it'll show up under System Joysticks
    • Click and drag your controller to the Joysticks box
  • Test if your controller is connected
    • Try wiggling one of the joysticks -- you should see a response under the axes
    • Try clicking a button -- one of the yellow boxes should become toggled

Exploring GUI Features

  • Hardware
    • Under the "Hardware" tab at the top of the window, you'll see a list of connected hardware for your project
      • Open any un-selected hardware, and experiment with the controller to see what happens
    • Keep in mind that different example projects will have different hardware!
  • Timing
    • The "Timing" box displays elapsed time since the code began simulation
    • You can also pause, step, and resume the time
      • By clicking step you advance the time by increments rather than continuously running
  • Robot States
    • The "Robot States" box provides the different modes of operation for our robot, and will simulate the selected state
    • Note that an controller will only be able to control the simulated robot in teleoperated mode

Shuffleboard and Other Tools

  • WPI Library also offers a variety of other tools
  • Shuffleboard is a kind of dash board that presents the same info but in a more visually pleasing way
  • How to access Shuffleboard/Other Tools:
    • Search "Start Tools" in the WPI command line and click on the result
    • Select whichever tool you'd like to run

Key Takeaways From This Workshop

  • WPI offers a wide range of tools which can be super useful!
  • Simulating designs is key in engineering, as it allows us to visualize and get an idea of how our design works and whether it is valid or not
  • More specifically, simulating our Robot code is extremely useful as we can ensure we are getting the results we want before ever even touching a robot!
    • This can save a lot of time in the long run...
  • I highly encourage you all to simulate different examples, and maybe even write your own based on the given examples
    • Bonus Exercise:
      • Try looking into the provided code for examples and reading through to understand what's going on, and what kind of robot was programmed. This goes a long way in enriching your understanding of a program, and is a skill I myself continue to work on all the time (just reading through code and trying to understand)
  • And of course, have a great day! :)

Supplemental Resources