USE CASE

Cart-pole, from textbook to reinforcement learning.

A pole hinged on a cart, the cart pushed by a horizontal force — the benchmark every controls course starts with, and the one every RL paper returns to. Here it is one program: the exact nonlinear dynamics, a full-state LQR that catches the inverted pole, an energy-shaping swing-up, a learned model-free policy, and a Monte-Carlo robustness sign-off — the plant and its stabiliser also composed as one runnable .djl on the canvas.

A DjiniousLab notebook plot of the cart-pole swinging up from hanging to upright and being caught by the controller at t = 7.2 s, with the control force trace
4 states
x, ẋ, θ, θ̇
3.68 s
LQR settling time
299.6 / 300
learned RL return
9
design notebooks
1
.djl composition
100%
of 300 robustness draws caught
THE PROGRAM

Five ways to balance one pole.

From a hand-derived model to a policy that learns with no model at all — each method is its own runnable notebook, all on the same plant.

Nonlinear dynamics

The exact cart-pole equations of motion, derived and integrated. The upright equilibrium is genuinely unstable — ∂θ̈/∂θ > 0 — so every uncontrolled run topples, the right baseline to beat.

LQR stabilisation

A full-state feedback law from lqr(A, B, Q, R) pulls every closed-loop eigenvalue into the left half-plane and settles an 11° lean to upright in 3.68 s.

Energy swing-up

An energy-shaping law pumps the pole from hanging all the way around, then hands off to LQR, which catches it upright at t ≈ 7.2 s.

Reinforcement learning

A cross-entropy-method policy learns to balance from random initial conditions with no model — converging to 299.6/300 return from a −220 random baseline.

Robustness

A 300-trial Monte-Carlo sweep perturbs cart mass, pole mass and length by ±30% and kicks the pole with impulses — all 300 are caught.

Gain optimisation

A bounded Nelder-Mead search retunes the LQR weights against a closed-loop cost, cutting it 34.5% while the gains stay physical.

A notebook plot of pole angle swinging up from π and being caught at upright, with the control-force trace spiking at the catch
Energy swing-up and catch: the pole is pumped from hanging through a sequence of growing swings, then the controller takes over and drives it to upright at t = 7.21 s — the control force (dashed) spikes exactly at the hand-off.
MODELICA-CLASS

The plant and its controller, composed on a canvas.

The whole closed loop — the nonlinear cart-pole plant and its full-state LQR law — is one acausal .djl component. Its equations are written implicitly in the accelerations ẍ and θ̈, a small algebraic system the kernel solves every step, so it is a genuine differential-algebraic model that needs a stiff Rodas5P solver, not a hand-rolled time-step. It lowers and runs through the same production engine the canvas uses: released from a 0.20 rad lean, the controller drives the pole to 0.005 rad. The gains are the same lqr() values the notebooks compute.

A notebook plot of the LQR-stabilised cart-pole states settling to zero within 3.68 seconds
LQR stabilisation: from an initial lean, cart position and pole angle both settle to zero in 3.68 s. The open-loop plant has an eigenvalue at +3.97 in the right half-plane; the feedback law pulls every closed-loop pole into the left half-plane.
A notebook plot of the reinforcement-learning return climbing from a negative baseline to near the maximum over training iterations
Model-free learning: a cross-entropy-method policy, given no dynamics model, learns to balance the pole from random starts — its return climbs from a −220 random baseline to a converged 299.6 / 300.
VALIDATION

Every result is a number you can re-run.

Each notebook is gated on its own worker-verified result, and the .djl stabiliser is confirmed solving through the production canvas engine.

ResultDetail
LQR settling time3.68 sall poles in LHP
Swing-up catcht ≈ 7.2 sθ → 0.0018 rad
Learned RL return299.6 / 300−220 baseline
Q/R optimisation−34.5% costbounded search
Robustness caught300 / 300±30% params
HONEST SCOPE

A benchmark, done honestly.

The pole is a point-mass pendulum on a frictionless cart — the standard textbook cart-pole, not a flexible or multi-body arm. The reinforcement-learning policy is a linear cross-entropy method chosen for speed and reproducibility, not a deep network; the optimiser is a bounded local search. What the program shows is the full arc — derive, stabilise, swing up, learn, and verify — on one plant, with the controller also living as composable acausal source you can wire into a larger system.

Bring your own plant.

Book a walkthrough and we'll stand up your dynamics, design the controller, and run the swing-up, learning and robustness studies live.

DjiniousLabOne engineering notebook for model-based design — model, simulate, and generate on a living digital replica.