▶ Try it its model runs in your browser, nothing to install

template · verified

arche/cart-pole

Cart-pole

A pole balanced upright on a cart pushed along a rail: encoders on the cart and the pole, a motor that pushes the cart, and an LQR controller whose gain comes from archec physics --linearize --lqr; its plant in MuJoCo, its test cases run against it.

plantmujococart-poleinverted-pendulumlqrcontrol

archec add main.arche arche/cart-pole@^0.1

Package

Kindtemplate
Version0.1.0
LicenseApache-2.0
Export controlnone
Works witharchec >=0.10
Edition0.12
Handlersthe action language (```arche), run as TypeScript from its code
Homehttps://github.com/arche-lang/arche-lang

Model

SystemsCartPole Linearized
ComponentsCart Pole Bob Motor CartEncoder PoleEncoder Controller CartPole
Requirements2
Messages3

Code it brings

WhereLanguageLines
main.arche · Controller.on_cart.bodyarche4
main.arche · Controller.on_pole.bodyarche10

Cart-pole

A pole balanced upright on a cart that a motor pushes along a rail. The pole is a 0.5 m rod of 10 g with a 200 g bob at its tip, on a 1 kg cart. It starts 0.1 rad off upright, at rest.

| | | |---|---| | Plant | a slide (x, ±2 m) and a hinge (y), a force motor (±20 N, a 10 ms lag), 2 encoders (noisy, 4096 counts a turn and 0.1 mm), 1 ms step | | Controller | u = −K·(x − target_x, v, θ, ω), 200 Hz; gives up past 0.6 rad (Fallen) | | Requirements | REQ-CP-UP (within 0.2 rad; formal "never controller in Fallen"), REQ-CP-SETTLE | | Test plan | TP-CP: from 0.1 rad, back to the centre, the cart moved 0.5 m |

The gain is the LQR gain of the cart-pole's equations, written as a physical network in physics.arche (a point mass at the tip):

archec physics physics.arche Linearized --linearize --inputs push.f --lqr 1:1:10:1,0.1
K = -3.162278  -5.751839  -47.57699  -10.52418      (x, v, θ, ω)
archec new my-cart-pole --template cart-pole     a project from it, yours to change
archec gen main.arche --target mujoco -o out
archec sim main.arche --plant out/mujoco/plant_bridge.py --test

In MuJoCo (4.0): the pole never more than 0.1 rad off (its start), within 0.02 rad from 1.08 s, the cart at most 0.16 m from the centre and back within 4 mm at 5 s; at most 4.8 N. Change the masses or the length in both files, then compute K again.

The encoders read with noise and the motor lags, as their ports say (noise, resolution, lag): the noise is drawn from a seed, so a run repeats (archec sim … --plant … --test --seed 5 for other draws).

Versions

VersionPublishedarchecState
0.1.02026-11-12>=0.10public

Signature

Signed by arche with key e660d0a8851875b9. Files: 4, fingerprint sha256-794c1294c659e59ee464…. archec add checks both before it writes anything.

Discussion

Loading…