Simulink TCP/IP Receive Data Used 120s (2 Steps) Late in HIL Control (Python Server)

조회 수: 6 (최근 30일)
I'm setting up a HIL simulation where a Python script on a Raspberry Pi calculates control commands based on data sent from my Simulink plant model running on a PC . The Simulink model has a fundamental step time of 60 seconds.
Setup & Communication:
Simulink uses TCP/IP Send to send sensor data (20 doubles) to Python.
Python server receives data, performs calculations (~1-2 seconds), and sends back control commands (2 doubles) using client.sendall() over the same connection.
Simulink uses TCP/IP Receive to get these 2 doubles from the Python server
The received Buy/Sell commands are intended to be used by the simulink model in the current simulation step.
I've observed a consistent 120-second (exactly two simulation steps) delay between when Python sends the control commands for time step i and when those commands affect the simulation results in Simulink, which appears to happen during time step i+2.
Python is Fast: Python logs confirm it calculates and executes sendall very quickly (~1-2 seconds) after receiving data for time step i. Logs show "Successfully executed sendall." promptly.
CP/IP Receive Block Configuration (Current Settings):
Data size: [1 2]
Source Data type: double
Byte order: LittleEndian
Enable blocking mode: tried both (enabled and disabled)
Block sample time: -1 or 60
Troubleshooting/Checks:
Confirmed Python sends promptly.
Confirmed basic network connectivity.
My Question:
What could be causing this specific and consistent two-step (120s) delay between Python sending data and Simulink using it?
Given the TCP/IP Receive settings, are there other common configuration issues that manifest as a multi-step delay for TCP/IP received data?
I need the commands calculated for time step i to be used during the simulation of Hour i. How can I configure the blocks or diagnose the model further to eliminate this 120s delay?
Thanks for any insights!

답변 (0개)

카테고리

Help CenterFile Exchange에서 Direct Interface Communication in Simulink에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by