package LEGOSegway annotation(__Wolfram(openClass=LEGOSegway.LQControl, useDocumentationTemplate=false), Documentation(info="

# LEGO Segway: Controlling an Inverted Pendulum

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

Parts of this example require Mathematica. Open the accompanying notebook LEGOSegway.nb in Mathematica for those scenarios.

## Package Overview

This is a package containing the following models:

## Terms and Conditions of Use

This domain example is an informational resource made freely available by Wolfram Research.

### Use of This Example

• You may not use this example for any purpose that is unlawful or dangerous.
• You assume total responsibility and risk for your use of this example.
• You may not present this example with any alteration to its trade dress, trademarks, or design.

A summary of the licensing terms can be found at:

The full legal code can be found at:

", revisions=""), preferredView="info", uses(Modelica(version="3.1")), Icon(coordinateSystem(extent={{-100.0,-100.0},{100.0,100.0}}, preserveAspectRatio=true, initialScale=0.1, grid={10,10}), graphics={Text(visible=true, origin={0.0,21.0}, lineColor={255,0,0}, extent={{-120.0,73.0},{120.0,132.0}}, textString="%name", fontName="Arial"),Rectangle(visible=true, lineColor={111,0,0}, fillColor={255,0,0}, fillPattern=FillPattern.HorizontalCylinder, lineThickness=4, extent={{-90.0,-90.0},{90.0,90.0}}, radius=25),Text(visible=true, origin={12.0,20.8333}, fillColor={255,255,255}, fillPattern=FillPattern.Solid, extent={{-102.0,-70.8333},{78.0,29.1667}}, textString="Ex", fontName="Arial")}), Diagram(coordinateSystem(extent={{-148.5,-105.0},{148.5,105.0}}, preserveAspectRatio=true, initialScale=0.1, grid={10,10}))); package Components "Contains components used in the LEGO Segway example" extends Modelica.Icons.Library; annotation(Documentation(info="

# LEGO Segway: Controlling an Inverted Pendulum

## Package Overview

This subpackage contains components used in the LEGO Segway models.

## Terms and Conditions of Use

This domain example is an informational resource made freely available by Wolfram Research.

### Use of This Example

• You may not use this example for any purpose that is unlawful or dangerous.
• You assume total responsibility and risk for your use of this example.
• You may not present this example with any alteration to its trade dress, trademarks, or design.

A summary of the licensing terms can be found at:

The full legal code can be found at:

# LEGO Segway: Controlling an Inverted Pendulum

## Description

This models the DC motor in the LEGO kit.

View the model diagram for this model.

## Terms and Conditions of Use

This domain example is an informational resource made freely available by Wolfram Research.

### Use of This Example

• You may not use this example for any purpose that is unlawful or dangerous.
• You assume total responsibility and risk for your use of this example.
• You may not present this example with any alteration to its trade dress, trademarks, or design.

A summary of the licensing terms can be found at:

The full legal code can be found at:

", revisions="")); Modelica.Electrical.Analog.Basic.Ground ground annotation(Placement(visible=true, transformation(origin={-50.0,-50.0}, extent={{-10.0,-10.0},{10.0,10.0}}, rotation=0))); Modelica.Mechanics.Rotational.Sensors.SpeedSensor speedSensor1 annotation(Placement(visible=true, transformation(origin={80.0,-30.0}, extent={{-10.0,-10.0},{10.0,10.0}}, rotation=-90))); Modelica.Blocks.Interfaces.RealOutput w annotation(Placement(visible=true, transformation(origin={80.0,-60.0}, extent={{-10.0,-10.0},{10.0,10.0}}, rotation=-90), iconTransformation(origin={-40.0,-60.0}, extent={{-10.0,-10.0},{10.0,10.0}}, rotation=-180))); Modelica.Electrical.Analog.Sensors.CurrentSensor currentSensor1 annotation(Placement(visible=true, transformation(origin={30.0,30.0}, extent={{-10.0,-10.0},{10.0,10.0}}, rotation=0))); Modelica.Blocks.Interfaces.RealOutput motori annotation(Placement(visible=true, transformation(origin={10.0,10.0}, extent={{-10.0,-10.0},{10.0,10.0}}, rotation=-180), iconTransformation(origin={-50.0,30.0}, extent={{-10.0,-10.0},{10.0,10.0}}, rotation=-180))); Modelica.Mechanics.Rotational.Interfaces.Support support1 annotation(Placement(visible=true, transformation(origin={30.0,-50.0}, extent={{-10.0,-10.0},{10.0,10.0}}, rotation=0), iconTransformation(origin={25.719,-74.281}, extent={{-4.281,-4.281},{4.281,4.281}}, rotation=0))); equation connect(speedSensor1.w,w) annotation(Line(visible=true, origin={80.0,-50.5}, points={{0.0,9.5},{0.0,-9.5}}, color={0,0,127})); connect(speedSensor1.flange,flange) annotation(Line(visible=true, origin={80.0,-10.0}, points={{0.0,-10.0},{0.0,10.0}})); connect(currentSensor1.i,motori) annotation(Line(visible=true, origin={23.3333,13.3333}, points={{6.6667,6.6667},{6.6667,-3.3333},{-13.3333,-3.3333}}, color={0,0,127})); connect(inductor.n,currentSensor1.p) annotation(Line(visible=true, origin={15.0,30.0}, points={{-5.0,-0.0},{5.0,0.0}}, color={0,0,255})); connect(currentSensor1.n,EMF1.p) annotation(Line(visible=true, origin={46.6667,23.3333}, points={{-6.6667,6.6667},{3.3333,6.6667},{3.3333,-13.3333}}, color={0,0,255})); connect(EMF1.n,ground.p) annotation(Line(visible=true, origin={0.0,-29.0}, points={{50.0,19.0},{50.0,-6.0},{-50.0,-6.0},{-50.0,-11.0}}, color={0,0,255})); connect(EMF1.flange,flange) annotation(Line(visible=true, origin={70.0,0.0}, points={{-10.0,0.0},{10.0,-0.0}})); connect(EMF1.support,support1) annotation(Line(visible=true, origin={33.3333,-16.6667}, points={{6.6667,16.6667},{-3.3333,16.6667},{-3.3333,-33.3333}})); connect(voltageSource.n,ground.p) annotation(Line(visible=true, origin={-55.0,-29.0}, points={{-5.0,19.0},{-5.0,-6.0},{5.0,-6.0},{5.0,-11.0}}, color={0,0,255})); connect(inductor.p,resistor.n) annotation(Line(visible=true, origin={-15.0,30.0}, points={{5.0,0.0},{-5.0,0.0}}, color={0,0,255})); connect(resistor.p,voltageSource.p) annotation(Line(visible=true, origin={-53.3333,23.3333}, points={{13.3333,6.6667},{-6.6667,6.6667},{-6.6667,-13.3333}}, color={0,0,255})); connect(u,voltageSource.v) annotation(Line(visible=true, origin={-78.5,0.0}, points={{-11.5,0.0},{11.5,0.0}}, color={0,0,127})); end Motor; model Brick "Models a LEGO CPU brick" annotation(Documentation(info="

# LEGO Segway: Controlling an Inverted Pendulum

## Description

This models the brick with the CPU of a LEGO Segway.

View the model diagram for this model.

## Terms and Conditions of Use

This domain example is an informational resource made freely available by Wolfram Research.

### Use of This Example

• You may not use this example for any purpose that is unlawful or dangerous.
• You assume total responsibility and risk for your use of this example.
• You may not present this example with any alteration to its trade dress, trademarks, or design.

A summary of the licensing terms can be found at:

The full legal code can be found at:

# LEGO Segway: Controlling an Inverted Pendulum

## Description

This models the gyroscopic sensor of a LEGO Segway.

View the model diagram for this model.

## Terms and Conditions of Use

This domain example is an informational resource made freely available by Wolfram Research.

### Use of This Example

• You may not use this example for any purpose that is unlawful or dangerous.
• You assume total responsibility and risk for your use of this example.
• You may not present this example with any alteration to its trade dress, trademarks, or design.

A summary of the licensing terms can be found at:

The full legal code can be found at:

", revisions=""), Icon(coordinateSystem(extent={{-100.0,-100.0},{100.0,100.0}}, preserveAspectRatio=true, initialScale=0.1, grid={10,10}), graphics={Bitmap(visible=true, origin={13.0175,6.0371}, rotation=-360, fileName="", imageSource="iVBORw0KGgoAAAANSUhEUgAAANIAAAEhCAYAAAAK6P5BAAAAAXNSR0IArs4c6QAAAAZiS0dE AP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9sKDgcdC3Ozis8AAB4L SURBVHja7Z1/cBvneee/C4CiALtKTFg0GSxINY7oHzlRnugHAVmhdVZypwiupaHANNPmMhfP VW6kxBYvSasb+SbM2LpRqmkpq6luok6bzriTiUOQpjWBwnb8g6YlYxFFjhRfnLOsuCaxsBx6 QF81MSDx194f4LvYBUASJBYgSH4/Mzv2kgRAgfvB87zPvu/zAoQQQgghhBBCCCGEEEIIIYQQ QgghlYq0HP9RA6+d19568zeAVOA/UDL/j1SON1la+CuNOyYL/2FN/EfDga/sl3jJUyQTL7zy ivabN3+N//vmm/i7v/0+/5IL5GuPH8BdG+7F3c2fxq6t/5GirST2//mj2vRnLQ+Ljrq6Ou2/ HfgzjVfXCuCFV17R7r77Ll74JTy2bt2i/Sz6MoVarrw4OMgLvUzHunXrtP6fU6Zlx569e3mB L8LxN6dPUqblwoGvH+RFvYjHnx18lDIt6fHQ4CtaXV0dL+YKOP78sa9RpiU5HnqV46FKOw4c +jqLEEuJrr89OesftL6+nhd2CY677moq6L39lwsDlKnS+cbjj/GiXgJS/cuFVyhTJfKzF1/Q Or7ZwehTgcdM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}), Diagram(coordinateSystem(extent={{-74.0,-52.5},{74.0,52.5}}, preserveAspectRatio=true, initialScale=0.1, grid={5,5}))); import SI = Modelica.SIunits; parameter Modelica.SIunits.RotationalDampingConstant d_legoBody=1e-05 "LEGO Body damper constant"; Modelica.Blocks.Interfaces.RealOutput Phi annotation(Placement(visible=true, transformation(origin={-30.0,30.0}, extent={{-10.0,-10.0},{10.0,10.0}}, rotation=-270), iconTransformation(origin={-26.1548,-78.278}, extent={{-6.1548,-6.1548},{6.1548,6.1548}}, rotation=-90))); Modelica.Blocks.Interfaces.RealOutput Omega annotation(Placement(visible=true, transformation(origin={30.0,30.0}, extent={{-10.0,-10.0},{10.0,10.0}}, rotation=-270), iconTransformation(origin={-10.0,-77.943}, extent={{-5.8914,-5.8914},{5.8914,5.8914}}, rotation=-90))); Modelica.Mechanics.Rotational.Sensors.SpeedSensor speedSensor1 annotation(Placement(visible=true, transformation(origin={30.0,0.0}, extent={{-10.0,-10.0},{10.0,10.0}}, rotation=-270))); Modelica.Mechanics.Rotational.Interfaces.Flange_a flange_a1 annotation(Placement(visible=true, transformation(origin={30.0,-30.0}, extent={{-10.0,-10.0},{10.0,10.0}}, rotation=0), iconTransformation(origin={23.9901,-80.0}, extent={{-6.0099,-6.0099},{6.0099,6.0099}}, rotation=0))); Modelica.Mechanics.Rotational.Sensors.AngleSensor angleSensor1 annotation(Placement(visible=true, transformation(origin={-30.0,0.0}, extent={{-10.0,-10.0},{10.0,10.0}}, rotation=-270))); Modelica.Mechanics.Rotational.Interfaces.Flange_a flange_a2 annotation(Placement(visible=true, transformation(origin={-30.0,-30.0}, extent={{-10.0,-10.0},{10.0,10.0}}, rotation=0), iconTransformation(origin={6.1564,-80.0}, extent={{-6.1564,-6.1564},{6.1564,6.1564}}, rotation=0))); equation connect(angleSensor1.flange,flange_a2) annotation(Line(visible=true, origin={-30.0,-20.0}, points={{-0.0,10.0},{0.0,-10.0}})); connect(angleSensor1.phi,Phi) annotation(Line(visible=true, origin={-30.0,20.5}, points={{-0.0,-9.5},{0.0,9.5}}, color={0,0,127})); connect(speedSensor1.w,Omega) annotation(Line(visible=true, origin={30.0,20.5}, points={{0.0,-9.5},{-0.0,9.5}}, color={0,0,127})); connect(speedSensor1.flange,flange_a1) annotation(Line(visible=true, origin={30.0,-20.0}, points={{0.0,10.0},{-0.0,-10.0}})); end Gyro; model SmallLeftTire "Models a LEGO tire" annotation(Documentation(info="

# LEGO Segway: Controlling an Inverted Pendulum

## Description

This models the left tire of a LEGO Segway.

View the model diagram for this model.

## Terms and Conditions of Use

This domain example is an informational resource made freely available by Wolfram Research.

### Use of This Example

• You may not use this example for any purpose that is unlawful or dangerous.
• You assume total responsibility and risk for your use of this example.
• You may not present this example with any alteration to its trade dress, trademarks, or design.

A summary of the licensing terms can be found at:

The full legal code can be found at:

# LEGO Segway: Controlling an Inverted Pendulum

## Description

This models the right tire of a LEGO Segway.

View the model diagram for this model.

## Terms and Conditions of Use

This domain example is an informational resource made freely available by Wolfram Research.

### Use of This Example

• You may not use this example for any purpose that is unlawful or dangerous.
• You assume total responsibility and risk for your use of this example.
• You may not present this example with any alteration to its trade dress, trademarks, or design.

A summary of the licensing terms can be found at:

The full legal code can be found at:

# LEGO Segway: Controlling an Inverted Pendulum

## Introduction

This model is of a standalone LEGO Segway. This model is used as a component in the models with control and without control.

View the model diagram for this model.

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

## Terms and Conditions of Use

This domain example is an informational resource made freely available by Wolfram Research.

### Use of This Example

• You may not use this example for any purpose that is unlawful or dangerous.
• You assume total responsibility and risk for your use of this example.
• You may not present this example with any alteration to its trade dress, trademarks, or design.

A summary of the licensing terms can be found at:

The full legal code can be found at:

# LEGO Segway: Controlling an Inverted Pendulum

## Description

This is a bare-bones LEGO Segway model used to build up the final Segway.

View the model diagram for this model.

## Terms and Conditions of Use

This domain example is an informational resource made freely available by Wolfram Research.

### Use of This Example

• You may not use this example for any purpose that is unlawful or dangerous.
• You assume total responsibility and risk for your use of this example.
• You may not present this example with any alteration to its trade dress, trademarks, or design.

A summary of the licensing terms can be found at:

The full legal code can be found at:

", revisions="")); end LEGOSegwayBase; end Components; model LQControl "Model of a LEGO Segway with an LQ controller keeping it upright" annotation(preferredView="info", Documentation(info="

# 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 Mathematica. Open the accompanying notebook LEGOSegway.nb in Mathematica 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

Plotting the path of the Segway is simple in Simulation Center:

• Click the icon for creating a new parametric plot .
• In the Plot tab on the left, expand the tree to segway, wheelSet and check the variables x and y.

Also plot the angle of the Segway:

• Click the icon for creating a new plot .
• In the Plot tab on the left, expand segway and check the variable Phi.

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 in Mathematica.

## Terms and Conditions of Use

This domain example is an informational resource made freely available by Wolfram Research.

### Use of This Example

• You may not use this example for any purpose that is unlawful or dangerous.
• You assume total responsibility and risk for your use of this example.
• You may not present this example with any alteration to its trade dress, trademarks, or design.

A summary of the licensing terms can be found at:

The full legal code can be found at:

# LEGO Segway: Controlling an Inverted Pendulum

CONTENTS:
 ˇ Introduction ˇ Simulation

## Introduction

This model is of a LEGO Segway with disturbances, but without any kind of controller to keep it upright. For the model with a controller, open LEGOSegway.LQControl.

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 .

Parts of this example require Mathematica. Open the accompanying notebook LEGOSegway.nb in Mathematica for those scenarios.

## Terms and Conditions of Use

This domain example is an informational resource made freely available by Wolfram Research.

### Use of This Example

• You may not use this example for any purpose that is unlawful or dangerous.
• You assume total responsibility and risk for your use of this example.
• You may not present this example with any alteration to its trade dress, trademarks, or design.

A summary of the licensing terms can be found at:

The full legal code can be found at: