Not getting /scan callbacks

I’m finishing up my Topics Quiz but can’t seem to get callbacks called for the LaserScan subscription. When I run my program I get an error something like

[topics_quiz_node-1] [WARN] [1666026534.440058881] [topics_quiz_node]: New publisher discovered on topic ‘/scan’, offering incompatible QoS. No messages will be sent to it. Last incompatible policy: RELIABILITY_QOS_POLICY

I’m ready to submit but cannot solve this problem. I guess that means I’m too stupid to use ROS2 to control my robot. HELP!

Hi Jovovich,
The warning seems to be about the QoS setting. When you initiate the subscriber by calling the function create_subscription, you need to specify the QoSProfile. Especially the subscriber’s QoSProfile reliability should be the same as that of the topics. You can check the topic’s QoSProfile with the command ros2 topic info <topic_name> -v. Try it out and double-check if the QoS reliability settings in your code match the topic’s QoSProfile.
Good luck!
Dingyi

Hi @jcocovich ,

@dysun is very much correct about the explanation, however, I would like to add some more information to make things easier for you to understand.

Like @dysun said, you must first check for the QoS profile the sensor uses to transport the data to the ROS2 system. Performing ros2 topic info <topic_name> -v will get you QoS info at the bottom. There you will notice something like BEST_EFFORT or RELIABLE for reliability setting. You must make note of that.

So you have two methods to get it working:
[YOU MUST USE ONLY ONE OF THEM - DO NOT USE BOTH TOGETHER]

  1. Make use of a global default QoS setting (use this within your class):

    // code statements
    auto sensor_qos = rclcpp::QoS(rclcpp::SensorDataQoS());
    scan_sub_ = this->create_subscription<sensor_msgs::msg::LaserScan>(
                "/scan", sensor_qos, 
                std::bind(&YourClassName::scan_callback, 
                          this, std::placeholders::_1));
    // code statements
    

    This is a modification from what is mentioned in this link: Exploring ROS2 with wheeled robot - #2 - How to subscribe to ROS2 laser scan topic - The Construct

  2. Setting proper QoS profile with message queue (use this within your class):
    [BETTER OPTION]

    #include <rclcpp/qos.hpp>
    #include <rmw/qos_profiles.h>
    
    // code statements
    auto sensor_qos = rclcpp::QoS(rclcpp::KeepLast(10), 
                                  rmw_qos_profile_sensor_data);
    scan_sub_ = this->create_subscription<sensor_msgs::msg::LaserScan>(
                "/scan", sensor_qos, 
                std::bind(&YourClassName::scan_callback, 
                          this, std::placeholders::_1));
    // code statements
    

    This is taken as-is from what is mentioned in this link: What is best practice for setting a QoS profile in a rclcpp publisher or subscriber? - ROS Answers: Open Source Q&A Forum

I went through the same problem as you did when I was doing the same course, I did a lot of Google-ing to figure out this answer. I would recommend you to Google these first before starting a post here.

Hope my answer helps you understand ROS2 with C++ better!

Best Regards,
Girish

!++++++++++++++++++++++++++++++++++++++++++++++++++!
Also for reference:
https://docs.ros.org/en/galactic/Concepts/About-Quality-of-Service-Settings.html
https://docs.ros2.org/galactic/api/rclcpp/
https://docs.ros2.org/galactic/api/rclcpp/classrclcpp_1_1Node.html#a82f97ad29e3d54c91f6ef3265a8636d1
https://docs.ros2.org/galactic/api/rclcpp/classrclcpp_1_1QoS.html

!++++++++++++++++++++++++++++++++++++++++++++++++++!

WOW! Thanks for your feedback. The VERY bad taste in my mouth over this so-called Topics Quiz is a result of not actually LEARNING anything except how to Google search for answers. My wife’s students do that to be lazy.
That was a HORRIBLE example for beginner students and forces me to question the validity of my subscription. I can do this on my own FREE albeit no fancy certificate. I’m disappointed and sorry I bothered anyone.

@jcocovich ,

Wow! I am not sure how to react to that ! I am glad that you found my answer helpful !

I hope I did not say anything in a harsh tone for you to get into such a thought (perhaps demotivation (?)).

This website is actually wonderful and I believe that you would not learn effectively if you had to learn all these yourself at your own pace! I am actually very thankful that I have this course website. Coursera or EdX does not have a curriculum for ROS2 at the moment, that is what makes this website special.

Also the fact that ROS2 is still in migratory / nascent stages (I believe). People are still porting from ROS1 to ROS2 and thus no immediate answers pop up on Google when you make a search. It takes time and some skill / technique to actually find the correct link on Google.

I am sure the subscription and the certificate you receive will be worth your time and effort !

Also, I have completed that course fully. You can always ask your questions here if you cannot find immediate answers. I ( / We the community) are here to help you out (although not immediately) !

Best Regards,
Girish

PS: Also, please mark the post as solution, so that this issue is marked as solved !

My suggestion is merely a hint #5:

“You might have to be concerned with the subscription to the range topic using LaserScan messages. QoS may have to be addressed.”

I would have immediately responded by going into Google search mode as you so patiently recommended. I was disappointed in the fact the entire Unit was riddled with helpful hints you had to recognize but that’s what I enjoyed except the all important Topics Quiz fell one hint short for me.

I am now receiving and reporting on callback data so I can finish with my avoidance logic.

Joe

Oh I see! The test is to figger out why my laser scan feedback don’t see the freaking sphere but the wall beyond it. Clever! Now I need to experiment and Google search “sphere not recognized”. I’m off a searching.

Well… I am sure you will find your search results to be delightful just as how elated I found your responses were !

Regards,
Girish

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.