Note: This page is not up to date!

Installation and prerequisites


Firstly, Matlab have to be installed correctly at the system. To check if Matlab is installed correctly type 'matlab' in terminal and if Matlab start it will be possible to use our nodes for ROS-Matlab interface. Otherwise follow Matlab installation .

Package clopema_matlab

If you used clopema ros_install file for packages installation type in terminal:

roscd clopema_matlab

otherwise you have to set rosws
rosws set clopema_matlab --git git@clopema.felk.cvut.cz:clopema_matlab.git
rosws update clopema_matlab
roscd clopema_matlab


All tutorials presented here assume that roscore and at least one matlab instance is started. To do it type following commands in terminal:
roslaunch clopema_matlab_tutorials basic_matlab.launch

In launch file two nodes are starting:
  • The call_matlab node provides service for executing Matlab commands from ROS. The number at the end of the command define number of Matlab instances which are running parallel - it can be change to any integer(>0) value but it can be computationally expensive.
    The second argument (string) specify additional search path for Matlab commands, the arguments contains packages names separated by semicolon. Only folders $ROS_WORKSPACE/package_name/matlab/* are added to search path.
    The following example will start one Matlab instance (in background) and paths $ROS_WORKSPACE/clopema_matlab/matlab/*, $ROS_WORKSPACE/package1/matlab/* and $ROS_WORKSPACE/package2/matlab/* will be added to Matlab search path.
    call_matlab 1 package1;package2
  • The call_from_matlab node provides services for access ROS data from matlab.

Launch file basic_matlab.launch:

<?xml version="1.0" encoding="UTF-8"?>
        <node name="clopema_matlab" pkg="clopema_matlab" type="call_matlab" args="2 clopema_matlab_tutorials" output="screen"/>
        <node name="call_from_matlab" pkg="clopema_matlab" type="call_from_mtlb.py" output="screen"/>

Executing Matlab commands from ROS

It is possible to execute any Matlab commands from ROS by calling service /clopema_matlab/call. Input and output are strings. Input string contains Matlab commands which will be executed in Matlab evalc function. The result of this function is included in output string. Note that clear all command is not supported, workspace is cleared automatically after execution is completed. Also there are two addition reserved words which you can not use for your variable names: voopFid_32154986 and voopT_32154986.

In terminal:

rosservice call /clopema_matlab/call_matlab 'sin(45)'

ans =


More commands at once:

rosservice call /clopema_matlab/call_matlab "A = sind(45);B = A*1.5;fprintf('%.2f',B);" 

res: 1.06


- Creating a ROS srv
- Writing a Simple Service in Matlab
- Writing a Simple Client in Matlab


- Simple Publisher
- Simple Subscriber


- Sending goal to the server

Matlab commands for ROS-Matlab communication

[req res] = rosClopemaCreateSrv(srv_type);                              % create service request and response with default values
msg = rosClopemaCreateMsg(msg_type);                                    % create message with default values
response = rosClopemaCallService(srv_name, request);                    % call service
rosClopemaPublishOnTopic(topic_name,msg_type,msg);                      % publish on topic
result = rosClopemaSendGoal(type, topic, goal, duration);               % send goal to actionLib server
ttime = rosClopemaGetTimeNow;                                           % return current ROS time
duration = rosClopemaGetDuration(5.0);                                  % create struct which represent duration type in ROS