Balancing cart with state feedback control / Controller realisation in HOTINT, X2C and Simulink

This tutorial shows three possible ways to realize a controller and couple it with a dynamic simulation in HOTINT. You can download all source files of these examples.

balancing_cart

Controller implemented in HOTINT

In this example a given state feedback controller \(u=\vec{k}^{T}x\) is tested in a dynamic simulation. An inverse pendulum is mounted on a cart. The states are measured. These values are used by a controller to stabilize the pendulum by adjusting a force acting on the cart. The dynamic simulation shows the response of the mechatronic system to a disturbance. The coefficients of the controller are \(\vec{k}^{T}=[-3, -6, 51, 21]\). This controller is realised in balancing_cart_LQR_HOTINT.hid.

Realisation

At first the balancing_cart.hid file have to be included. This gives an access to all data which are specified therein. In this example the sensors and the ElementSet setCart are needed.

The controlled force is calculated by a linear transformation which is implemented in the IOLinearTransformation.

Next the force be assigned to a force vector. It can be done with ForceVector3D from the Load elements. The command AssignLoad adds the force vector to the cart.
That’s it!

To load this file in HOTINT use the OpenMBS command in the file-menu. The computation starts by hitting the Start! button.
For further information about the used commands have a look at the documentation.

Controller implementation in X2C

The open source software X2C offers an comfortable way to use models from the graphical programming environment Xcos for the computation in HOTINT. The big win is that both are freely available. With the Communicator from X2C the Xcos model can be compiled easily. The result is an application which have to be started at the beginning of the computation.

This example shows how to control the balancing cart with an state feedback controller realised in Xcos.

Realisation

There are again only tiny modification to do in the balancing_cart_LQR_HOTINT.hid file. Here we use the IOX2C command instead of the IOLinearTransformation. Again the communication run locally on the computer. So the default address 127.0.0.1 is in use. For the port number 10000 is chosen. That’s it!

Run the example

  • Load the balancing_cart_LQR_X2C.hid in HOTINT.
  • Click the Start! button in HOTINT.
  • Start the application that was created with X2C.

For further information about the used commands have a look at the documentation.

Cart_xcos

Controller implementation in MATLAB/Simulink

In HOTINT it is possible to connect to other programs or tools via TCP/IP. This example shows how to control the balancing cart with an state feedback controller realised in Simulink.

Realisation

In the example balancing_cart_LQR_HOTINT.hid the state feedback controller is directly implemented in HOTINT. With slight modifications this file can be used for the connection with Simulink. The only thing to do is to use IOTCPIP instead IOLinearTransformation. In this example the communication run locally on the computer. So the default address 127.0.0.1 is in use. For the port number 50000 is chosen. That’s it!

Run the example

  • Load the balancing_cart_LQR_TCPIP.hid in HOTINT.
  • Load the LQRcontrol.mdl in Simulink
  • Click the Start! button in HOTINT.
  • Click the Start simulation button in Simulink

For further information about the used commands and the TCP/IP connection have a look at the documentation.

X2C is an open source tool for the model-based development and code generation of real time control algorithms for micro processor units.
X2C

X2C and HOTINT are developed at LCM GmbH

Linz Center of Mechatronics GmbH
with great support of the Institute of Technical Mechanics at Johannes Kepler University Linz

Institute of Technical Mechanics at Johannes Kepler University Linz
and with the support of the province of Upper Austria

Land Oberösterreich
within the regional development program Regio13 of the European Union

Land Oberösterreich

Imprint