ROS toolbox stuck on service call

6 visualizzazioni (ultimi 30 giorni)
Kyösti Alkio
Kyösti Alkio il 10 Ago 2022
Commentato: Kyösti Alkio il 11 Ago 2022
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.

Risposta accettata

Josh Chen
Josh Chen il 10 Ago 2022
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 Commenti
Josh Chen
Josh Chen il 10 Ago 2022
Modificato: Josh Chen il 10 Ago 2022
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 il 11 Ago 2022
Thank you, this solved the problem! I used option 1:
setenv("RMW_IMPLEMENTATION","rmw_cyclonedds_cpp")

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Network Connection and Exploration in Help Center e File Exchange

Prodotti


Release

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by