필터 지우기
필터 지우기

How to connect simulink real-time(or step-by-step) control with python for RL

조회 수: 9 (최근 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
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
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
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개)

카테고리

Help CenterFile Exchange에서 Call Python from MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by