This is a solution to the CartPole-Swing Up problem using a pre-existing iLQR implementation from https://github.com/TGlad/ILQR.
-
added a
CartPole
class / problem definition, following the exampleAcrobot
class / problem definition- implemented the dynamics
CartPole::f()
, copying from the Python codeCartPole.step()
provided in the assignment - implemented the cost functions
CartPole::l()
,CartPole::lf()
, finding a penalization scheme that produces the desired final state
- implemented the dynamics
-
added
cartpole_main.cpp
that runs the pre-existing iLQR implementation / solver on the aboveCartPole
problem- copied parameter values (time delta
td
, trajectory lengthT
, initial statex0
) from the assignment code
- copied parameter values (time delta
git diff wrt. fork base:
cartpole.mp4
optimized
g++ cartpole_main.cpp -o cartpole_main -Wall -O3
debug
g++ cartpole_main.cpp -o cartpole_main -Wall -O0 -g
requires Eigen C++ library (Debian/Ubuntu: apt install libeigen3-dev
)
$ cartpole_main # outputs cartpole.trajectory.csv
$ cartpole_render.py cartpole.trajectory.csv # outputs cartpole.mp4
cartpole.h
- CartPole problem definition (dynamics & cost functions)cartpole_main.cpp
- executable, runs iLQR implementation on the above problemcartpole.trajectory.csv
- iLQR output, optimized (state, control) trajectorycartpole.mp4
- visualization of the above trajectorycartpole_render.py
- visualization code, extracted from the assignment code
TODO: cartpole_main static binary