WOLFRAM SYSTEM MODELER

LQControl

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

Diagram

Wolfram Language

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

Information

 

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 simCenter button in the top-right corner.
  • When the build is finished, click the Simulate button simulate.
  • Click the Animate button animate.

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

animation3d

 

Instant Plotting

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

positionplot

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:

angleplot

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)

fMax

Value: 0.31

Type: Force (N)

L

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

force

Type: WorldForce

pulsex

Type: Pulse

pulsey

Type: Pulse

pulsez

Type: Pulse

LeftMotorVoltage

Type: TimeTable

RightMotorVoltage

Type: TimeTable

feedback1

Type: Feedback

feedback2

Type: Feedback

LQGain

Type: MatrixGain

multiplex

Type: Multiplex6

world

Type: World

gain1

Type: Gain

gain2

Type: Gain