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

Proper conventions of separating large projects into .cpp and .h files?

asked 2018-07-12 02:22:24 -0500

Infection gravatar image

Hello,

I was wondering if there are any proper ways of making large projects more understandable for the reader. I am trying to make separate header and source files for my publishers and subscribers. I have made attempts to place them in a class, but I can't seem to access the data. Even when using global variables, which I hate doing, I can't get things to work.

Now my question is, is there some form of template or example of clearly structured projects that have their publishers and subscribers, maybe even service calling routines as well, in .cpp and .h files?

Thank you for your time. Kind regards, Infection.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2018-07-12 05:00:36 -0500

Delb gravatar image

Yes, you can check this git repo where you have miminimal templates for all kind of purpose : simple publisher/subscriber, using a class, using a ros message, a ros server etc.. It helped me a lot at the beginning.

Also @pavel92 's advice is good, it's always nice to see well-written code by developpers to get good habits. See the commonly used packages in ROS for example, it's always good to know what's really behind all the nodes you are using to learn and debug faster.

edit flag offensive delete link more
0

answered 2018-07-12 03:03:57 -0500

pavel92 gravatar image

You can always take a look at the structure of existing packages on github. You will see that, whithin a package, .h files are in the include folder, .cpp are in the src folder, custom messages(.msg) and services(.srv) go to msg and srv folders, .launch and test files also have their respective folders. For example you can examine this package.

Regarding the problem you have with not being able to access the header variables, make sure that you have included the header files properly in your CMakeLists.txt

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2018-07-12 02:22:24 -0500

Seen: 132 times

Last updated: Jul 12 '18