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 printspublisher: 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.