Reposting C++ Issue

Hi, I think my previous post may have notifications turned off with the amount of replies.

Here is my issue.

I am doing the final project for C++. I have made a odom subscriber and a server so far as suggested. So for I have transfered over my odom subscriber. I assume, what you are meant to do in order to use the odom subscriber in the action server is to create a get method in the odom subscriber and call it in the server. So this is what I have tried.:

This is my odom subscriber:

As you can see I have the class and the getOdomData get method, which returns the Odometry which is provided by the callback.

Next I didn’t really know how to get that method in the server cpp file. So I assume you have to create an object. But to do that you need to #include the file I assume? And in order to do that you need a .h file. I have never made a header file before so I am unsure on if that is right. So far all our .h files have been compiled automatically for our msg files etc.

So I made this header file here:

As you can see, I have made the header file. Though I think it is incorrect as it is flagging errors. I am still unsure how to use this in order to get the getOdomData() method in the record_odom_action_server.cpp file. Can I get some help on this?

Many thanks


Hi Zac,

Are you familiar with C++? If not I will suggest you try the Python version of the course, which is easier for a beginner.

If you are somewhat familiar with C++, and you follow the examples given in toto, you should be able to get it working:

IMPORTANT: you don’t need to create any header file. In fact, you shouldn’t! It’s automatically created for you when you

  • setup your package properly by taking the pains to make the necessary changes in CMakeList.txt and package.xml. The changes required could be the normal one required for a C++ source file AND other required if you are creating a custom message or action.
  • It’s extremely helpful to add your dependencies to the catkin_create_pkg command as this will save you some manual edits to CMakeList.txt and package.xml.
  • compile your package successfully with catkin_make.
  • run source devel/setup.bash in all terminals where you will use the code.

Please check these and let us know how it goes.