WOLFRAM SYSTEM MODELER

BallAndBeamLQR

Model of a ball and beam setup controlled by a linear quadratic regulator

Diagram

Wolfram Language

In[1]:=
SystemModel["EducationExamples.Physics.BallAndBeam.BallAndBeamLQR"]
Out[1]:=

Information

 

Ball and Beam: Controlling the Position of a Ball along a Beam with an LQR Controller

 

Introduction

This model studies a ball rolling on top of a beam. The ball translational acceleration will be dependent on how the beam is angled. This example studies two different control schemes, the PID regulator and the LQ regulator, which can be used to control the position of the ball along the beam, using the beam angle as input.

In order to get the full experience of this example, you need the following:

 

These pages show an overview of the example. For the full example, open the accompanying notebook BallAndBeam.nb.

 

Dynamics

This model is different from the main model in that it uses a linear-quadratic regulator to control the ball position along the beam, instead of a PID controller, as in the example model. The gains for the controller have been calculated using the accompanying Wolfram Language notebook.

lqrdiagram

 

Simulation

To simulate the model, perform this step:

  • Click the Simulate button in the top toolbar simulate.

Plot the results

Explore how the actual ball position differs from the reference ball position. Do this by plotting the variables x and y. The first variable describes the reference position and the latter describes the measured position. This plot will be displayed immediately upon simulation.

You should now see the following plot:

piddefaultplot

 

Visualize

Multibody systems have automatic visualizers to show what a real-world system would look like.

In this example, custom CAD models have been loaded to better represent the system. To see a 3D representation of the system, follow the steps below:

  • From the Simulation Center, click the Animation button animate in the toolbar.
  • Use your mouse or trackpad to drag the animation to a good angle and zoom in with your scroll wheel or by using the trackpad. Then click the Play button play to play the animation.

3Dplot

 

Parameters (4)

amplitude

Value: 0.07

Type: Length (m)

Description: Amplitude of the reference pulse.

offset

Value: -0.05

Type: Length (m)

Description: Offset of the reference pulse.

period

Value: 10

Type: Time (s)

Description: Period of the reference pulse.

K

Value: {{1., 0.582915}}

Type: Real[:,:]

Description: Gain matrix which is multiplied with the input (LQRGains.K)

Connectors (4)

x

Type: RealOutput

Description: Ball position along the beam

v

Type: RealOutput

Description: Ball velocity along the beam

y

Type: RealOutput

Description: Reference signal

u

Type: RealOutput

Description: Input variable for the servo

Components (4)

ballAndBeam

Type: BallAndBeamModel

feedback

Type: Feedback

pulse

Type: Pulse

LQRGains

Type: MatrixGain