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]:=

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:

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 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) 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] 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 Type: WorldForce Description: External force acting at frame_b, defined by 3 input signals and resolved in frame world, frame_b or frame_resolve Type: Pulse Description: Generate pulse signal of type Real Type: Pulse Description: Generate pulse signal of type Real Type: Pulse Description: Generate pulse signal of type Real Type: TimeTable Description: Generate a (possibly discontinuous) signal by linear interpolation in a table Type: TimeTable Description: Generate a (possibly discontinuous) signal by linear interpolation in a table Type: Feedback Description: Output difference between commanded and feedback input Type: Feedback Description: Output difference between commanded and feedback input Type: MatrixGain Description: Output the product of a gain matrix with the input signal vector Type: Multiplex6 Description: Multiplexer block for six input connectors Type: World Description: World coordinate system + gravity field + default animation definition Type: Gain Description: Output the product of a gain value with the input signal Type: Gain Description: Output the product of a gain value with the input signal