Skip to content

Comments

Matlab Agent New Use Case - Trajectory planning of a Robotic Arm#33

Merged
prasadtalasila merged 14 commits intoINTO-CPS-Association:mainfrom
marcomelloni:matlab-agent-use-case
Dec 19, 2025
Merged

Matlab Agent New Use Case - Trajectory planning of a Robotic Arm#33
prasadtalasila merged 14 commits intoINTO-CPS-Association:mainfrom
marcomelloni:matlab-agent-use-case

Conversation

@marcomelloni
Copy link
Collaborator

@marcomelloni marcomelloni commented Oct 25, 2025

This pull request introduces a new example for joint space control and quintic trajectory tracking for a Universal Robots UR10e robotic arm in MATLAB. It includes a full simulation script, a helper function for quintic polynomial fitting, updated documentation, and an example API YAML. Additionally, there are improvements to the MATLAB simulator's Python integration and its associated unit tests to better handle output processing and empty output lists.

MATLAB Robotic Arm Trajectory Planning Example:

  • Added a comprehensive README (README.md) describing the quintic trajectory tracking approach, control law, input/output parameters, visualization options, and troubleshooting tips for the UR10e robotic arm simulation.
  • Implemented the main simulation script (simulation.m) for trajectory generation, proportional control with velocity feedforward, data logging, and visualization of robot motion and tracking error.
  • Added the helper function (polynomialfit.m) to compute quintic polynomial coefficients for smooth joint trajectories with boundary conditions for position, velocity, and acceleration.
  • Provided an example API YAML (api/simulation.yaml.example) for batch simulation requests, specifying input and output formats.

Python Integration and Testing Improvements:

  • Enhanced the output processing logic in the MATLAB simulator Python backend (matlab_simulator.py) to robustly handle MATLAB results as dicts, lists, tuples, and single values, and to generate default output names when none are provided.
  • Updated the unit test (test_matlab_simulator.py) to verify correct handling of empty output lists, ensuring the simulator returns outputs with default names and matches expected values.
Registrazione.schermo.2025-10-26.alle.00.02.56.mov

@codecov
Copy link

codecov bot commented Oct 25, 2025

Codecov Report

❌ Patch coverage is 71.42857% with 14 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (main@0fa417b). Learn more about missing BASE report.

Files with missing lines Patch % Lines
...s/matlab/matlab_agent/src/core/matlab_simulator.py 62.85% 13 Missing ⚠️
agents/matlab/matlab_agent/__version__.py 0.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main      #33   +/-   ##
=======================================
  Coverage        ?   90.31%           
=======================================
  Files           ?       35           
  Lines           ?     3540           
  Branches        ?        0           
=======================================
  Hits            ?     3197           
  Misses          ?      343           
  Partials        ?        0           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

@prasadtalasila prasadtalasila left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@marcomelloni Thanks for the PR. Please see the suggestions. In addition, the following changes are suggested.

  1. The docs/examples directory has templates for batch and streaming simulations. The template for interactive simulation is missing. Please make a copy and add .template extension.
  2. In the README.md of the example, please add the instructions to run the example.
  3. When the simulation is run, the following error occurs.
matlab-agent --config-file .\config.yaml
2025-10-28 22:06:49 - MATLAB-AGENT - INFO - Initializing MATLAB agent with ID: matlab
2025-10-28 22:06:49 - MATLAB-AGENT - INFO - Configuration validated successfully.
2025-10-28 22:06:49 - MATLAB-AGENT - INFO - Initializing RabbitMQ broker
2025-10-28 22:06:50 - MATLAB-AGENT - INFO - MATLAB agent running and listening for requests
2025-10-28 22:14:53 - MATLAB-AGENT - INFO - Received simulation type: batch
2025-10-28 22:14:53 - MATLAB-AGENT - INFO - Starting simulation 'simulation.m'

=== [DEBUG] Inputs received by the simulation ===
qs (start pose):
   -1.5708   -1.2500    1.2500    3.1000   -0.0010   -3.1000

qg (goal pose):
    1.5708   -1.2000    1.2000         0    0.0010         0

tf (duration): true
ts (time step): 0.005
showGui: 5
===============================================

Error using simulation
Expected tf to be one of these types:

double, single, uint8, uint16, uint32, uint64, int8, int16, int32, int64

Instead its type was logical.

Error in simulation (line 36)
    validateattributes(tf, {'numeric'}, {'scalar','real','finite','>',0}, mfilename, 'tf');
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

2025-10-28 22:15:21 - MATLAB-AGENT - ERROR - Simulation error:
  File C:\Users\foo\git\simulation-bridge\agents\matlab\matlab_agent\docs\examples\trajectory-planning-robotic-arm\simulation.m, line 36, in simulation
Expected tf to be one of these types:

double, single, uint8, uint16, uint32, uint64, int8, int16, int32, int64

Instead its type was logical.

Traceback (most recent call last):
  File "C:\Users\foo\git\simulation-bridge\agents\matlab\.venv\Lib\site-packages\matlab_agent\src\core\matlab_simulator.py", line 99, in run
    result: Union[Any, Tuple[Any, ...]] = self.eng.feval(
                                          ^^^^^^^^^^^^^^^
  File "C:\Users\foo\git\simulation-bridge\agents\matlab\.venv\Lib\site-packages\matlab\engine\matlabengine.py", line 71, in __call__
    _stderr, feval=True).result()
                         ^^^^^^^^
  File "C:\Users\foo\git\simulation-bridge\agents\matlab\.venv\Lib\site-packages\matlab\engine\futureresult.py", line 62, in result
    return self.__future.result(timeout)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\foo\git\simulation-bridge\agents\matlab\.venv\Lib\site-packages\matlab\engine\fevalfuture.py", line 76, in result
    self._result = pythonengine.getFEvalResult(self._future,self._nargout, None, out=self._out, err=self._err)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
matlab.engine.MatlabExecutionError:
  File C:\Users\foo\git\simulation-bridge\agents\matlab\matlab_agent\docs\examples\trajectory-planning-robotic-arm\simulation.m, line 36, in simulation
Expected tf to be one of these types:

double, single, uint8, uint16, uint32, uint64, int8, int16, int32, int64

Instead its type was logical.
python .\use_matlab_agent_batch.py
[DT] Infrastructure ready.
[DT] Infrastructure ready.
[DT] Request sent → MATLAB (routing key dt.matlab).

Press Ctrl+C to exit manually…
[DT] Waiting for results (binding key 'matlab.result.dt')…

[DT] Result received:
{'bridge_meta': 'unknown', 'destinations': ['dt'], 'error': {'code': 500, 'details': 'InteractiveSimulation.m', 'message': 'Error processing message', 'type': 'execution_error'}, 'request_id': 'unknown', 'simulation': {'name': '', 'type': ''}, 'source': 'matlab', 'status': 'error', 'timestamp': '2025-10-28T22:06:39Z'}
----------------------------------------

[DT] Result received:
{'bridge_meta': {'protocol': 'rabbitmq'}, 'destinations': ['dt'], 'progress': {'percentage': 0}, 'request_id': 'abcdef12345', 'simulation': {'name': 'simulation.m', 'type': 'batch'}, 'source': 'matlab', 'status': 'in_progress', 'timestamp': '2025-10-28T22:14:53Z'}
----------------------------------------

[DT] Result received:
{'bridge_meta': {'protocol': 'rabbitmq'}, 'destinations': ['dt'], 'progress': {'percentage': 50}, 'request_id': 'abcdef12345', 'simulation': {'name': 'simulation.m', 'type': 'batch'}, 'source': 'matlab', 'status': 'in_progress', 'timestamp': '2025-10-28T22:15:15Z'}
----------------------------------------

[DT] Result received:
{'bridge_meta': 'unknown', 'destinations': ['dt'], 'error': {'code': 500, 'message': 'Simulation error: \n  File C:\\Users\\foo\\git\\simulation-bridge\\agents\\matlab\\matlab_agent\\docs\\examples\\trajectory-planning-robotic-arm\\simulation.m, line 36, in simulation\nExpected tf to be one of these types:\n\ndouble, single, uint8, uint16, uint32, uint64, int8, int16, int32, int64\n\nInstead its type was logical.\n', 'type': 'execution_error'}, 'request_id': 'unknown', 'simulation': {'name': 'simulation.m', 'type': 'batch'}, 'source': 'matlab', 'status': 'error', 'timestamp': '2025-10-28T22:15:21Z'}
----------------------------------------

timestamp: "2024-01-01T00:00:00Z"
timeout: 60
inputs:
qs: [1.5708, -1.2000, 1.2000, 0.0000, 0.0010, 0.0000]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an list type input. Is this the major change? The PR description hints at it. Just want to be sure. Also is this type supported for outputs as well?
Also simul8 agent supports list type in inputs and outputs. Call you please check to make sure that the implementation is consistent?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.
The main change in this new use case is the ability to declare and show list-type inputs. In the new YAML example (api/simulation.yaml.example, line 10), qs and qg are arrays of six values. The MATLAB pipeline already supports this: input dictionaries are now ordered by function signature, and any list is converted to matlab.double before execution (matlab_simulator.py, lines 96 and 135).
Outputs are unaffected, _process_results already converts any MATLAB vector or matrix into standard Python lists before returning them (matlab_simulator.py, line 113).
The Simul8 agent is consistent: its configuration examples use lists for rows and columns (simulation_batch.yaml.example, line 7), these are validated as Python arrays and serialized to CSV, and outputs are mapped back as dictionaries, supporting list values when present (simul8_simulator.py, line 296).

Rasmus-M-C and others added 3 commits November 1, 2025 18:28
Adds dedicated agent for Simul8 software. This agent supports
only batch mode simulation and works only on Windows.
The code also contains one example.

---------
Co-authored-by: Marco Melloni <adddministro@gmail.com>
Co-authored-by: prasadtalasila <prasadtalasila@users.noreply.github.com>
@marcomelloni
Copy link
Collaborator Author

marcomelloni commented Nov 1, 2025

Hi @prasadtalasila , thanks for the suggestions. Please find my considerations below:

The crash was caused by the MATLAB agent relying on the YAML key order to determine the argument order.
Some clients serialized the inputs with swapped keys, causing tf to be passed in place of showGui, which triggered a type error.
To fix this, I added the _parse_function_inputs() function in matlab_simulator.py.
This function reads the MATLAB simulation file and extracts the input argument names from the function signature.
It ensures that input parameters are passed in the correct order automatically.
From now on, we don’t need to manually respect the exact input order,the MATLAB agent will handle the mapping internally.

I’ve also translated all comments into English and verified that list-type input/output handling is consistent with the Simul8 agent.

There is a folder: .vscode.
i suggest to remove it, i think it shouldn’t be in the main repository since it's simul8-specific.

@marcomelloni
Copy link
Collaborator Author

I’ve checked the Matlab agent code and didn't find any issues. I only made a modification to the client source code to prevent the key parameters from being sorted. Could you please try it now? It works on my PC.

@sonarqubecloud
Copy link

@prasadtalasila prasadtalasila merged commit 0fd4d4d into INTO-CPS-Association:main Dec 19, 2025
6 checks passed
@marcomelloni marcomelloni deleted the matlab-agent-use-case branch December 19, 2025 21:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants