This is a trajectory optimization library written in an easy-to-understand functional style. It treats the problem as a non-linear one and solves for the entire trajectory as one large optimization problem using ipopt instead of solving it iteratively per time point.
It is written in a purely function style. The Jacobian and gradients are calculated manually using numerical computing methods and are hand-tuned for performance. The Hessian is approximated by ipopt. The only dependencies are ipopt and Rangev3 (which is used very sparingly since it didn't turn out to be very performant, at least when this was written.)
The example is located here. It optimizes a 3-D trajectory, starting from (0,0,0) and ending at (50,40,30), while hitting (-10, 20, 30) along the way, using simple block dynamics. Here are what the results look like:
A script setup.sh
has been provided to install these dependencies on a Mac-based system. It will install Homebrew and use it to install these dependencies. To execute it, run chmod +x setup.sh && ./setup.sh
.
Linux support has not been added to the script yet.
Note that Rangev3 is cloned and built automatically by CMake, so it does not need to be fetched manually.
TrajectoryOptimization can be easily used as a git submodule in any other CMake-based project. Let's walk through integrating TrajectoryOptimization into an existing source project.
- cd into your project directory,
git init
if it isn't already a git repository. mkdir -p lib && git submodule add [insert this project's clone URL (https/ssh)] lib/trajectoryOptimization
- If you don't already use CMake, run
touch CMakeLists.txt
. Insertcmake_minimum_required(VERSION 3.8)
as the first line. - Insert these into your
CMakeLists.txt
to import and link theTrajectoryOptimization::TrajectoryOptimizationLib
target:
add_subdirectory(lib/trajectoryOptimization)
add_executable([yourExecutableName] [yourSourceFiles])
target_link_libraries([yourExecutableName]
PUBLIC
TrajectoryOptimization::TrajectoryOptimizationLib
)
mkdir build && cd build && cmake ..
make
./[yourExecutableName]
Now you can build software using TrajectoryOptimization!
To ever recompile and rerun, just cd into build/
and run make && ./[yourExecutableName]
.
To build tests, run cmake like this: cmake -Dtraj_opt_build_tests=ON ..
. Then cd into lib/trajectoryOptimization
and run ctest
.
To build samples, run cmake like this: cmake -Dtraj_opt_build_samples=ON ..
. Then cd into lib/trajectoryOptimization
and run ./trajectoryOptimizationSample
. The sample currently optimizes a 3D trajectory. Inspect the source for more information and to learn about usage.
Mujoco support is currently baked into this project, but disabled.
To enable building/linking it:
- Uncomment the relevant lines in CMakeLists.txt that are marked for Mujoco.
- Copy this file to cmake/LocalProperties.cmake and replace the FIXME with the path to your Mujoco installation.