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

Why are many ros_control plugins putting all code in header files?

asked 2020-11-27 06:32:52 -0500

smihael gravatar image

I stumbled across a proposal for standardization of cartesian_controllers and noticed a similarity to what I’ve already seen in joint_trajectory_controller. Namely, most of the code is in .hpp files instead of .cpp, which is as far as I was thought the standard way of doing the things.

Why is that? I couldn’t find any guideline in the wiki on writing a new controller with ros_control. Stackoverflow lists some Pros & Cons of putting all code in Header files in C++?, but they are mostly related to compiling, which should not be too important for ros_control (compared to run times).

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
2

answered 2020-11-27 08:15:27 -0500

gvdhoorn gravatar image

updated 2020-11-27 08:16:54 -0500

Quite a bit of code in ros_control is heavily templated.

This allows for a significant level of code reuse (see the many variants of the controllers fi, many of them simply specialise a template).

While it is possible to split template code across .h and .cpp, it's not often done (as it comes with some drawbacks) and it wasn't done by the original authors of ros_control and ros_controllers. Maintainers and developers who took over never really had a reason to change this, so that's why you still see this now in the sources.

Personally I also don't necessarily like to split templated code in declarations and definitions (because of the drawbacks that come with it), but I've not been involved in the development of ros_control (certainly not in the beginning), so that doesn't really count.

Stackoverflow lists some Pros & Cons of putting all code in Header files in C++?, but they are mostly related to compiling, which should not be too important for ros_control (compared to run times).

Afaik, this is not about performance.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2020-11-27 06:32:52 -0500

Seen: 107 times

Last updated: Nov 27 '20