FRC: VS Code C++/Java

FRC C++/Java – Create a Project

Next we will create a new robot project in vscode and create a Talon SRX. The goal is compile the project only, so hardware is not needed.

Follow the WPI frc-docs instructions on reaching the create new project. Typically, you can use CNTRL+SHIFT+P to open the VS text bar, and type create to reach the WPI command.

_images/verify-1.png

“Timed Skeleton” is used in this example for sake of simplicity.

_images/verify-2.png _images/verify-3.png

Once the project is created, ensure project builds. Testing robot deploy is also useful if robot controller is available.

FRC C++/Java – Add Phoenix

Right-Click on “build.gradle” in the project tree, then select “Manage Vendor Libraries”.

_images/verify-4.png

At the top of your screen, a menu will appear. Select “Install new libraries (offline)”.

Tip

Alternatively you can use “Install new libraries (online)” option with https://maven.ctr-electronics.com/release/com/ctre/phoenix/Phoenix5-frc2023-latest.json. However this is not recommended as this requires a live Internet connection to use your FRC project.

_images/verify-5.png

The menu will now display a list of vendor libraries you can install. Check “CTRE Phoenix”, then click “OK”

_images/verify-6.png

Note

This will bring the library into the project references, however the library will not be loaded if the source code does not create a Phoenix object or call any Phoenix routines. Therefore, you must create a Phoenix object to properly test the install.

Tip

Teams can verify Phoenix is in their robot project by checking for the existence of vendordeps/Phoenix.json in the project directory.

FRC C++ Build Test: Single Talon

Create a TalonSRX object. The number specified is the Talon’s device ID, however for this test, the device ID is irrelevant.

Be sure to include “ctre/Phoenix.h”, otherwise TalonSRX will not be recognized as a valid class type.

Add an example call, take your time to ensure to spell it correctly.

_images/verify-7.png

Intellisense may not be functional at this point in time (note the green underline indicating VS did not parse the header).

_images/verify-7-2.png

Tip

To correct this - Close all files in the project - Restart VS Code - Wait ~40s - Reopen source files in VS Code

If you see linker errors, then the desktop simulation checkbox was likely checked.

_images/verify-8.png

This can be resolved by manually turning off the feature. Set flag to false.

_images/verify-9.png

Tip

When resolving compiler/linker errors, press the trash icon first to cleanly erase the previous error lines in the terminal. Or manually scroll the bottom to ensure you are not looking at stale error lines from previously failed builds.

_images/verify-10.png

The only reliable way to confirm build was successful is to confirm the BUILD SUCCESSFUL line at the bottom of the TERMINAL.

Note

The problems tab may or may not be clear of errors. Our testing with VSCode has shown that it can report stale or incorrect information while making code changes. Always use the TERMINAL output to determine the health of your compilation and build system.

_images/verify-11.png

In the event that the intellisense is not resolving symbols (for IDE auto-complete features), restart VSCode.

_images/verify-12.png

After restart, routines should be found correctly.

_images/verify-13.png

Tip

Headers can be auto-opened by CNTRL+CLICK the include line.

_images/verify-14.png

Depending on the version of VS Code used, you may encounter an IntelliSense warning. These can be ignored.

_images/verify-15.png

FRC Java Build Test: Single Talon

Create a TalonSRX object. The number specified is the Talon’s device ID, however for this test, the device ID is irrelevant.

Typically, you can type “TalonSRX” and watch the intellisense auto pop up. If you press ENTER to select the entry, the IDE may auto insert the import line for you.

_images/verify-16.png

Add an example call, take your time to ensure to spell it correctly. Use the intellisense features if available.

Here is the final result.

_images/verify-17.png

If you see build errors, carefully find the first erroneous line in the TERMINAL output. Typically, you can CNTRL + click the error line and auto-navigate to the source.

_images/verify-18.png

When resolving compiler errors, press the trash icon first to cleanly erase the previous error lines in the terminal. Or manually scroll the bottom to ensure you are not looking at stale error lines from previously failed builds.

_images/verify-10.png

The only reliable way to confirm build was successful is to confirm the BUILD SUCCESSFUL line at the bottom of the TERMINAL.

Note

The problems tab may or may not be clear of errors. Our testing with VSCode has shown that it can report stale or incorrect information while making code changes. Always use the TERMINAL output to determine the health of your compilation and build system.

_images/verify-20.png

FRC C++/Java - Updating Phoenix

If you already have a previous version of Phoenix installed and you want to update to a newer version, follow these steps. Install the latest version of Phoenix on your PC. Basically, rerun the latest installer (same as section above).

Open your robot program in VS Code.

_images/verify-4.png

At the top of your screen, a menu will appear. Select “Check for updates (offline)”.

Tip

Alternatively you can use “Check for updates (online)”. However this is not recommended as this requires a live Internet connection to use your FRC project.

_images/verify-21.png

The menu will now display a list of vendor libraries you can update. Check “CTRE Phoenix”, then click “OK”

_images/verify-6.png

FRC C++/Java – Test Deploy

Create a Talon SRX (or Pigeon, CANifier, Victor SPX) and attempt to “deploy”. Adding a print statement also helps to confirm you are actually deploying the software displayed in VsCode. Confirm that the software deployed using DriverStation. DS may report firmware-too-old / not-retrieved errors since the hardware has not been setup yet.