Skip to content

Matlab Emio Communicaiton - #38

Open
AlessandriniAntoine wants to merge 14 commits into
SofaComplianceRobotics:mainfrom
AlessandriniAntoine:main
Open

Matlab Emio Communicaiton#38
AlessandriniAntoine wants to merge 14 commits into
SofaComplianceRobotics:mainfrom
AlessandriniAntoine:main

Conversation

@AlessandriniAntoine

Copy link
Copy Markdown
Contributor

adds a Matlab/Simulink TP extensions to _depthcamera.py required to support it.

Changes to _depthcamera.py

  • Raw camera coordinates: added access to unprocessed tracker coordinates from the camera frame, used for the front-facing camera mode without noise introduced by post-processing.
  • Frame split: separated get_frame() and process_frame() into two distinct calls, allowing synchronization via multiprocessing events between the camera and motor control processes.

New: examples/matlab/

A complete Python/Simulink bridge for a compliant robotics TP:

  • UDP communication between Python and Simulink (clock-master pattern)
  • Python multiprocessing work:
    • Camera-based marker tracking (top and front modes)
    • Motor control loop synchronized with the camera process
    • Configurable via a single params.py file
  • Includes a hardware-free test script

@HanaeRateau

HanaeRateau commented May 11, 2026

Copy link
Copy Markdown
Collaborator

We won't merge this PR but we will integrate the UDP server #39, and we created a repo with a minimal the matlab example https://github.com/SofaComplianceRobotics/MatlabxEmio.
We will also created another repo with a the full matlab.

Copilot AI lite review requested due to automatic review settings August 11, 2026 11:40

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adds a Matlab/Simulink-oriented Python bridge and extends the camera stack to support raw image-frame tracker coordinates and a split acquisition/processing workflow (to enable inter-process synchronization).

Changes:

  • Introduces examples/matlab/ with a UDP bridge, multiprocessing camera/motor processes, configuration, and a hardware-free test loop.
  • Extends DepthCamera / EmioCamera with get_frame() + process_frame() separation and exposes raw tracker pixel coordinates (trackers_pos_image).
  • Adds a plane-intersection helper in position estimation and updates .gitignore for MATLAB/Simulink artifacts.

Reviewed changes

Copilot reviewed 16 out of 63 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
examples/matlab/udp_bridge.py UDP clock-master bridge with handshake, timeout/desync handling, and reconnection logic
examples/matlab/main.py Spawns camera + motor processes and wires shared memory + events
examples/matlab/camera.py Camera process + marker extraction modes (top/front/plan) feeding shared memory
examples/matlab/process_motor.py Motor process synchronized to camera ticks and bridged to Simulink via UDP
examples/matlab/test.py Hardware-free loop to validate UDP bridge against a remote model
examples/matlab/params.py Central configuration for example scripts (fps, UDP ports, camera settings)
examples/matlab/README.md Usage/config docs and Simulink UDP block settings
examples/matlab/launch_python.m MATLAB helper to launch the Python test loop in a terminal
emioapi/_depthcamera.py Splits acquisition vs processing, stores depth rs-frame for point cloud, adds trackers_pos_image
emioapi/emiocamera.py Exposes trackers_pos_image and splits update() into get_frame() + process_frame()
emioapi/_positionestimation.py Adds camera-ray to plane intersection helper (used by "plan" mode)
examples/matlab/Jacobian/slprj/sim/varcache/jacobian/tmwinternal/simulink_cache.xml Generated Simulink cache artifact added to repo
examples/matlab/Pendulum/State_Space/slprj/sim/varcache/transfert_function/tmwinternal/simulink_cache.xml Generated Simulink cache artifact added to repo
examples/matlab/Pendulum/State_Space/slprj/sim/varcache/state_space/tmwinternal/simulink_cache.xml Generated Simulink cache artifact added to repo
examples/matlab/Pendulum/slprj/sim/varcache/transfert_function/tmwinternal/simulink_cache.xml Generated Simulink cache artifact added to repo
examples/matlab/Pendulum/slprj/sim/varcache/state_space/tmwinternal/simulink_cache.xml Generated Simulink cache artifact added to repo
.gitignore Ignores MATLAB/Simulink build/cache outputs (*.slxc, slprj/)

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +365 to +373
ray_world = self.camera_image_to_simulation(x, y, 1.0) - self.t
camera_pos_world = self.t
denom = plane_n.dot(ray_world)

if abs(denom) < 1e-6:
raise ValueError("Ray is parallel to the plane")
s = - (plane_n.dot(camera_pos_world) + plane_d) / denom
result = camera_pos_world + s * ray_world
return [result[0], result[1], result[2]]
Comment thread examples/matlab/camera.py
Comment on lines +96 to +99
if side == "top":
pos = np.array(camera.trackers_pos).reshape(nb_markers, 3).copy()
pos = pos.astype(np.float64)
return pos
Comment thread examples/matlab/camera.py
Comment on lines +110 to +113
for pixel_pos in camera.trackers_pos_image:
result = camera._camera.position_estimator.camera_image_to_simulation_plane_intersection(
pixel_pos[0],pixel_pos[1],prm.plane_n, prm.plane_d)
trackers_projected.append(result)
Comment on lines +1 to +6
<?xml version="1.0" encoding="UTF-8"?>
<MF0 version="1.1" packageUris="http://schema.mathworks.com/mf0/SlCache/19700101">
<slcache.FileAttributes type="slcache.FileAttributes" uuid="c7637f53-da09-4dd7-b4b0-a3ccfd495eec">
<checksum>1CdfPOZQp2C+bnxfUmNTWYKBUzHQfJ90D+MY45thlKRqvvnRI62WZl9tmrGU0JViLHXTLzVjsSVsQ0wLJGdTBg==</checksum>
</slcache.FileAttributes>
</MF0> No newline at end of file
Comment on lines +1 to +6
<?xml version="1.0" encoding="UTF-8"?>
<MF0 version="1.1" packageUris="http://schema.mathworks.com/mf0/SlCache/19700101">
<slcache.FileAttributes type="slcache.FileAttributes" uuid="94ca11ee-1535-4f1a-8c9e-419ec7eeb144">
<checksum>8qJKTnJiuTH/aGZ17KapfN6U09KZubf0XO7c/dUNBkw9N4OlINRVduUJFv6DJp0w1M4iZSujGkrAS9Osjaccsg==</checksum>
</slcache.FileAttributes>
</MF0> No newline at end of file
Comment on lines +1 to +6
<?xml version="1.0" encoding="UTF-8"?>
<MF0 version="1.1" packageUris="http://schema.mathworks.com/mf0/SlCache/19700101">
<slcache.FileAttributes type="slcache.FileAttributes" uuid="ea97faf6-8f70-4221-8aad-4ed8c5c25ada">
<checksum>BNqY+xVWfqSfLgDHRoG8onrCNVcJaarE3f9pwALr1FtPC49Ts5/QI6qtSOJzrdX6Y0XNSVxKzDUzQWhcZV9oeg==</checksum>
</slcache.FileAttributes>
</MF0> No newline at end of file
Comment on lines +1 to +6
<?xml version="1.0" encoding="UTF-8"?>
<MF0 version="1.1" packageUris="http://schema.mathworks.com/mf0/SlCache/19700101">
<slcache.FileAttributes type="slcache.FileAttributes" uuid="4fd59ba0-7a75-48fa-bb5a-0c08c968adfb">
<checksum>Jhh57wFTTsQB2/9iEyLWm46mwsyh3k2LeYZUtDgDoq3gtr3lhWAK3ItB18HMcTAJmdHu9K913ax+7uvnLohxrg==</checksum>
</slcache.FileAttributes>
</MF0> No newline at end of file
Comment on lines +1 to +6
<?xml version="1.0" encoding="UTF-8"?>
<MF0 version="1.1" packageUris="http://schema.mathworks.com/mf0/SlCache/19700101">
<slcache.FileAttributes type="slcache.FileAttributes" uuid="10d569cb-de26-461b-ac1b-e88403b0a43b">
<checksum>Q83cycAKxswSGwblyt++9jH3boxpVi8p2pBf1zOSA9IdIK5zWmpZikphj/Ycn+E0fwdAmgo4ZB9GeXJsAe985w==</checksum>
</slcache.FileAttributes>
</MF0> No newline at end of file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants