Subscribing to the wrong Topic
My problem is that I want to subscribe to the Topic "joy" but from a class.
Let's say that i have a class named My_Class.
As protected method i wrote the subscriber.
protected:
ros::Subscriber my_subscriber;
Then i iniatlized it.
my_subscriber = nh_.subscribe("joy", 1, &My_Class::my_subscriber_cb, this);
Then i wrote my Callback Function
void my_subscriber_cb(const sensor_msgs::Joy::ConstPtr& msg){}
Then i initialised my node like this:
// ROS-Node Initialisation
ros::init(argc, argv, "TEST_CORE", ros::init_options::NoSigintHandler);
The problem is that at the end when i show the topic with rostopic list
I get a topic named TEST_CORE/joy
. So I'm subscribing to TEST_CORE/joy
and not to /joy
.
What can i do or change to get the Data of my gamepad from the right Topic ?
Could it be that your nodehandle is private? I.e.
nh_("~")
? this would explain why the topic is put in the node namespace.Otherwise, you could always remap...
Hello. Yes i had my nodehandle like this
nh_ = ros::NodeHandle("~");
I removed the"~"
and it worked. Thanks. But I'm afraid it will bring some problems with it. I have all my code written innode.cpp
file. Can you explain the remap tool ? how can i write that in a correct way, because i tried it and it didn't work.posted as answer...