Robotics StackExchange | Archived questions

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

I stumbled across a proposal for standardization of cartesian_controllers and noticed a similarity to what I’ve already seen in jointtrajectorycontroller. 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).

Asked by smihael on 2020-11-27 07:32:52 UTC

Comments

Answers

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.

Asked by gvdhoorn on 2020-11-27 09:15:27 UTC

Comments