Creating a new WPILib project in VS Code
In this article we will create a new WPILib project in VS Code. In this example we will be making a Command Based Robot, however the same methods apply to creating a project from any of the existing templates or examples.
Accessing The Command Palette
Clicking Ctrl+Shift+P will open the command palette. The command palette contains the WPILib commands for creating and interacting with projects.
Accessing The WPILib Commands
All WPILib commands start with "WPILib:", so in order to access the WPILib commands type "WPILib:" into the command palette search bar.
Creating A New WPILib Project
In order to create a new project select the "Create a new project" command. This will show a a form with a number of fields where you enter the information required to create your new project.
New project creator window
The steps to create the new project are outlined here:
- Select the kind of project you want to create. It can be an example project or one of the template projects provided by WPILib.
- Select the language that you are using for your project.
- In the case of a template - select the template type (Timed robot, Iterative robot, Command robot, etc.)
- Select the folder to place the project.
- If the "Create new folder" checkbox is checked, a new folder named with the project name is created in the supplied folder. If the checkbox is NOT checked, then the folder supplied is assumed to be empty (will give an error if not) and the project files will be placed into that directory.
- The project name is used in the project and also to optionally create the folder to place it if the checkbox from the previous step is checked.
- The team number for the project. This will be used for package names and to locate your robot when deploying code.
And last, click "Generate Project" and VS Code will create the project in the location specified.
Click the "Select a project type" button and then select your desired type from the dropdown.
Note: If there are any errors generating the project (such as trying to use a non-empty folder with the checkbox unchecked), they will pop up in the bottom right corner of the screen.
After successfully creating your project, VS Code will give you the option of opening the project as shown below. You can choose to do that now or later by typing Ctrl-O (Command+O on mac) and select the folder where you saved your project.
Once opened you will see the project hierarchy on the left. Double clicking on the file will open that file in the editor.
C++ Configurations (C++ Only)
For C++ projects, there is one more step to set up IntelliSense. Whenever you open a project, you should get a pop-up in the bottom right corner asking to refresh C++ configurations, click Yes to setup IntelliSense.
Building and Deploying Robot Code
To build the robot project, do one of:
- Open the Command Palette and select "WPILib: Build Robot Code"
- Open the shortcut menu indicated by the ellipses in the top right corner of the VS Code window and select "Build Robot Code"
- Right-click on the build.gradle file in the project hierarchy and select "Build Robot Code"
Deploy robot code by selecting "Deploy Robot Code" from any of the three locations from the previous instructions. That will build (if necessary) and deploy the robot program to the roboRIO. If successful, your see a "Build Successful" message (2) and the RioLog will open with the console output from the robot program as it runs.