0
$\begingroup$

Rosanswers logo

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.

Thanks!


Originally posted by Javier V. Gómez on ROS Answers with karma: 1305 on 2015-07-22

Post score: 0


Original comments

Comment by Javier V. Gómez on 2015-07-22:
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.

Comment by gvdhoorn on 2015-07-22:
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.

Comment by Javier V. Gómez on 2015-07-22:
There will be 2 conversions per type, but if I use many types, like Vector, Matrix, Quaternion, etc, there would be lots of conversions.

Comment by dornhege on 2015-07-22:
For exactly these types there are already conversion packages to tf, Eigen.

Comment by Javier V. Gómez on 2015-07-22:
Those are just an example (those are not self-defined messages). But in any case this post is about the practice of avoiding conversions.

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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.


Originally posted by gvdhoorn with karma: 86574 on 2015-07-22

This answer was ACCEPTED on the original site

Post score: 0

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.