C++

C++_Icon

The navX_FRC C++ software library supports access to navX2-MXP via all four of the navX2-MXP communication interfaces, and to the navX2-Micro via I2C.  Several example programs are provided, demonstrating how to use a navX-Sensor in a RoboRIO-based robot control application.

Note that this Java library is also backwards-compatible with the “Classic” navX-MXP and navX-Micro sensors.

[Update:  1/8/2020 – Version 3.1.400 is now available – which is compatible with the FRC 2020.1.2 (Kickoff) Release.  Both offline and online installation methods are supported for installing the library update within VSCode.]

To use the library, you can download the latest build of the libraries; advanced users can checkout the source code with Git.  To learn more about the library, online help is available.  If developing in a Linux or MacOS platform, you can download the cross-platform library package.

Additionally, the new online installation method is available, as described below.

Getting Started

Before getting started, ensure you have installed the WPI Libraries and VS Code.

Several sample C++ Robot Applications are provided.  After running the setup program included in the latest build, the libraries and samples will be installed to the following location:

<HomeDirectory>\navx-mxp\      (e.g., if your user name is Robot, the directory name will be C:\Users\Robot\navx-mxp

Within this directory, the “cpp\examples” directory contains several example programs.

NOTE:  The example programs are written for Eclipse, but can easily be imported into VSCode using the “Import a WPILib Eclipse Project” option.

Importing a WPILib Eclipse project into VSCode.

Configuring your VSCode Project to use the navX_FRC Library for RoboRIO

Offline Installation Method

The Offline Installation method can be used even when you are not connected to the Internet.  In this method, you must first run the latest setup program.

The setup program will all the navX-sensor tools and libraries.  The C++ libraries for FRC are automatically installed into a local “maven” repository located at C:\Users\Public\wpilib\2020\maven.

After running the setup program, open your WPILibrary-based C++ project in VSCode, click on the “WPI” button in the toolbar, and select “Manage Vendor Libraries”.

Next, select “Install new libraries (offline)”:

And select the “KauaiLabs_navX_FRC” item, and press the “OK” button.

At this point, the “navx_frc.json” file will be added to the “vendordeps” directory in your project.  This file provides GradleRIO with all the information need to compile and link your application with the navX_FRC libraries – and even enables you to debug into the navX_FRC libraries if you wish.

VSCode Project Vendordeps folder

Online Installation Method

The Online Installation method can be used instead of the Offline Installation method, if you are connected to the Internet.  Note that the Online  Installation method only installs the navX_FRC library, but does not install any of the navX-sensor tools.  However, the online installation process is very simple.

First, open your WPILibrary-based C++ project in VSCode, click on the “WPI” button in the toolbar, and select “Manage Vendor Libraries”.

Next, select the “Install new library (online)” option

Then, enter the Offline Installation URL shown below and press ENTER.

  • https://www.kauailabs.com/dist/frc/2020/navx_frc.json

At this point, the “navx_frc.json” file will be added to the “vendordeps” directory in your project.  This file provides GradleRIO with all the information need to compile and link your application with the navX_FRC libraries – and even enables you to debug into the navX_FRC libraries if you wish.

VSCode Project Vendordeps folder

 

Next Steps

Once the C++ library paths are configured as indicated above, import the example projects into VSCode, and then modify the constructor of the Robot.java file to specify your selected interface, as follows:

ahrs = new AHRS(SPI.Port.kMXP); /* Alternatives:  I2C.Port.kMXP or SerialPort.Port.kUSB */

To better understand navX-sensor capabilities, the DataMonitor example is recommended.  After compiling and downloading this example to the RoboRIO, the application will connect and sensor readings will be displayed in the DriverStation’s SmartDashboard display.  This sample application’s OperatorControl() function demonstrates how to access navX-sensor readings; more information is available in the online documentation for the AHRS class.

After getting the sample navX-sensor application running, please see the Examples section for a description and sample code which implements some key capabilities enabled by a navX-sensor.

Stepping into the navX_FRC C++ Library source code

If you would like to step into the navX_FRC Java Library source code, or set breakpoints in the library, use the VSCode “Debug Robot Code” option.  If you have successfully imported the navX_FRC library as shown above, all the sources will be available during your debug session.