0
$\begingroup$

Rosanswers logo

I am trying to simply subscribe to /scan topic after launching turtlebot3_world.py launch file in turtlebot3_gazebo pkg. For that I am creating a ros2 node which subscribes to /scan topic and logs it into the console.

Thanks in advance!

UPDATE:

/scan works from terminal using ros2 topic echo /scan but when run my pkg it simple not calling the callback function. This is how my subscriber class looks like.

class ScanPrinter:public rclcpp::Node{
public:

ScanPrinter():Node("scan_printer"){
    sub_ = this->create_subscription<sensor_msgs::msg::LaserScan>(
    "scan",
    rclcpp::QoS(rclcpp::KeepLast(10)),
    std::bind(&ScanPrinter::LaserCallback, this, std::placeholders::_1)
    );
}

private:
void LaserCallback(const sensor_msgs::msg::LaserScan::SharedPtr msg){
    RCLCPP_INFO(this->get_logger(), std::to_string(msg->ranges[90]).c_str());
}
rclcpp::Subscription<sensor_msgs::msg::LaserScan>::SharedPtr sub_;
};
  • Operating System:
    • Ubuntu 18.04
  • Version or commit hash:
    • Compiled from github <!-- from source: output of `git -C navigation2 rev-parse HEAD apt binaries: output of: dpkg-query --show "ros-$ROS_DISTRO-navigation2" or: dpkg-query --show "ros-$ROS_DISTRO-nav2-*" -->
  • DDS implementation:
    • Default

Steps I do in order

  • export TURTLEBOT3_MODEL=burger

  • export GAZEBO_MODEL_PATH=$GAZEBO_MODEL_PATH:<PATH/TO/MODELS>

  • I launch the turtlebot3_world.launch.py file which opens up the gazebo with the spawned turtle bot.

  • I try to run my subscriber node and it prints nothing on the console log, as it suppose to according to the LaseCallback function. By which I deduce that its not calling the call back function.

  • Then I tried ros2 topic echo /scan and it prints the message correctly.

  • Then I tried to see if my subscribers has really subscribed this topic by ros2 topic info /scan and then it prints publisher: 1, subscriber 1 by which I deduce it does.

  • Then I tried to subscribe custom string publisher by making necessary changes in the code, and it behaves perfectly.

I don't know what is wrong here.


Originally posted by shivaang12 on ROS Answers with karma: 61 on 2019-10-05

Post score: 1


Original comments

Comment by gvdhoorn on 2019-10-06:
It's unlikely members here will analyse your complete package for you -- especially if you just post a link here. We don't run a debugging service here.

Please provide some excerpts of your code, especially the parts having to do with creating subscribers, an overview of the topics that do exist, a description of how you start everything (also: in what order), versions of things like Fast-RTPS (or any other DDS implementation you are using), etc, etc.

Comment by shivaang12 on 2019-10-06:
Sorry, I couldn't figured out earlier how to post code, which is why I provided the link. But I made the necessary changes as per you suggestion.

$\endgroup$

2 Answers 2

1
$\begingroup$

Rosanswers logo

You can also take a look at the Dolly demo for Gazebo (https://github.com/chapulina/dolly). They are using rclcpp::QoS(rclcpp::SystemDefaultsQoS()).


Originally posted by greggScutum with karma: 21 on 2019-12-03

This answer was NOT ACCEPTED on the original site

Post score: 2

$\endgroup$
0
$\begingroup$

Rosanswers logo

I made it work at the end. The /scan topic publishes the data with Sensor QoS profile, qos_profile_sensor_data. So it is mandatory to use qos_profile_sensor_data QoS profile in the subscriber.


Originally posted by shivaang12 with karma: 61 on 2019-10-08

This answer was NOT ACCEPTED on the original site

Post score: 3


Original comments

Comment by zmk5 on 2019-10-15:
This worked for me! Thank you!

For those that need help with this in python it should be: rclpy.qos.qos_profile_sensor_data

For C++, it should be: rmw_qos_profile_sensor_data

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.