LabVIEW Trajectory Library (and more) WPILib port V1.4

Here is a link to a version, 1.4, of the LabVIEW Trajectory (and more) library. It is a native port of the WPILIB routines available for Java/C++. Also included are some utility programs for the creation and conversion of trajectories. (Actually it is the same link. I just replaced the files.)

If you are looking to have some fun without a real robot, the sample robots can all run simulated on a PC…

To install:

  1. Download the files

  2. Unzip the files to a new directory.

  3. Run the install package. This contains the entire library. Old versions should be upgraded.

  4. If you want to use the samples, unzip them to a new directory.

Additions and changes to this library include:

  • Addition of most of the rest of the non hardware functionality of the Java/C++ WPILIB. This includes;
    • Linear Filter
    • Median Filter
    • Slew Rate Filter
    • Timer
    • Arm Feedforward
    • Elevator Feedforward
    • PID Controller
    • Profiled PID controller
    • Trapezoid Profile
    • Better menus (These could still use some work…)
    • LabVIEW style single call subVI (_execute subVIs) for many of the new functions
    • An “advanced” PID was added.

Some new samples have also been included. These are fairly crude and evolving. If you create any samples of your own and want to contribute, that would be great.

Some of the new functionality duplicates things that LabVIEW has built-in (slew rate filter, PID). I included them to maintain compatibility with the WPILIB of other languages.

This document contains the list of VI’s and there current status. Other than doing additional cleanup, documentation, and adding more samples, I think the library is now essentially complete. (Suggestions are always welcome!!!)
FRC_LabVIEW_Trajectory_Library_Routines_1_4.pdf (169.5 KB)

Previous posts containing additional information on the library can be found here.

If, or when, you find bugs, or have suggestions or comments, please let me know.

Happy roboting.


The location of the files have been moved to github. There are two repositories, one for the trajectory library and its install files, and the other for utilities, samples, and test programs. Here are the links.

GitHub - jsimpso81/FRC_LV_TrajLib: FRC LabVIEW trajctory library

GitHub - jsimpso81/FRC_LV_TrajLib_Util_and_Samp: FRC LabVIEW Trajectory Library Utilities and Samples

Happy roboting…


The Utilities and Samples github repository has been updated so that the simulated robot projects are compatible with FRC 2021. There is an updated release.

GitHub - jsimpso81/FRC_LV_TrajLib_Util_and_Samp: FRC LabVIEW Trajectory Library Utilities and Samples - releases

The trajectory library repository is unchanged.

GitHub - jsimpso81/FRC_LV_TrajLib: FRC LabVIEW trajctory library

GitHub - jsimpso81/FRC_LV_TrajLib_Util_and_Samp: FRC LabVIEW Trajectory Library Utilities and Samples

1 Like

So awesome. Thank you again for all the work.

The Trajectory Library has been updated with a new release, 1.04C. A few new functions have been added.

  • Holonomic Drive Controller
  • Trajectory write to JSON
  • Updated Create Trajectory utility to write to JSON in addition to CSV file.
  • A number of miscellaneous geometry "get" functions that retrieve multiple values at once.
This install package was built with NI Package manager 2020.5 that is installed with the FRC 2021 software.

Here is a link to the github repository release.

Here is a link to the github repository.

Happy roboting.

The Trajectory Library has been updated with a new release, 1.04F.

See the Release description for a list of all the changes. Maybe one of the most interesting things is the ability of the Trajectory Creation utility to select which field to display (including the 2021 fields). The utility can write JSON and or CSV output files.

This install package was built with NI Package manager 2020.5 that is installed with the FRC 2021 software.

Here is a link to the github repository release.

Happy roboting.

1 Like

Thanks so much for creating this trajectory library and making it available to everyone!

I would love to learn how to use trajectory planning in our autonomous routines, but I am not sure where to start. We usually try to keep things simple by using sequence structures to run a “drive distance, turn, drive distance, do thing” sort of autonomous, but we think this year’s auto challenges seem like they would really benefit from a trajectory. We have also never used velocity closed-loop control before. I’ve poked around in your provided examples, but I’m a bit overwhelmed.

What kind of hardware/software do we need to have setup in order to make use of your trajectory software?

Right now, we’re running 4 NEOs with SPARK MAXs via CAN and the ADIS16470 Gyro. We’re able to read the encoder and gyro values, but we’ve had little success implementing the SPARK MAX velocity closed-loop example and there’s not a lot of LabVIEW documentation for their software.

I tried messing around in your Create Trajectory program, but I have some questions -

I can’t figure out the best way to generate waypoints. Do I have to enter the coordinates manually or can I click on the field map?

Is the Robot Data and Constraints information calculated or set somewhere in the velocity closed-loop configuration?

Do you happen to have a step by step guide of how to use the Create Trajectory program (or even a video of someone using it)?

Thanks again for providing this resource!

The library is intended to be used with robots programmed in LabVIEW. However, the trajectory creation utility can make trajectory files that can be used with C++/Java robots. This utility may be of benefit to those teams because it allows definition of “constraints”, things that limit the robot’s velocity and acceleration.

For teams using LabVIEW, I’d suggest installing the software in this order:

  • LabVIEW

  • If you use Java or C for Raspberry PI, install the WPILIB software which includes Visual Studio code and the libraries. If you don’t need C or Java, this step can be skipped.

  • Install the FRC LabVIEW update and FRC Game tools. This is a single installation.

  • Then download the LabVIEW “package” for the releases section of the LabVIEW trajectory library github. Right click on the file and select install. This installs the LabVIEW VI library as part of the “Third party” palette in LabVIEW. It also installs the utility executable programs in a group called JASJUNK in the Windows Start Menu.

As far as getting started, there are a lot of resources available online. Here are just a few.

  • Secret Book of FRC LabVIEW version 2 (I didn’t write the original, but I added the version 2 updates.) This presents LabVIEW and some control system concepts, like position control and closed loop speed control. Secret Book of FRC LabVIEW (and control logic) version 2.07

  • Here are some presentations on basic control theorey I gave to the team I mentor a couple of years ago. I’m certain how well they work on there own, but you are welome to them. The first chapter or two are not related to control theory and probably have lesser applicability. Control_Logic_Training - Google Drive Specifically, I’d skip Modules 1,2,3.

  • Here is a training on trajectory following we did just a couple of weeks ago. Again, I don’t know how well it stands on its own… Trajectory_Following_Training_2021 - Google Drive

  • There are lots and lots of other good resources. The secret book above has a list in it to other resources.

As far as auto movement go, I think there are two basic approaches (with probably some variations including some things built into newer motor controllers).

  • Straight, spin, straight, spin, straight… This can be done quickly and accurately without using closed loop control on the drive system motors. It requires encoders on the drive wheels to measure distance and a gyro to measure robot rotation. The straight movements use “position control” to calculate the drive motor voltage demand (or speed demand) as a function of how far the robot still has to move. (Error). The spin movements use the same process by calculating the drive motor voltage demand (or speed demand) based on Error to the target angle. The training above has a chapter about position control. (If your team writes a general position control subVI, it can be used for many things.) It addition to robot drive movements, it can be used for elevator height control and vision positioning.

  • Trajectory following. This follows a much smoother route to get to a position. It requires accurate drive wheel encoders and a gyro. (Gyro drift affects trajectory following more that it affects the straight, spin, straight since it is used continuously, not just when spinning.) This might work without needing to control the speed of the drive motors – if you fairly accurately determine the speed (ft/sec) of the maximum speed of your robot and convert the speed output of the trajectory system, typically (m/sec) directly into motor voltage demand based on your testing. Closed loop drive motor speed control will likely be somewhat more accurate.

As for drive speed control, there are two general ways to do this.

  • Use the built in velocity control of the newer motor controllers. We have used the Talon SPX. They require sending the tuning constants Kf, Kp, Ki, Kd, Intzone (and maybe some others I’m forgetting). The units for the call to the routine that sets the velocity is a little odd. It is based on how many encoder ticks (up and down, A and B) you want in 100 ms. Converting from FT/SEC to this is fun… (The spark max NEO may be different.) The Kf, Kp, Ki, Kd, intzone need to be tuned. The Kf, Kp can be estimated knowing the robot’s maximum speed. I’d start with Kp = 0.8 * Kf, and leaving Ki to be zero or very small. There are a number of resources for tuning PID. (This method usually requires wiring the encoder to the motor controller.)

  • The other way is to execute a PID agorithm in the roboRIO and output a voltage value to the drive motors. This is maybe easier to configure, but probably won’t control as well since it runs at the roboRIO rate. (This can be done wiring the encoder to the motor controller or the roborio.).

There is an accompanying Samples and Utilities github repository that goes with the Trajectory library. It has a number of sample robots. All of these can be executed in simulation on a PC without needing to have a robot. (They use the LabVIEW ODE simulation.) They might also run on a real robot if the sensors and actuators are replaced with what the real robot has. The purpose of these was for education, not as code to be used… GitHub - jsimpso81/WPIlibMathLabVIEW_Examples: FRC LabVIEW Control / Trajectory Library Utilities and Samples

On the Trajectory Creation utility program:

  • The waypoints are entered numerically in the table in the bottom left of the screen. The X, Y, Angle, and Weight are entered. If you want just enter 1 for all the weights and un-select the “Use Weights” button.

  • The constraint information tries to ensure that the robot speed or acceleration doesn’t exceed what the robot is capable of. They can be turned off, guessed at, or set by using the WPILIB Robot Characterization tool. (I’ve not used the tool, so I can’t tell you much about it.) It suggest the following ---- If you use a differential drive robot – Set the max speed to approx 60% of the real speed of the robot (to start with), Set the max acceleration to be somewhere between 50% to 100% of the maximum speed. Set the wheel base width to be slightly larger, maybe 1.2 times or more, than the width between the left and right wheels. (If you have a differential drive robot, use the differential drive kinematics constraint.). Suggest using the centripetal acceleration constraint and setting it to 50% of what you set the overall acceleration. If these work well, try increasing these to get the robot to go faster.

  • Sorry I don’t have a step by step video or instructions. Basically go through each tab in order. The first time through you won’t have a configuration to read. Skip this to get a default configuration.

Set the robot parameters and pick a field to use.

Set the constraints you want to use. These are all optional. Use the button at the bottom of each constraint to enable/disable each one.

Enter the waypoints. Type over the gray boxes to enter a new row. Right click and select delete to delete a row you don’t want.

Select what kind of spline to use for trajectory creation, if the trajectory is reverse, and whether to use the built in weights or the ones you entered. (I’d start with the built in ones and customize.)

Press the create trajectory button.

Look at the results.

The trajectory line color, width can be changed by clicking on the box next to the legend.

The left and right wheel paths can be turned on if desired.

Change the waypoints as needed and push the button to create an updated trajectory.
The Graph and Trajectory tabs are there to show information about the trajectory.
Choose the file names for the trajectory file to save. You don’t need a JSON file if using the LabVIEW library on the robot.

Push the create file buttons.

Optionally to save the configuration so you can come back and change it later.

The created trajectory CSV (or JSON) file is readable…

This file needs to be copied to the robot… The sample robot project has a sample build specification that does this. To run it on a simulated robot it needs to be copied to the c:\user\xxxxx\Documents\LabVIEW data directory.

Hope this helps. Happy to answer additional questions. Happy roboting.

1 Like

This is VERY helpful! Thanks for the detailed response! I’ll definitely let you know if I have any more questions. Thanks!

Your welcome. I was curious about the Spark Max and looked very briefly at their velocity control example. It didn’t seem to match their LabVIEW palette, which I thought was a little odd. I made some changes, which you can find here – GitHub - jsimpso81/SPARK-MAX-Examples: Example code for SPARK MAX (specifically this example SPARK-MAX-Examples/LabVIEW/Velocity Closed Loop Control at master · jsimpso81/SPARK-MAX-Examples · GitHub ). I think you should be able to run it by, modifying BEGIN,INI for your motor configuration, connecting USB to roborio, opening ROBOT MAIN.VI and pressing the run button on the VI.

The example uses the odd native units. If this is anything like the Talons, then the units are encoder EDGES for distance and EDGES/100 MILLISECONDS, for velocity. So the input and output have to be converted to useful things like FEET and FEET/SEC. (I DIDN’T read the documentation so all of this could be wrong !!)

Awesome! I’m on mobile right now, but I’ll take a look at your examples asap. from what I remember, I believe the Spark MAX reads the integrated NEO encoder and returns position and velocity in units of rotations and rpm, respectively.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.