WOLFRAM SYSTEM MODELER

# LQControl

Model of a LEGO Segway with an LQ controller keeping it upright.

# Wolfram Language

In[1]:=
`SystemModel["EducationExamples.ElectricalEngineering.LEGOSegway.LQControl"]`
Out[1]:=

# LEGO Segway: Controlling an Inverted Pendulum

## Introduction

This models a LEGO Segway kept upright by an LQ controller. The LQ controller is designed in Mathematica using the SystemModeler Link. For the model without a controller, open LEGOSegway.NoControl.

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

Parts of this example require the Wolfram Language. Open the accompanying notebook LEGOSegway.nb for those scenarios.

View the model diagram for this model.

## Simulation

To simulate the LEGO Segway and view a 3D animation of it, follow the steps below:

• Click the button in the top-right corner.
• When the build is finished, click the Simulate button .
• Click the Animate button .

The result shows the LEGO Segway moving around, withstanding pushes applied at the top of the Segway.

## Instant Plotting

As soon as the simulation is done, a stored plot will be displayed, showing the path of the Segway:

There is also a stored plot the angle of the Segway. To view that, click on Segway Angle in the Stored Plots widget.

This will show the following plot:

As you can see, the angle never deviates more than 0.08 rad, or 4.6°.

## Create Custom Libraries

The model of this controlled Segway is built on custom components, modeling parts of the LEGO Mindstorms NXT 2.0 kit. For example, the model diagrams for the gyro, the motor, and one of the tires.

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

# Parameters (3)

uMax Value: 8.5 Type: Voltage (V) Value: 0.31 Type: Force (N) Value: {{-0.317389999945665, -0.332770810105325, -189.012455398573, -19.1625910782731, 0.00986193616239615, 0.0175149167638231}, {-0.332770810116102, -0.317389999939135, -189.012455399932, -19.1625910784022, 0.0175149167639171, 0.00986193616242574}} Type: Real[2,6]

# Connectors (1)

angle Type: RealOutput

# Components (14)

segway Type: LEGOSegwayModel Type: WorldForce Type: Pulse Type: Pulse Type: Pulse Type: TimeTable Type: TimeTable Type: Feedback Type: Feedback Type: MatrixGain Type: Multiplex6 Type: World Type: Gain Type: Gain