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

Overload operators for self-defined messages

asked 2015-07-22 05:48:47 -0500

updated 2015-07-22 07:23:56 -0500

Is it possible to overload operators for self-defined ROS messages? Say I have a vector message and I want to implement the multiplication by a scalar value.

EDIT: I know I can do it, as they are just classes, and they will be available at building time. But I was wondering what problems can occur and if this is a bad practice.


edit retag flag offensive close merge delete


This is because I want to avoid doing a lot of conversions between for example pose msgs and pose representation to operate on them. It will have small impact on performance, but the lines of code will be reduced, together with "error-proneness" when coding.

Javier V. Gómez gravatar image Javier V. Gómez  ( 2015-07-22 07:22:54 -0500 )edit

Wouldn't there be only a conversion at the 'entrance' and at the 'exit' of your business logic?

In any case: it is actually 'accepted practice' to convert stuff to-and-fro ROS msgs. See fi tf2 and its many tf2_bullet, tf2_kdl etc conversion pkgs.

gvdhoorn gravatar image gvdhoorn  ( 2015-07-22 07:41:53 -0500 )edit

There will be 2 conversions per type, but if I use many types, like Vector, Matrix, Quaternion, etc, there would be lots of conversions.

Javier V. Gómez gravatar image Javier V. Gómez  ( 2015-07-22 07:59:48 -0500 )edit

For exactly these types there are already conversion packages to tf, Eigen.

dornhege gravatar image dornhege  ( 2015-07-22 08:29:10 -0500 )edit

Those are just an example (those are not self-defined messages). But in any case this post is about the practice of avoiding conversions.

Javier V. Gómez gravatar image Javier V. Gómez  ( 2015-07-22 08:47:27 -0500 )edit

1 Answer

Sort by » oldest newest most voted

answered 2015-07-22 07:04:26 -0500

gvdhoorn gravatar image

I'm not saying it can't be done, but it is generally recommended to keep your 'business logic' ROS agnostic. Doing what you suggest seems to inherently lead to code that uses ROS messages as variable types throughout, and thus completely violating the recommendation.

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2015-07-22 05:48:47 -0500

Seen: 259 times

Last updated: Jul 22 '15