jgeisler0303 / DDP-Generator

Generate taylored code for Differential Dynamic Programming (DDP) aka Iterative Linear Quadratic Gaussian (iLQG) solvers for finite time Optimal Control Problems (OCP)
GNU General Public License v2.0
15 stars 2 forks source link

Introduction

This is a highly efficient C implementation of Yuval Tassa's iLQG algorithm (see also his paper) plus some improvements and extentions.

Efficiency is achieved using the following features:

On my computer, this yields a speed improvement of 8ms per iteration vs. 1500ms of the original MATLAB implementation for the car-parking example from Yuval's MATLAB code.

As improvements I have added the handling of state dependent input constraints and an experimental regularisation via a modified cholesky decomposition.

Everything is still very raw, partially tested and undocumented. But if you are interested I will be more than happy to supply addition information and help with problems. In this case, please just open new a github issue in my repo.

Code Generation

The problem-specific code is generated from a problem definition in the Maxima language using the maxima package gentran. Unfortunately, the gentran package as supplied by the current maxima release is not fully functional. Therefore you will have to download the package from my my repo and replace the files in the maxima/share/contrib/gentran folder of your maxima installation with the files from my repo. On my Linux computer I got gentran only to work using Steel Bank Common Lisp (SBCL) implementation. Unfortunately, this meant I had to recompile maxima from source. On Windows, SBCL is the default Lisp implementation supplied with the wxMaxima installation.

Code generation and compilation is easy using the MATLAB/Octave function make_iLQG.m. This function takes as first argument the string name of the problem definition .mac-file and as optional second argument additional compiler switches. These can be used to get reasonable console output by setting the following defines: -DDEBUG_BACKPASS=1 -DDEBUG_FORWARDPASS=1. Further, the define -DFULL_DDP=0 can be used to switch off the use of second order derivates of the system function during the backward-pass of the iLQG algorithm. Using the define -DMULTI_THREADED=1 experimental multi-threaded calculation of derivates and backpass can be enabled.

Problem Description

Your optimal control problem has to be defined in a maxima batch file, i.e. a text file with .mac suffix containing maxima expressions. In this file at least five variables plus an optional sixth have to be defined:

The symbols for states and inputs may not be defined. In the expressions of f, L, F and h any undefined symbol appart from state and input symbols is considered to be a parameter. Any defined symbol is considered to be an auxillari value. Auxillari values and their derivatives are calculated separately and before their use in f, L, F or h or their derivatives. Auxillari values may depend on other auxillari values, states, inputs or parameters. If you use auxillaries, make sure to prefix them with an apostrophe. Otherwise, the auxillari definition will be substitued in to your expression and you end up without the benefits of auxillaries.

Getting the Example to Run

As an example the definition of the car parking problem from Yuval Tassa's iLQG implementation and the classic brachistochrone problem can be found in the examples folder. These definitions can be compiled into an Octave Mex function or a MATLAB mex function using the make_iLQG.m MATLAB/Octave function with the following arguments: make_iLQG('optDef{Brachi|Car}', '-DDEBUG_BACKPASS=1 -DDEBUG_FORWARDPASS=1 -DFULL_DDP=0'). This is assuming you have Maxima, and for Octave the mkoctfile package installed and the DDP-Generator base path is in your MATLAB or Octave path. In MATLAB you may also have to setenv('MAXIMA', 'path to maxima');. Upon success, a subfolder named {problem name}_gen_files is created, containing the generated problem specific code and an empty err.log file. In the problem folder, the compiled iLQG{prablem name}.mex file is created. Now you can run the testCar or testBrachi demo script.