NodeHandle::subscribe fail to subscribe topic
Hi, I'm new to ROS and C++ and doing Programming for Robotics ( http://www.rsl.ethz.ch/education-stud... ). My problem is "Create a subscriber to the /scan topic" in exercise2. Here is my code:
HuskyHighlevelController.Cpp File:
#include "husky_highlevel_controller/HuskyHighlevelController.hpp"
#include <std_msgs/String.h>
#include <ros/ros.h>
#include <sensor_msgs/LaserScan.h>
namespace husky_highlevel_controller {
HuskyHighlevelController::HuskyHighlevelController(ros::NodeHandle& nodeHandle) :
nodeHandle_(nodeHandle)
{
ros::Subscriber subscriber =
nodeHandle_.subscribe("scan",1000,&HuskyHighlevelController::ScanCallback,this);
ROS_INFO("Successfully launched node.");
}
HuskyHighlevelController::~HuskyHighlevelController()
{
}
void HuskyHighlevelController::ScanCallback(const sensor_msgs::LaserScan& msg)
{
ROS_INFO("Received");
}
}
husky_highlevel_controller_node.Cpp File:
#include <ros/ros.h>
#include "husky_highlevel_controller/HuskyHighlevelController.hpp"
int main(int argc, char** argv)
{
ros::init(argc, argv, "husky_highlevel_controller");
ros::NodeHandle nodeHandle("~");
husky_highlevel_controller::HuskyHighlevelController huskyHighlevelController(nodeHandle);
ros::spin();
return 0;
}
No problem with build but I launched husky_world.launch first then I ran this node (husky_highlevel_controller_node) and I checked the info of husky_highlevel_controller node and scan topic. Found No relationship between them (also rqt_console to check info message but receive nothing). I'm confused with
ros::Subscriber sub = handle.subscribe("my_topic", 1, &Foo::callback, &foo_object);
and
ros::Subscriber sub = handle.subscribe("my_topic", 1, callback);
From the ROS/Tutorials/WritingPublisherSubscriber(c++), I think my_topic should be the topic found in rostopic list but didn't work for subscribing scan topic. Thanks.