Skip to content

Using VSCode

xgreyskiesx edited this page Feb 2, 2019 · 6 revisions

Installation

VSCode and WPILib

Before getting started, VSCode and all the extra extensions need to be installed. The good news: WPI provides a handy installer that does all the major work for you. The bad news: this installer is a little over a gigabyte in size, and might take a while to download.

Get the installer from their official GitHub, and unless you've got super fast internet, strap yourself in for a wild ride. A ride consisting of sitting in one spot for a few minutes. Probably.

When it's done, extract the zip file to a safe folder and run the provided .exe. When prompted for what user to install for, it's probably best to do it just for your profile, unless otherwise instructed.

On the next screen, make sure you click the "Select/Download VS Code" button. In there, hit "Download", and wait for the program to get everything it needs. Once that's finished, make sure the window looks like this:

All the boxes should be checked

Hit that fancy "Execute Install" button and wait for a bit again. When the window saying everything finished pops up, you're done!

CTRE

Cross the Road Electronics (CTRE) offers software and libraries made to work with certain robot objects called Talons, which control motors. This is necessary to the robot, as many of the motor controllers we have only work with this software.

The download is located here, as the top link in the "installer" tab.

This time, you can just keep hitting next/agree/install until it's done with everything. At the end, uncheck the "View Release Notes" box and click finish. You're done!


Creating Robot Projects

Check the desktop for a few new icons made by WPI's installer. One of them should be for VSCode; fire that up for now.

When it's loaded, press CTRL+shift+P to open the command palette. Start typing "create" and an option for WPILib's "create a new project" option should come up. Clicking that should get you something like this:

At the top, with the three buttons in a row, first choose "Template," then "java," and finally "Iterative Robot." Under that you'll need to point the program to a (preferably, dedicated) workspace folder, and then enter a project name and our team number (314). Go ahead and hit the checkbox underneath everything, and then create the project. It should look like this:

If this is your first time after installation, you may have to restart VSCode after a few minutes. Otherwise, you're finished! Important code can be found under


Adding CTRE as a Dependency

After creating the project, if you open the src folder, you'll be met with something like this:

What we need to add CTRE as a dependency is the build.gradle file. Right clicking that will give you an option called "Manage Vendor Libraries", here:

Choose that, and in the palette that opens up, select "Install new libraries (offline)":

CTRE should be the only one available. Check the box and hit okay:

After that, you're pretty much done! In order to make sure everything is working, go to the Robot.java file and create an empty line after line 25. Start typing private TalonSRX. A box should show up* that looks like this:

It's part of Intellisense

If you hit tab, the program will automatically complete the name and add the proper dependency needed:

You're all set! If you want to keep that line, type a name after (like exampleTalon) and add a semicolon.

* Note: If the box doesn't show up, or VSCode doesn't autocomplete the statement and add the dependency, the language server might not have started yet. Check the bottom left corner to make sure that it isn't still starting.


Managing Git Integration

Most of the interaction with Git in VSCode will be done through the built-in extension tab on the left side of the program. It's the icon that has a split in the middle:

It's a reference to branches!

Clicking the white icon in the top right of the source control window gives you the option to initialize a repository in your project. After doing that, you should have a panel that looks like this:

Now, what you'll want to do is log in to the CLI so you can make commits. Click the terminal option in VSCode's toolbar, and then New Terminal:

Use the terminal that came up and your knowledge from the Github page here to add your credentials to the project from the command line.

You'll also need to add a remote manually. Using the next section in the linked page above, add the remote for your repository to the project using the VSCode terminal. Now, you're ready to start making and pushing commits.


Preparing for Remote Interaction

This far into the process, you should have a repository that's already been created and has a README file. Alternatively, you may have a repository already full of working robot code that belongs to the team, and are using the remote from that.

In order to make sure that you can push changes to the repository, you'll first have to pull from it. Unfortunately, Git may not allow this the normal way (git pull [remote] [branch], or using the Pull option in the source control's toolbar), and instead, you'll have to use git pull --allow-unrelated-histories [remote] [branch].

To get started with this part of the tutorial, run the latter command. It should pull the existing README file, and affect nothing else. It should also automatically stage the change for a commit. Feel free to ignore that for the moment.


Staging Files and Committing Changes

Staging files to commit is as easy as tapping the plus sign on files you want to add. The plus sign will show up as you roll over items:

You can make this easier by rolling over the Changes tab and clicking the plus there as well:

Type a message in the bar above that and hit CTRL+Enter to commit the changes. All the files should disappear, as there are no more changes to commit.


Pushing and Pulling Files

In the top right of the source control panel, there are now 3 horizontal dots. Clicking the Push option will automatically push your changes.

A popup dialogue may show stating that master has no upstream branch, and asking if you'd like to publish it. Hit yes. If all goes well, you shouldn't see any changes or other boxes. Check the repo from GitHub's website in order to make sure all went well.

Pulling changes from the repo may also be done with the pull option in that menu. Be sure to pull existing repo changes before making new ones. This minimizes merge conflicts and makes collaboration easier in the long run. Communicate with teammates before pushing and pulling code to be sure that merge conflicts are kept at a minimum.