Problems with ROS service client in MATLAB
8 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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
0 Commenti
Risposte (2)
Cam Salzberger
il 28 Mag 2021
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
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!