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

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

Simulation

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

Click the Simulate buttom: simCenter

Click the Animate button: animate

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 Model plot will be displayed, showing the path of the Segway:

There is also a Model plot the angle of the Segway. To view that, click on Segway angle in the Model 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.

In order to get the full experience of this example, you need a desktop Wolfram Language product. A free trial download is available at www.wolfram.com/mathematica/trial/

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]

Description: Gain matrix

Connectors (1)

angle

Type: RealOutput

Description: 'output Real' as connector

Components (14)

segway

Type: LEGOSegwayModel

Description: Contains a model of a LEGO Segway with some extra inputs and outputs

force

Type: WorldForce

Description: External force acting at frame_b, defined by 3 input signals and resolved in frame world, frame_b or frame_resolve

pulsex

Type: Pulse

Description: Generate pulse signal of type Real

pulsey

Type: Pulse

Description: Generate pulse signal of type Real

pulsez

Type: Pulse

Description: Generate pulse signal of type Real

leftMotorVoltage

Type: TimeTable

Description: Generate a (possibly discontinuous) signal by linear interpolation in a table

rightMotorVoltage

Type: TimeTable

Description: Generate a (possibly discontinuous) signal by linear interpolation in a table

feedback1

Type: Feedback

Description: Output difference between commanded and feedback input

feedback2

Type: Feedback

Description: Output difference between commanded and feedback input

LQGain

Type: MatrixGain

Description: Output the product of a gain matrix with the input signal vector

multiplex

Type: Multiplex6

Description: Multiplexer block for six input connectors

world

Type: World

Description: World coordinate system + gravity field + default animation definition

gain1

Type: Gain

Description: Output the product of a gain value with the input signal

gain2

Type: Gain

Description: Output the product of a gain value with the input signal