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

Discussão em 'Python' iniciado por Stack, Maio 8, 2025.

  1. Stack

    Stack Membro Participativo

    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!

    [​IMG]

    Continue reading...

Compartilhe esta Página