Cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted

Control Simcenter Amesim simulation with Telegram Bot

Experimenter
Experimenter

On YouTube I found a mind blowing video of Alejandro Magnitopic who easily created a working Telegram Bot communicating with a Python application. This video is the base of the project I would like to present to you in this article and most of the source code is coming from Alejandro. The video you can find here: https://www.youtube.com/watch?v=q9YScw0YBB4. It gives you also the first steps of how creating a Telegram Bot. I do not want to describe it in detail here.

 

The first task was to get the request Python resources into Amesim to get a easy to use web communication. Therefore I go from my point of view the easiest way. I went to https://pypi.org/project/ and downloaded the sources. After the download I just copied the resource into my Simcenter Amesim Folder (C:\Amesim\v1600\Amesim\sys\python\win64\Lib) like you can see in the picture below. There are some more resources needed to get requests started. The complete list you can find it the header of my code in the attachment.

 

Python_Lib_Directory.jpgSimcenter Amesim directory for Python ressources

After I had all the resources to get the Python code running I started using the Simcenter Amesim Simulation Scripting routines to control my simulation project. The Simcenter Amesim simulation is very easy as it is just a spring mass damper system. Using the Simcenter Amesim Help it was very easy to create the code finding the correct references. The code allows me to set a parameter, run the simulation and get a variable for further post processing.

 

And that’s it! My Telegram Amesim Bot Python script is ready. There are just some stumbling blocks in the way you have to move to the side:

 

  1. Please make sure that the Python script is in the same folder like your Simcenter Amesim model
  2. Please compile your Simcenter Amesim model going to simulation mode so that there is a working executable. You can also force recompilation in the menu bar under File – Force recompilation (Ctrl + T)
  3. Write the files for simulation in the menu bar under File – Write files for simulation (Ctrl + Shift + W)
  4. Change the Telegram Bot token and the model file name in the source code to your special bot and model.

 

Now I just have to open my Simcenter Amesim Model and start the Python command interpreter and give following command:

import Telegram_Amesim_Bot.py

 

 

 

Amesim_Python_Command_Interpreter.jpgSimcenter Amesim model and launched Telegram Bot in Python command interpreterIf the script started without any error you can use your Telegram App to control your Simcenter Amesim model. The picture below shows the possible commands. You will also see some feedback in the Python command interpreter.

 Telegram_App.jpgTelegram App showing Simcenter Amesim Bot interacting

 

So I hope you will enjoy your new simulation possibilities using Telegram Bot and Simcenter Amesim with Python scripting!

5 REPLIES

Re: Control Simcenter Amesim simulation with Telegram Bot

Siemens Phenom Siemens Phenom
Siemens Phenom
Very nice! Thanks for sharing.

Re: Control Simcenter Amesim simulation with Telegram Bot

Siemens Valued Contributor Siemens Valued Contributor
Siemens Valued Contributor

Hi Jesko!

 

Great work! thanks for sharing! this looks really cool!

 

Regards

Dennis

Re: Control Simcenter Amesim simulation with Telegram Bot

Siemens Phenom Siemens Phenom
Siemens Phenom

Tried it and it does work nicely (not on VPN).

 

Being a Python novice, I only struggled to extract the packages properly, this is how it should look like.

Okay there's probably too many folders I left in there, but it does work.

image.png

Re: Control Simcenter Amesim simulation with Telegram Bot

Experimenter
Experimenter

Hi Emmanuel_D,

 

Thanks for validating the code. I also faced the same issue that is not working under some circumstances like VPN connection.

 

Regarding the Python packages I am also a novice. For me it worked also only copying the “request” folder which is highlighted in the picture below. The other folders like .egg-info, tests and the other files are not necessary.

Maybe there is a Python expert in the forum who can explain it to us.

 

 

Requests_Python_Source_Package.jpg

 

Re: Control Simcenter Amesim simulation with Telegram Bot

Siemens Valued Contributor Siemens Valued Contributor
Siemens Valued Contributor

Hi @NicoV, maybe you can chip-in with some of that knowledge of yours on this topic??

 

Cheers

Dennis