You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This example showcases a basic "Hello world" interactive simulation.
3
+
The `InteractiveSimulation` is a 'Hello world' MATLAB-based simulation that interacts with external clients, processes telemetry data, and returns predicted positions for a moving object. Both input and output are in streaming.
4
+
The simulation operates in steps: it receives input, validates it, computes the next position using velocity and time, and sends the result back. This process repeats for up to 100 steps.
4
5
5
-
The simulation relies on `SimulationWrapperInteractive.m` to manage TCP/IP communication with the MATLAB agent, allowing real-time data exchange between the simulation and the client.
6
+
Telemetry data must include time (`t`), position (`x`, `y`), and velocity (`vx`, `vy`). The simulation uses the Euler method to predict the next position (`x_next`, `y_next`). If required data is missing or invalid, an error message is returned. After 100 steps, the simulation terminates.
7
+
8
+
Communication with the MATLAB agent is handled via TCP, using the `SimulationWrapperInteractive` object to manage data exchange.
-[Simulation Steps and Flow](#simulation-steps-and-flow)
12
16
13
17
## Usage
14
18
15
-
Before running the simulation, you need to configure the Matlab agent by setting the simulation folder path in the `config.yaml` file under the simulation section:
19
+
Run this simulation interactively with a Python client using the specified API payload.
16
20
17
21
```yaml
18
22
simulation:
19
-
path: <path_to_simulation_folder>
20
-
```
23
+
# Unique identifier for this simulation request. This ID is used to track and reference the simulation request.
24
+
request_id: abcdef12345
21
25
22
-
This path should point to the directory `interactive-simulation` containing the simulation files
26
+
# Identifier for the client that is sending the simulation request.
27
+
client_id: dt
23
28
24
-
Once configured, you can initiate the simulation using the API as described below.
29
+
# Specifies the simulator type. In this case, it indicates that the simulation is running in MATLAB.
30
+
simulator: matlab
25
31
26
-
The simulation can be initiated via the API by submitting a YAML payload, a template of which is available in the file `api/simulation.yaml`
32
+
# Type of simulation. Here, it indicates that the simulation is "interactive", meaning it involves continuous interaction.
33
+
type: interactive
27
34
28
-
```yaml
29
-
simulation:
30
-
request_id: abcdef12345 # Unique identifier for this simulation request
31
-
client_id: dt # Client identifier for tracking purposes
32
-
simulator: matlab # Specifies MATLAB as the simulation engine
33
-
type: interactive # Indicates this is an interactive simulation type
34
-
file: InteractiveSimulation.m # Main MATLAB file to execute
35
+
# Name of the MATLAB script that will handle the simulation. This script will process the input data and return the output.
36
+
file: InteractiveSimulation.m
37
+
38
+
# The inputs section defines the data that the simulation will receive to process.
35
39
inputs:
36
-
stream_source: "rabbitmq://streaming.inputs.sim123" # RabbitMQ stream for input data
40
+
# Specifies the RabbitMQ stream URL from which the simulation will receive telemetry data.
41
+
# This is the source for continuous stream data to be processed in the simulation.
# The outputs section defines the structure of the results that will be returned after processing the inputs.
37
45
outputs:
46
+
# Predicted values after the simulation process. These values represent the predicted next positions of the object.
38
47
predicted:
39
-
x_next: float # Next predicted X coordinate value
40
-
y_next: float # Next predicted Y coordinate value
48
+
# Predicted x-coordinate of the object in the next time step.
49
+
x_next: float
50
+
51
+
# Predicted y-coordinate of the object in the next time step.
52
+
y_next: float
53
+
54
+
# Miscellaneous data that could provide additional context or information about the simulation.
41
55
misc:
42
-
distance_from_origin: float # Calculated distance from origin point
43
-
timestamp: float # Simulation timestamp in epoch seconds
56
+
# The Euclidean distance from the origin (0, 0) to the current position of the object.
57
+
# This can be used to measure how far the object has moved from its starting point.
58
+
distance_from_origin: float
59
+
60
+
# The timestamp of the output data in epoch seconds. This helps to track when the output was generated.
61
+
timestamp: float # epoch seconds
44
62
```
45
63
46
-
Use the client `use_matlab_agent_interactive.py` with the CLI option `--api-payload` to specify the path to this YAML payload file and start the client.
64
+
> **Note:** The stream_source field in the inputs section is mandatory for interactive simulations. This parameter specifies the RabbitMQ stream from which the simulation will receive real-time input data, and it must be included for the simulation to function correctly.
65
+
66
+
## Simulation Steps and Flow
67
+
68
+
1. **Initialization**
69
+
70
+
- Initialize `SimulationWrapperInteractive` for TCP communication.
71
+
- Prepare to receive telemetry input.
72
+
73
+
2. **Main Loop (100 Steps)**
74
+
75
+
- Process telemetry frames from the Python client.
76
+
- Each frame must include: `t`, `x`, `y`, `vx`, `vy`.
77
+
78
+
3. **Frame Validation**
79
+
80
+
- Check for all required fields.
81
+
- If valid, compute next position using Euler method:
82
+
- `x_next = x + vx * dt`
83
+
- `y_next = y + vy * dt`
84
+
- `dt`is the time difference between current and previous `t`.
85
+
- If invalid, send error message.
86
+
87
+
4. **Output**
88
+
89
+
- Send predicted position and additional info (distance from origin, timestamp) to the client.
0 commit comments