WOLFRAM SYSTEM MODELER

InvertedPendulumHardware

A LQR-controlled inverted pendulum system, controlled by external hardware using the ModelPlug library

Diagram

Wolfram Language

In[1]:=
SystemModel["EducationExamples.MechanicalEngineering.InvertedPendulum.InvertedPendulumHardware"]
Out[1]:=

Information

Library Dependency

This model requires the ModelPlug and PlanarMechanics libraries.

  • ModelPlug is a free Modelica library that allows you to link your simulation models to the real world by the use of an Arduino Board or any other board following the Firmata protocol). ModelPlug opens up a wide variety of ways to interact with your models, for example by using buttons, switches, input sensor information or even actuators such as motors and servos.
  • The free PlanarMechanics library was created especially for modeling multibody systems with two-dimensional mechanical components. Compared to the MultiBody library, currently available in the Modelica Standard Library, it is simpler to use and it is more optimized to planar modeling. Planar models of mechanical systems are useful in many different applications, for example, in contact problems that are more easily modeled in 2D than in 3D.

Model

This model is a variation of the main example model. It uses connection to external hardware to control the magnitude of the disturbance forces.

External Connection

To run this model, you will need to connect an Arduino board to your computer and control the input to two analog pins, for example, thumbwheel potentiometers. Adjust the port of the Arduino component to the one used by your connected board with the Port parameter.

Parameters (12)

cartMass

Value: 1

Type: Mass (kg)

Description: Mass of the cart (base of the pendulum)

cartInertia

Value: 0.1

Type: Inertia (kg⋅m²)

Description: Inertia of the cart (base of the pendulum)

pendulumMass

Value: 0.5

Type: Mass (kg)

Description: Mass at the top of the pendulum

pendulumInertia

Value: 0.1

Type: Inertia (kg⋅m²)

Description: Inertia at the top of the pendulum

angle0

Value: 0

Type: Angle (rad)

Description: Initial angle of the pendulum

port

Value: "COM4"

Type: SerialPort

Description: Name of the serial port

cartPin

Value: 14

Type: Integer

Description: Number of the analog pin

cartMinValue

Value: -0.22

Type: Real

Description: Minimum value when the ADC reads 0

cartMaxValue

Value: 0.5

Type: Real

Description: Maximum value when the ADC reads 1024

pendulumPin

Value: 15

Type: Integer

Description: Number of the analog pin

pendulumMinValue

Value: -0.22

Type: Real

Description: Minimum value when the ADC reads 0

pendulumMaxValue

Value: 0.5

Type: Real

Description: Maximum value when the ADC reads 1024

Connectors (5)

s

Type: RealOutput

Description: Absolute position of flange as output signal (position.s)

v

Type: RealOutput

Description: Absolute velocity of flange as output signal (speed.v)

phi

Type: RealOutput

Description: Absolute angle of flange as output signal (angle.phi)

w

Type: RealOutput

Description: Absolute angular velocity of flange as output signal (angularVelocity.w)

y

Type: RealOutput[controller.nout]

Description: Connector of Real output signals (controller.y)

Components (18)

pendulum

Type: Body

Description: Pendulum mass.

origin

Type: Fixed

Description: Center point. Reference point for cart.

cart

Type: Body

Description: Mass of cart.

planarWorld

Type: PlanarWorld

Description: Planar world coordinate system + gravity field + default animation definition

revolute

Type: Revolute

Description: Pendulum axis of rotation.

cartPosition

Type: Prismatic

Description: Translational position of cart.

angle

Type: AngleSensor

Description: Angle sensor for the pendulum.

controller

Type: MatrixGain

Description: LQ-regulator with optimal gains.

position

Type: PositionSensor

Description: Position sensor for the cart.

angularVelocity

Type: SpeedSensor

Description: Velocity sensor for the pendulum.

speed

Type: SpeedSensor

Description: Velocity sensor for the cart.

disturbancePendulum

Type: WorldForce

Description: Disturbance force applied on the pendulum.

disturbanceCart

Type: WorldForce

Description: Disturbance force applied on the cart.

pendulumLength

Type: FixedTranslation

Description: Length of the pendulum.

controllerForce

Type: WorldForce

Description: Corrective force applied to the cart.

cartInput

Type: AnalogInput

Description: Reads an analog signal from the specified pin

arduino

Type: Arduino

Description: Component with default configuration for Arduino boards

pendulumInput

Type: AnalogInput

Description: Reads an analog signal from the specified pin