How to connect simulink real-time(or step-by-step) control with python for RL
5 次查看(过去 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!