Receive data from ros2 /scan topic does not work, while it is possible for /odom and /cmd_vel topic
42 ビュー (過去 30 日間)
古いコメントを表示
- A Simulink model according to the tutorial here was created. The Virtual Machine provided by Matlab for Dashing and Gazebo (where the ROS bridge is used for ROS2 interaction) was used to successfully extract the Turtlebot3 /scan and /odom topics from the Gazebo simulation to build a 2D map.
2. The same Simulink model was used with a real Turtlebot3 with Ubuntu 18.04.3 preinstalled server as sbc operating system. Strangely, the /odom data is available,
but no /scan data can be measured (all scan.signal.values are 0).
3. The behavior from 2. can be confirmed with a Gazebo simulation with a fresh installation on a host PC with
- Ubuntu 18.04 LTS
- Dashing Diademata for ROS2
- Matlab 2020b
The following test were executed with the described setting from 3. For easier testing basic ROS2 Matlab commands were used.
Preparation of further investigations
Gazebo und keyboard teleoperation were started:
$ ros2 launch turtlebot3_gazebo turtlebot3_world.launch.py
$ ros2 run turtlebot3_teleop teleop_keyboard
Connection between Matlab and Ubuntu host is working:
>> ros2 topic list -t
Topic MessageType
_______________________ _________________________________
{'/camera/camera_info'} {'sensor_msgs/CameraInfo' }
{'/camera/image_raw' } {'sensor_msgs/Image' }
{'/clock' } {'rosgraph_msgs/Clock' }
{'/cmd_vel' } {'geometry_msgs/Twist' }
{'/imu' } {'sensor_msgs/Imu' }
{'/joint_states' } {'sensor_msgs/JointState' }
{'/odom' } {'nav_msgs/Odometry' }
{'/parameter_events' } {'rcl_interfaces/ParameterEvent'}
{'/robot_description' } {'std_msgs/String' }
{'/rosout' } {'rcl_interfaces/Log' }
{'/scan' } {'sensor_msgs/LaserScan' }
{'/tf' } {'tf2_msgs/TFMessage' }
{'/tf_static' } {'tf2_msgs/TFMessage' }
Error message
To get the laser scan data the following commands are used:
detectNode = ros2node("/tb3_scan");
pause(2)
laserSub = ros2subscriber(detectNode,"/scan");
pause(2)
scanData = receive(laserSub,10);
which leads to the error message
Error using ros2subscriber/receive (line 458)
Subscriber did not receive any messages and timed out.
On the Ubuntu host,
$ ros2 topic echo scan
outputs the laser scan data to the gnome-terminal: the data seems to be available.
Further tests
- Test with /odom:
detectNodeOdom = ros2node("/tb3_odom");
pause(2)
odomSub = ros2subscriber(detectNodeOdom,"/odom");
pause(2)
odomData = receive(odomSub,10);
No error message, odomData is available in the workspace.
2. Test with /cmd_vel provides same result as with /odom under 1. (data available in workspace).
3. The command
>> ros2 msg list
shows no messages.
The same command shows loads of messages in the gnome-terminal.
Any help is appreciated.
5 件のコメント
Cam Salzberger
2021 年 3 月 15 日
Thanks for letting me know. I'll look into what is going on with it, but this is probably a good workaround for now.
-Cam
採用された回答
Cam Salzberger
2021 年 3 月 11 日
編集済み: Cam Salzberger
2021 年 3 月 12 日
Hello Bernd,
There are two main culprits that I always look at first when there is difficulty communicating in ROS 2, but there is information about the topic, indicating some level of communication:
Quality of Service Setting Compatibility
There are certain combinations of QoS settings between publisher and subscriber that can result in them being unable to communicate. See explainations here and here. You can check the settings that the publisher and subscriber use by checking their properties (in MATLAB) or how it is created (outside of MATLAB).
Ensure that the settings are compatible according to the table in the first link.
Subnet/Extended-network
Check the IP addresses of the computers on both ends of the network. If they are in the same "subnet", then they should be able to communicate freely. Typically this means that the first three sequences in the IP addresses need to be the same, but the definition of the subnet may vary depending on your network mask.
If the computers are not in the same subnet, you need to extend your network. MATLAB uses the Fast-RTPS DDS back-end for ROS 2, so it needs a DEFAULT_FASTRTPS_PROFILES.xml file in the current directory to extend the network. This has to be done in a reciprocal manner, though, so the other machine needs the same file pointing to the MATLAB computer's IP. If the other machine also uses Fast-RTPS on the back-end (the default for Dashing), then the same file should suffice if it lists both IP addresses. I don't have experience with talking across different DDS implementations, but I assume there is a similar way to extend the network for other back-ends.
See here for an example profiles XML file. Make sure the domain ID is set correctly in the file. Any nodes will need to be deleted and recreated for changes to the profiles file to take effect.
Complete Lack of Communication
Just for completeness, I wanted to link to other fixes for issues when communication is not occurring at all. It's not necessarily applicable here, since the topic is visible from MATLAB though.
- General troubleshooting (causes and solutions)
- Incompatibility between versions of ROS 2
- Additional version incompatibility statement from OSRF
-Cam
4 件のコメント
Hossein Moghimi
2022 年 5 月 5 日
Hi,
I have a linux device on my network. The subnet of my PC and the linux device are the same. I set the domain ID of both to 5. When I create a node in either of them I can detect it in another. Likewise, I can do the same for topics. I have a basic publisher and subscriber, which work perfectly fine, when run in the linux device. When I run the publisher on the linux machine; although Matlab in my PC can detect both the publisher node and the topic, the Matlab "receive" function always timeout and does not recieve any messages. I trully appreciate if you can suggest something.
By the way I am running linux 18.04 with ROS2 Dashing. I tested this on both Matlab 2020b and 2021b with no luck.
Here is my Matlab Code:
clear all
clc
setenv("ROS_DOMAIN_ID","5");
ros2 topic list
topicList=ros2("topic","list");
if(sum(contains(topicList, "test_publisher_topic")))
SubscriberNode=ros2node("/matlab_subscriber", 5);
msgSub=ros2subscriber(SubscriberNode, "/test_publisher_topic" ,"std_msgs/String");
while(1)
Message=receive(msgSub, 5);
disp(Message)
end
else
disp('hossein_topic not present!')
end
ERROR Code:
Error using ros2subscriber/receive (line 458)
Subscriber did not receive any messages and timed out.
Thanks
Hossein
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!