Receive data from ros2 /scan topic does not work, while it is possible for /odom and /cmd_vel topic
Show older comments
- 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 Comments
Cam Salzberger
on 11 Mar 2021
The lack of messages showing from "ros2 msg list" is odd, to say the least. That command doesn't even use the network, it just checks available message definitions.
Can you check if you have an environment variable defined in MATLAB that may be throwing things off slightly?
getenv('AMENT_PREFIX_PATH')
It may also be worth restarting MATLAB and seeing if the problem persists. Some parts of the message list get cached within a session (to improve performance). If that cache got corrupted somehow, that could be giving you that result.
-Cam
Bernd Schmidt
on 11 Mar 2021
Cam Salzberger
on 12 Mar 2021
Hmm, just to rule it out as a possible issue, can you try restarting MATLAB (or start a new session) and running this before anything else:
setenv('AMENT_PREFIX_PATH','')
ros2('msg', 'list')
-Cam
Bernd Schmidt
on 12 Mar 2021
Cam Salzberger
on 15 Mar 2021
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
Accepted Answer
More Answers (0)
Categories
Find more on Get Started with ROS Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!