PhysSandbox
Classical MechanicsWaves & SoundElectricity & MagnetismOptics & LightGravity & OrbitsLabs
🌙Astronomy & The Sky🌡️Thermodynamics🌍Biophysics, Fluids & Geoscience📐Math Visualization🔧Engineering🧪Chemistry

Related simulators

Continue with similar topics in this category — or all 48 in Engineering.

View category →
NewUniversity / research

Cart–Pole: LQR vs MPC vs PID

Launch Simulator

Nonlinear cart inverted pendulum: linearize about upright φ = θ, discrete-time LQR from DARE (Q, R → K), finite-horizon LQ MPC with DARE terminal cost, and hand-tuned PID — same force limit, kicks, and plant as the mechanics cart-pole.

NewUniversity / research

Holonomic 2D Hovercraft MPC (MPPI)

Launch Simulator

Planar double integrator with ‖u‖₂ thrust cap: sampling-based MPPI steers to a draggable goal while soft-penalizing circular obstacles — rollout fan and best predicted path drawn live.

NewUniversity / research

Particle Filter Localization (MCL)

Launch Simulator

1D or 2D toy robot with fixed range beacons: predict with noisy odometry, update with Gaussian range likelihood, systematic resample on low ESS; weighted mean vs ground truth.

NewUniversity / research

ADC / DAC (Sampling)

Launch Simulator

Sine → samples → quantization → ZOH; Nyquist and optional aliasing demo.

NewSchool

RRT Path Planner (grid)

Launch Simulator

Same 40×28 wall map as A*: random samples, nearest-neighbor steer, goal bias, collision-checked edges; grow an RRT and compare summary stats with one-click Manhattan A* baseline.

NewUniversity / research

Thermostat vs PID

Launch Simulator

First-order room: on/off hysteresis vs continuous PID heater power.

PhysSandbox

Interactive physics, chemistry, and engineering simulators for students, teachers, and curious minds.

Physics

  • Classical Mechanics
  • Waves & Sound
  • Electricity & Magnetism

Science

  • Optics & Light
  • Gravity & Orbits
  • Astronomy & The Sky

More

  • Thermodynamics
  • Biophysics, Fluids & Geoscience
  • Math Visualization
  • Engineering
  • Chemistry

© 2026 PhysSandbox. Free interactive science simulators.

PrivacyTermsContact
Home/Engineering/MPC Pendulum Swing-Up (MPPI)

MPC Pendulum Swing-Up (MPPI)

Sampling-based Model Predictive Control: K candidate torque rollouts over horizon H, MPPI cost-weighted update, bounded torque |u|≤u_max — swing up an inverted pendulum live and watch the planner replan.

MPC (sampling-based MPPI)

40
120
1.5N·m
1
0.05s
2N·m

Cost weights

8
0.05
0.005
50

Pendulum physics

1kg
0.7m
0.1N·m·s

Difficulty preset

Shortcuts

  • •Pause / Play; tweak horizon, samples, λ on the fly

Measured values

θ0.0°
ω0.00rad/s
u (applied)0.00N·m
deviation 1+cos θ0.000
m·g·L (gravity torque)6.87N·m
direct-lift feasible?no — must swing

About this model

Model Predictive Control (MPC) repeatedly optimizes a short-horizon plan, applies the first action, then replans. This simulator uses sampling-based MPPI (Model Predictive Path Integral) control: at each step it draws K candidate torque sequences over horizon H, rolls out a pendulum model, scores trajectories with a cost, and forms a cost-weighted update of the nominal controls under a torque bound |u| ≤ u_max. The task is swing-up and balance of an inverted pendulum while you watch the planner replan live. Idealizations include a simplified pendulum dynamics model, no full nonlinear programming solver, and stochastic sampling rather than globally optimal MPC. Vary K, H, and u_max to see sample quality versus real-time replanning behavior.

Who it's for: Advanced control, robotics, and reinforcement-learning courses introducing sampling-based MPC.

Key terms

  • Model Predictive Control
  • MPPI
  • Swing-up
  • Inverted pendulum
  • Control horizon
  • Sampling-based control

How it works

Sampling-based Model Predictive Control (MPPI) drives a damped pendulum from hanging (θ = 0) to the upright fixed point (θ = π) under a bounded torque |u| ≤ u_max. Every Δt the controller samples K candidate torque sequences over a horizon H, simulates each forward with RK4, and re-fits the mean by an exponentially weighted average of the costs (MPPI update with temperature λ). The first action is applied; the plan is shifted and warm-started for the next step. Try the Swing-up preset where u_max < m·g·L: the controller has to *pump* energy by swinging back and forth before catching the inverted equilibrium. Purple lines are the K candidate rollouts; green is the best one.

Key equations

Iθ̈ = − m g L sinθ − bθ̇ + u, |u| ≤ u_max
min J = Σ [q_θ(1+cosθ) + q_ω ω² + r_u u²] + q_term · (1+cosθ_T)²
MPPI: μ_t ← Σ w_k u_t^k / Σ w_k, w_k = exp(−(J_k − J_min)/λ)

Frequently asked questions

Why sample many torque rollouts instead of solving one optimization?
MPPI approximates the optimal control distribution by weighted samples. That sidesteps hard nonconvex NLP at the cost of needing enough samples K and a sensible temperature/weighting to emphasize low-cost rollouts.
What happens if the horizon H is too short?
The planner may not ‘see’ far enough to commit energy for swing-up, so it can dither near the bottom. Longer H looks ahead further but increases computation per replan.
Why bound |u| ≤ u_max?
Real actuators saturate. Without a torque limit the sampler could invent unrealistically large controls. The bound makes swing-up a genuine underactuated challenge rather than an instant teleport to the upright state.