Problems with ROS service client in MATLAB

8 ビュー (過去 30 日間)
Massimo Satler
Massimo Satler 2021 年 5 月 28 日
回答済み: Massimo Satler 2021 年 5 月 31 日
Hi everybody,
I'm having trouble trying to connect to an external (i.e. a ROS MASTER running outside the Matlab environment) ROS service server.
In particular, I am trying to connect to a mavros service server (mavros/cmd/takeoff) but I have several problems.
Being a custom message type, I followed the Matlab documentation to generate custom messages (rosgenmsg). Here I had a different generated directory structure, so I modified the path in the addpath command in the following way: ..matlab_msg_gen_ros1/glnxa64/install/m
Typing the command "rosmsg list", I can see all the generated custom messages. Fine!
Then I moved to the service client generation for the /mavros/cmd/takeoff server, as described in the documentation:
client = rossvcclient('/mavros/cmd/takeoff');
testreq = rosmessage(client);
response = call(testreq,'TimeOut',3);
I got the following error: "Failed to create a service client"
I investigated a lot the problem, but I am not being able to find a solution.
Can someone help me?
What am I doing wrong?
Additional information:
rosservice type /mavros/cmd/takeoff
=> mavros_msgs/CommandTOL
rosservice info /mavros/cmd/takeoff
=> initially doesn't work (error message: Unrecognized function or variable 'ros.internal.ros.messages.mavros_msgs.commandTOLRequest' )
I had to rename the generated custom_message folder in the following way:
original: ~./matlab_msg_gen_ros1/glnxa64/install/m/+ros/+internal/+ros/+custommessages/...
working: ~./matlab_msg_gen_ros1/glnxa64/install/m/+ros/+internal/+ros/+messages/...
Now it finds the function and provides the expected output:
Node: /mavros
URI: rospc://user-PC:43679
Type: mavros_msgs/CommandTOL
Args: MessageType MinPitch Yaw Latitude Longitude Altitude

回答 (2 件)

Cam Salzberger
Cam Salzberger 2021 年 5 月 28 日
Hello Massimo,
I attempted to reproduce this by taking this mavros_msgs/CommandTOL service defintiion. Fortunately it doesn't even need the whole package, since the service stands on its own, so it was a quick generation.
current_dir/
|-mavros_msgs/
|-srv/
|-CommandTOL.srv
And ran this code:
rosshutdown
rosgenmsg(pwd)
addpath('path\to\current_dir\matlab_msg_gen_ros1\win64\install\m')
clear classes
rehash toolboxcache
rosinit
s = rossvcserver('/mavros/cmd/takeoff', 'mavros_msgs/CommandTOL', @(~,~,r)r);
c = rossvcclient('/mavros/cmd/takeoff');
rosservice type /mavros/cmd/takeoff
rosservice info /mavros/cmd/takeoff
call(c)
It didn't have any issues. I also didn't have to edit the path to the struct definition file; "+custommessages" worked fine for me. I suspect that editing that is preventing the call command from working, if it is expecting +custommessages in the package. I'm not sure why your "rosservice" command was failing though. Can you provide the output of "ver" so I can see what update version of R2021a you are working with? There was an issue in the original release of R2020b that could be related, but it was fixed by R2021a.
Also, can you try shutting down (rosshutdown) and restarting (rosinit) ROS on MATLAB, and just communicating between a MATLAB server and client and see if that works, rather than your external server? One possibility is that the service definition may be different on your external system in comparison to MATLAB. It's worth checking that by running this on both MATLAB and your external system:
rosmsg md5 mavros_msgs/CommandTOLRequest
rosmsg md5 mavros_msgs/CommandTOLResponse
They must be the same to communicate.
-Cam
  2 件のコメント
Massimo Satler
Massimo Satler 2021 年 5 月 28 日
Hi Cam,
thank you so much for you replay and the provided support.
I will give a try communicating between service server and client inside Matlab environment, in the meantime this is the MATLAB version I am using:
-----------------------------------------------------------------------------------------------------
MATLAB Version: 9.10.0.1669831 (R2021a) Update 2
Operating System: Linux 5.8.0-53-generic #60~20.04.1-Ubuntu SMP Thu May 6 09:52:46 UTC 2021 x86_64
Java Version: Java 1.8.0_202-b08 with Oracle Corporation Java HotSpot(TM) 64-Bit Server VM mixed mode
-----------------------------------------------------------------------------------------------------
MATLAB Version 9.10 (R2021a)
Simulink Version 10.3 (R2021a)
5G Toolbox Version 2.2 (R2021a)
AUTOSAR Blockset Version 2.4 (R2021a)
Aerospace Blockset Version 5.0 (R2021a)
Aerospace Toolbox Version 4.0 (R2021a)
Antenna Toolbox Version 5.0 (R2021a)
Audio Toolbox Version 3.0 (R2021a)
....
I'll get back to you as soon as possible..
Best,
Massimo
Massimo Satler
Massimo Satler 2021 年 5 月 28 日
Hi, I have tested the communication between a service server and client inside MATLAB, it works.
Then I switched again to the communication with a service server running in a ROS environment and it didn't work. I tested other services but the resul didn't change.

サインインしてコメントする。


Massimo Satler
Massimo Satler 2021 年 5 月 31 日
Brief Update
I have switched to a Windows machine running Matlab2020b and I repeated all the required steps to firstly generate custom messages, then to create a client service to a ROS server service.
It works without any problems. I also didn't have to edit the path to the struct definition file as required in Linux.
So I guess in Linux there are some bugs in the ros.internal... functions.

カテゴリ

Help Center および File ExchangeROS Network Access in MATLAB についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by