Software Practice | Python + MapleSim + Insight Realize Real-time Simulation

thumbnail

brief introduction

This example uses a Python script to run the driving process of the vehicle dynamics FMU model on uneven ground, and uses the computer keyboard to control the running direction of the vehicle in real time.

The vehicle dynamics model FMU file is generated by MapleSim; the FMU model is run in real time through the FMPy library in Python; MapleSim Insight is responsible for the real-time visualization of the model.

In MapleSim, 16 degrees of freedom (6 for chassis, 4 for independent suspension, 2 for steering, 4 for rotation) and Pacejka2012 tire model are used to model the entire vehicle dynamics.

Vehicle dynamics model files and Python scripts can be downloaded through the following links:

https://github.com/sbonab/sim-insider/tree/main/MapleSim_Insight_FMPy/Vehicle

Steps

Step 1: Build a dynamic model - export FMU

The vehicle dynamics model is established in the MapleSim multidisciplinary system modeling software and exported as an FMU format file.

Step 2: Configure the Python environment and install the necessary library files

The following defaults in Windows OS.

  1. Create a new Conda environment;

  2. Activate the created environment in Conda;

  3. Install FMPy using the following command:

conda install -c conda-forge fmpy

  1. Install the keyboard library and jupyter notebook;

pip install keyboard

conda install -c conda-forge jupyterlab

  1. After activating the environment, open jupyter and load the Python script NFS.ipynb .

Step 3: Configure MapleSim Insight real-time visualization

Make sure you have MapleSim Insight installed.

Typing simulate_custom_input() will wake up MapleSim Insight.

Alternatively, you can load Vis.simData directly in MapleSim Insight .

Then, run the python script to control the vehicle through the number key 1235.

The Python script is as follows:

Latest Programming News and Information | GeekBar

Related Posts