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

danividanivi's profile - activity

2019-04-07 22:46:14 -0500 marked best answer Declaring publisher twice

I have a program with a main.cpp and a message.cpp files.

The second has a function that is called every time an event happens and I have to send a ros message.

My first try was to declare the publisher and send the message in message.cpp:

ros::NodeHandle nh("~");
ros::Publisher pub = nh.advertise<myProject_ros::PathMessage>("/myProject_ros/message", 1000);
// creating my message
pub.publish(message);

But doing it like that, I had to insert a delay between the publisher and the publish, otherwise the listener had no time to connect.

In order to avoid introducing delays, I started creating the publisher in my main file:

ros::NodeHandle nh("~");
ros::Publisher pub = nh.advertise<myProject_ros::PathMessage>("/myProject_ros/message", 1000);

And then I wanted to publish in message.cpp:

pub.publish(message);

But then

error: ‘pub’ was not declared in this scope

So now I am creating the publisher both in the main so listener is ready and in message.cpp again to avoid pub not declared. It is working fine, I don't need delay now, but it looks like a "dirty" solution.

What is the proper way to do this? I am new to ROS and C++.

2018-12-03 05:32:51 -0500 received badge  Famous Question (source)
2018-04-04 09:45:22 -0500 received badge  Famous Question (source)
2018-03-20 07:26:55 -0500 received badge  Famous Question (source)
2018-03-11 20:18:28 -0500 received badge  Notable Question (source)
2018-01-17 09:37:07 -0500 commented answer example RQT plugin in C++ that uses signals/slots

I had exactly the same problem, just in my case it is a service instead of a publisher subscriber. This definitely shoul

2018-01-17 09:36:49 -0500 commented answer example RQT plugin in C++ that uses signals/slots

I had the exactly same problem, just in my case it is a service instead of a publisher subscriber. This definitely shoul

2018-01-17 09:36:22 -0500 commented answer example RQT plugin in C++ that uses signals/slots

I had the exactly same problem, just in my case it is a service instead of a publisher subscriber. This definetly should

2017-12-04 06:39:20 -0500 received badge  Popular Question (source)
2017-12-04 05:22:22 -0500 commented question Migrating from catkin_make to catkin build headers

@gvdhoorn it is not, the .msg files are in a different folder with .msg extension.

2017-12-04 05:20:17 -0500 commented question Migrating from catkin_make to catkin build headers

I added CmakeLists.txt

2017-12-04 05:18:40 -0500 edited question Migrating from catkin_make to catkin build headers

Migrating from catkin_make to catkin build headers I am following this guide to migrate from catkin_make to catkin build

2017-12-04 03:07:07 -0500 asked a question Migrating from catkin_make to catkin build headers

Migrating from catkin_make to catkin build headers I am following this guide to migrate from catkin_make to catkin build

2017-12-04 01:42:20 -0500 marked best answer catkin_make works but catkin build fails

I am working with a complex software where I have to make some changes. In order to build it, I was instructed to use catkin_make, which was (and is) working well. Now I have to use MAVROS, and the guide says to use catkin build instead.

However, I am unable to do so, it keeps giving a lot of errors, most of them about not found header files.

Why is this happening? shouldn't both methods build fine? (or fail both)

Is it possible to work with MAVROS with catkin_make?

(I know you can't work with both at the same time, so before switching I am doing catkin clean --all)

2017-12-04 01:42:20 -0500 received badge  Scholar (source)
2017-12-03 18:12:55 -0500 received badge  Notable Question (source)
2017-12-01 15:11:03 -0500 received badge  Popular Question (source)
2017-12-01 08:53:58 -0500 asked a question catkin_make works but catkin build fails

catkin_make works but catkin build fails I am working with a complex software where I have to make some changes. In orde

2017-11-07 15:03:02 -0500 received badge  Notable Question (source)
2017-11-07 09:36:10 -0500 received badge  Popular Question (source)
2017-11-07 02:40:14 -0500 commented question Declaring publisher twice

I thought about waiting for getNumSubscribers>0 but sometimes code will run without any listener, so I cannot do that

2017-11-07 02:38:30 -0500 commented question Declaring publisher twice

Thank you! The full code is very long and copyright protected, I just have to add this feature of sending ROS messages a

2017-11-07 01:57:08 -0500 asked a question Declaring publisher twice

Declaring publisher twice I have a program with a main.cpp and a message.cpp files. The second has a function that is c

2017-11-07 01:56:47 -0500 received badge  Supporter (source)