ROS toolbox stuck on service call

조회 수: 6 (최근 30일)
Kyösti Alkio
Kyösti Alkio 2022년 8월 10일
댓글: Kyösti Alkio 2022년 8월 11일
I'm trying to make a service call from MATLAB to a ros service. The node with the service works from other nodes and from the command line, but when I try to call it from MATLAB, I never get a response. The same happens to all services I have tried when calling them from MATLAB. I'm using ros2 with the following code:
classdef Test < handle
%TEST Summary of this class goes here
% Detailed explanation goes here
properties
node
client
end
methods
function obj = Test()
%TEST Construct an instance of this class
% Detailed explanation goes here
obj.node = ros2node("api2");
obj.client = ros2svcclient(obj.node, "/planner/clear_state", "mtms_interfaces/ClearState");
end
function out = call_service(obj)
msg = ros2message(obj.client);
disp(msg);
[response,status,statustext] = call(obj.client, msg);
disp(response);
disp(status);
disp(statustext);
out = res;
end
end
end
To call the service, I simply do
>> t = Test()
t =
Test with properties:
node: [1×1 ros2node]
client: [1×1 ros2svcclient]
>> t.call_service()
MessageType: 'mtms_interfaces/ClearStateRequest'
but as you can see, I get stuck on the service call. The service call never finishes. The ROS service receives the message and sends it back but MATLAB code's service call never finishes. The ClearState srv is simply as follows:
# ROS service for clearing state.
---
bool success
Is there something I'm doing wrong? I'm using Ubuntu 20.04.4.

채택된 답변

Josh Chen
Josh Chen 2022년 8월 10일
Hi Kyösti,
The code looks correct for me except "res" should probably be "response". But I don't think that is the culprit.
I wonder if there is any network setup issue that's preventing this code from working properly. It is always recommanded to make sure the service server is visiableand available from client side before using the "call" method. Coud you run the following code on the same MATLAB session and see if the "connectionStatus" is true?
>> myNode = ros2node("api2");
>> myClient = ros2svcclient(myNode,'/test','test_msgs/BasicTypes');
>> [connectionStatus,connectionStatustext] = waitForServer(myClient)
As an alternative, you may also try:
>> isServerAvailable(myClient)
If everyting above is working fine, I am suspecting this is an issue caused by ROS version difference or DomainID difference. Which distribution of MATLAB and ROS are you using in your environment? This page listed out supported ROS distributions for different MATLAB releases.
Hope this helps,
Josh
  댓글 수: 3
Josh Chen
Josh Chen 2022년 8월 10일
편집: Josh Chen 2022년 8월 10일
Hi,
Thanks for providing this additional information.
As for now, ROS Toolbox does not support communication with ROS2 Galactic. Different DDS implementation (MATLAB R2022a uses fastrtps, while ROS Galactic uses cyclonedds) underneath cause this invisible issue.
As a workaround, please consider one of the following two solutions:
  1. Follow the steps listed here to use Foxy in MATLAB with Cyclone DDS, and keep using Cyclone DDS with Galactic
  2. Run the following command before launching the server to use fastrtps on ROS 2 Galactic to make it discoverable by MATLAB ROS Toolbox
$ export RMW_IMPLEMENTATION="rmw_fastrtps_cpp"
-Josh
Kyösti Alkio
Kyösti Alkio 2022년 8월 11일
Thank you, this solved the problem! I used option 1:
setenv("RMW_IMPLEMENTATION","rmw_cyclonedds_cpp")

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Network Connection and Exploration에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by