Main Content

Inverted Pendulum Controller Tuning

This example shows how to use Simulink® Design Optimization™ to optimize the controller of an inverted pendulum. The inverted pendulum is on a cart and the motion of the cart is controlled. The controller's Proportional, Integral and Feed-forward gains are tuned to limit pendulum angle variations and respond to step changes in cart position optimally.

Open the pendulum_demo model using the command below and run the simulation. The simulation produces an unoptimized position and angle of the inverted pendulum and the initial data for optimization. An animation window shows the cart position and inverted pendulum angle.

open_system('pendulum_demo')

Double-click the Desired Cart Position block to view constraints on the cart position of the inverted pendulum.

Double-click the Angle Constraints block to view constraints on the angle of the inverted pendulum.

You can launch the Response Optimizer using the Apps menu in the Simulink toolstrip, or the sdotool command in MATLAB®. You can launch a pre-configured optimization task in Response Optimizer by first opening the model and by double-clicking on the orange block at the bottom of the model. From the Response Optimizer, press the Plot Model Response button to simulate the model and show how well the initial design satisfies the design requirements.

We start the optimization by pressing the Optimize button from the Response Optimizer. The plots are updated to indicate that the design requirements are now satisfied.

% Close the model.
bdclose('pendulum_demo')