Create your own simulation dashboard

Sometimes users do not have a background in Dymola, however they require information obtained through simulation. One way they can get this information without having to learn Dymola is if someone creates a simple simulation dashboard in which they can only modify the parameter of interest and view the results they may be interested in. This post has a look at how this can be done using the Python interface.

Why use Python?

Dymola provides an interface to the Python as described in Section 12.3 Python Interface for Dymola of the Dymola Full User Manual. This interface makes it easy to call Dymola functions from a Python programme. Also Python is a relatively easy programming language to learn and code in and contains many useful open source libraries. For example the PyQt6 library provides a Python Qt interface which I make use of to create a simple simulation dashboard.

The PyQt6 package

The PyQt6 package gives Python users the ability to make Qt graphical user interfaces. Qt comes with a number of graphical objects called widgets such as check boxes, combo boxes, dials, labels, sliders, input text boxes and much more. There is also a Qt Designer app for building the entire simulation dashboard in a graphical drag and drop environment. In this example I do create the simulation dashboard using only PyQt6 code.

The Dymola model: Trailer model

The example of a vehicle pulling a trailer is going to be the model being simulated, this model is in Figure 1.

Figure 1. Loaded trailer example

Figure 1. Loaded trailer example

The mass and location of the load in the trailer can be altered by changing the parameters m and the r respectively. Many other parameters can also be altered; however, in this example we will also be interested in changing the roughness of the road which is done by redeclaring the roadRoughness model used in the road component. The vehicle is controlled to perform one slalom manoeuvre and then continue driving straight. This example was taken from the YouTube video: The truth about weight distribution and trailers …proven!

Creating the PyQt6 interface

The Python GUIS tutorial website was used to create my simple dashboard. In my case I chose to just include the mass, the location of the mass relative to the centre of the trailer axle and the road roughness in the interface. To do this the code in Figure 2 was used:

Figure 2. Python code to generate the graphical dashboard. Note that the run_done function is collapsed

Figure 2. Python code to generate the graphical dashboard. Note that the run_done function is collapsed.

For more details on how this code works please refer to the Python GUIS tutorial website. This code focuses on how to create the graphical dashboard and does not show all the checking and error handling that is required. The code does also not include the Python Dymola interface which you can find out more about in our Claytex Python interface course.

The dashboard created is in Figure 3.

Figure 3. Simple dashboard

Figure 3. Simple dashboard

The dashboard consists of two text edit boxes for setting the load mass and centre of mass and a combo box for setting the road roughness.

The simple dashboard

When this code is run the user sets the mass, centre of mass of the load and the road roughness and then presses the Done button as in Figure 4.

Figure 4. The simple dashboard with results

When the Done button is pressed the run_done function from Figure 2, is run which interfaces with Dymola to simulate the trailer example with the desired settings and plots the wheel slip angle, alpha, for the left trailer wheel and the rotational angles of the hitch as well as the vehicle towing the trailer animation.

Once this simulation is performed it can be run again with different parameters by adjusting the parameters in the dashboard and pressing Done.

Conclusions

This post describes how PyQt6 can be used to create a simple dashboard. For more information about the Dymola/Python interface, please refer to Claytex training course.

Written by: Garron Fish – Chief Engineer

Please get in touch if you have any questions or have got a topic in mind that you would like us to write about. You can submit your questions / topics via: Tech Blog Questions / Topic Suggestion

CONTACT US

Got a question? Just fill in this form and send it to us and we'll get back to you shortly.

Sending

© Copyright 2010-2023 Claytex Services Ltd All Rights Reserved

Log in with your credentials

Forgot your details?