How ferrolho/rotary-inverted-pendulum works
This repository builds a rotary inverted pendulum and its learned controller. The principal workflow measures a physical rig, trains in simulation, fine-tunes and evaluates on real hardware, distills and exports a compact policy, then runs it standalone on an Arduino; the website also demonstrates the deployed policy in browser-based simulation. The README documents the end-to-end stages, while sampled source confirms the simulation environment, SAC trainer, serial client, and demo components. Firmware sketches and several pipeline implementations are outside the supplied tree or excerpts, so their internal wiring is not shown.
Main entry points: index.ts Demo orchestrator · real_env.py Real rig interface · export_weights.py Weight export · train_sac.py SAC training
Components 22
Rig modeling
- System identification
policy/sysid_core.py - Sysid workflow
policy/sysid_wizard.py - Real rig interface
policy/real_env.py - Serial client
policy/lowlevel_client.py - Simulation environment
policy/pendulum_env.py
Policy learning
- SAC training
policy/train_sac.py - Real fine-tuning
policy/finetune_real.py - Async fine-tuning
policy/finetune_async.py - Policy evaluation
policy/analyze_run.py - Policy distillation
policy/distill.py - DAgger distillation
policy/dagger_distill.py
Deployment
- Arduino rig
- Weight export
policy/export_weights.py - Embedded policy weights
firmware/RLControl/policy_weights_rig1_tmc2209_32.h
Browser demo
- Project documentation
website/src/content.config.ts - Demo orchestrator
website/src/demo/index.ts - Demo controller
website/src/demo/control.ts - Demo policy
website/src/demo/policy.ts - 3D renderer
website/src/demo/renderer.ts - Demo plots
website/src/demo/sparkline.ts
Other components
- Rig builder
- Website visitor
Connections 20
- Rig builder → Sysid workflow: starts measurement
- Sysid workflow → System identification: fits rig parameters
- System identification → Simulation environment: provides parameters
- SAC training → Simulation environment: trains against
- Rig builder → Real fine-tuning: starts fine-tuning
- Real fine-tuning → Real rig interface: controls real rig
- Async fine-tuning → Real rig interface: controls real rig
- Real rig interface → Serial client: exchanges state and commands
- Serial client → Arduino rig: serial protocol
- SAC training → Policy evaluation: evaluates checkpoints
- Policy distillation → Weight export: exports student
- DAgger distillation → Weight export: exports student
- Weight export → Embedded policy weights: generates weights
- Website visitor → Project documentation: reads guidance
- Website visitor → Demo orchestrator: interacts with
- Demo orchestrator → 3D renderer: loads and poses
- Demo orchestrator → Demo controller: creates and steps
- Demo orchestrator → Demo policy: loads policy
- Demo orchestrator → Demo plots: updates plots
- Demo controller → Demo policy: gets action