How to run on-demand asynchronous tasks in Simulink?

3 views (last 30 days)
I wonder how one could implement an on-demand computation task in Simulink that will keep running in the background until finished while not holding up the step-by-step propagation of the Simulink operation.
An example would be: a vehicle follows a path provided by a planner module. The planner module replans the future path in an on-demand manner when a new situation is detected. The vehicle KEEPS TRACKING the previous path without waiting for the replanning results. And the planner module in the meantime replans the path for the new situation, which will take a few seconds of time. Once the new path is calculated, it replaces the old path in Simulink. An illustration figure is shown below(source of figure)
https://www.dlr.de/sr/en/desktopdefault.aspx/tabid-15356/24932_read-62365/
Can this be done for example, by two individual Simulink models, in which model A is running the vehicle controller with an existing planned path, and model B is the on-demand re-planner?
Any hint is appreciated.
  1 Comment
Tong Zhao
Tong Zhao on 20 Jul 2022
Update: is it possible to use some Simulink-constructed communication protocol to link one Simulink model running on computer A to another Simulink model running on computer B on the same local network, and effectively creating an asynchronous communication channel in this way? If so, then I can place my main path tracking controller in computer A, while placing my on-demand planner in computer B.

Sign in to comment.

Answers (1)

Karan Singh
Karan Singh on 29 Sep 2023
Hi Tong,
From what I understand, you want guidance on implementing an on-demand computation task in Simulink while ensuring that it runs in the background without interrupting the step-by-step propagation of the Simulink operation.
While one approach being you can use a combination of Stateflow and Simulink blocks. You can have steps as:
  1. Create a Stateflow chart: Start by creating a Stateflow chart that represents the planner module. This chart will handle the replanning task and run independently in the background. It should have states to handle the different stages of the replanning process.
  2. Trigger the replanning task: In Simulink, use an event-based trigger to initiate the replanning task. This trigger can be based on a condition that signals the need for replanning.
  3. Transition to the replanning state: When the trigger condition is met, transition to a replanning state in the Stateflow chart. This state will handle the actual computation of the new path. You can use MATLAB functions or Simulink blocks within this state to perform the replanning calculations.
  4. Update the path: Once the new path is calculated, update the path variable or data structure in the Stateflow chart to store the new path information.
  5. Transition back to the tracking state: After the path is updated, transition back to the tracking state in the Stateflow chart. This state will continue to track the vehicle's position using the previous or updated path information.
For your comment, yes, it is possible to establish communication between two Simulink models running on different computers on the same local network. One common approach is to use the Simulink Real-Time product, which allows you to connect Simulink models running on different computers using TCP/IP or UDP/IP communication protocols.
Attached below are some documentation links that you may find helpful:
Hope this helps!
Karan Singh Khati

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!