How to connect simulink real-time(or step-by-step) control with python for RL
10 ビュー (過去 30 日間)
古いコメントを表示
I'm trying to connect simulink model with python to control the model with Reinforcement learning
For this, I need to simulate a few timesteps (for example, 0.01hr)
then python reads current states and sets the control value by using policy / also learning and optimizing policy
I am currently using the pause method with matlab engine API:
By using clock and assertion block, if simulation time reaches that specific interval(0.01hr), simulation pauses
python checks the simulation status constantly, and if simulation is paused, it reads state values, set control, learns
and then resume simulation.
This works quite well, but repeatedly pausing simulation spends too much time.
Doing 5hr simulation 6000 times takes 3 whole days.
Is there any way better/faster?
I tried TCP-IP connecting but I don't have lincense for corresponding toolbox and I think control action cannot be applied for every fixed timestep for its real-timedness.
Thanks in advance.
2 件のコメント
Sijin
2022 年 11 月 30 日
Hi,
Did you find a solution for this? I am having a similar usecase, and currently using the pause to update the control action from Python. As you mentioned, it takes a lot of time for a meaningful number of training steps.
Please share if you have found some better solution.
Best Regards,
Sijin
Enzo Yacometti
2022 年 12 月 13 日
Hello, if anyone has a solution to this I would be very interested. I'm currently also pausing and resuming constantly the simulation. Thank you.
採用された回答
Pratik
2024 年 1 月 3 日
Hi 원혁 최,
As per my understanding, you want to connect a Simulink model with python to control the model with Reinforcement learning. Using the MATLAB engine API and pausing the Simulink model makes the whole process slow.
To run Python code in a Simulink model, a MATLAB function block or a MATLAB System block can be used. To call Python modules in MATLAB, there should be a supported version of the reference implementation (CPython) installed on the system.
Please refer to the following documentation for an example usage of a MATLAB function block and a MATLAB System block:
Please refer to this question on MATLAB answers for more information:
I Hope this helps.
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Call Python from MATLAB についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!