ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

huytyskland's profile - activity

2021-10-15 08:41:17 -0500 marked best answer Unable to publish a message to a predefined topic

Hello,

My project is on Linux. I am having an issue with Publisher. I git clone a package in which a node called A1 has a topic named a1. I also installed another package in which a node called B2 has a topic named b2. Then I created myself a package in which my created node subsribed to the topic b2 and whenever it received a message, it will convert the message before publish the new message to the topic a1. With linux command: "rostopic pub a1......", I can read (using "rostopic echo a1") the data from topic a1. However, when I used the code in my .cpp file, I cannot echo the data of topic a1. Here is my abstract code:

....

void callBack(const received_message_type receivedMessage)
{

       new_message_type newMessage;
       [code for conversion]
       ros::NodeHandle nh_pub;
       ros::Publisher pub = nh_pub.advertise<new_message_type>("a1", 1000);
       pub.publish(newMessage);
}

int main (int argc, char **argv)
{

       ros::init(argc, argv, "simple_node");
       ros::NodeHandle nh_sub;
       ros::Subcriber sub = nh_sub.subscribe("b2", 1000, &callBack);

       ros::spin();
}

I also add "find_package" which includes node A1 and node B2 in CMakeLists.txt and <build_depend> as well as <exec_depend> of those 2 in package.xml. But cannot echo any data from a1.

The flow of my application is receiving arrow keys from node B2 which publich the message via topic b2. My created node will subscribe to b2 to convert the message from it and then publish to topic a1.

In my case, what could possibly be the cause?

Hope someone help me soon, thank you very much.

2021-10-15 08:41:17 -0500 received badge  Scholar (source)
2021-10-15 01:21:45 -0500 commented answer Unable to publish a message to a predefined topic

Thank you. That helps me to solve the issue.

2021-10-14 21:03:01 -0500 received badge  Popular Question (source)
2021-10-14 13:26:20 -0500 asked a question Unable to publish a message to a predefined topic

Unable to publish a message to a predefined topic Hello, My project is on Linux. I am having an issue with Publisher. I