Ask Your Question
1

Where are useful message constructors, converters

asked 2013-07-31 01:01:37 -0500

nevik gravatar image

updated 2014-01-28 17:17:29 -0500

ngrennan gravatar image

I'm relatively new to coding in/for ROS, and I'm looking at both the Python and the C++ side, but let's focus on C++ here.

There are all those useful classes (which are mappings of the ROS message types), like Pose, Twist, etc. But where are the related utility functions?

I mean, by what I've found so far, if I want to construct a Pose object, I have to:

geometry_msgs::Pose p;
p.position.x = MYXVAL;
p.position.x = MYYVAL;
p.position.x = MYZVAL;
p.orientation.x = ORXVAL;
p.orientation.y = ORYVAL;
p.orientation.z = ORZVAL;
p.orientation.w = ORWVAL;

Why can't I just do:

geometry_msgs::Pose p(geometry_msgs::Point(MYXVAL, MYYVAL, MYZVAL), geometry_msgs::Quaternion(ORXVAL, ORYVAL, ORZVAL, ORWVAL));

(which would of course be even shorter with the proper includes and using namespace declaration).

And where are my usual utility functions, like Vector3<->Quaternion or maybe Twist(Position+Facing)<->Pose(Position+Orientation)?

I could write the convenience constructors (which one would expect to be provided) myself, of course, but that's not the point of using a library like ROS/roscpp.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
2

answered 2013-07-31 04:16:13 -0500

tbh gravatar image

You might need to upgrade to a newer ROS version. This ticket says that copy constructors have been available for a while.

Anyway, ROS C++ message classes are auto-generated from *.msg files. See the genmsg package. The generator can't insert convenience functions to convert to and from related message types because it doesn't know what's related and what's not. You'd have to write that yourself.

edit flag offensive delete link more

Comments

While I can see that the code generator cannot add semantically meaningful conversion functions, I'd expect some kind of constructor that takes a list of all attributes, like in the case of a Point: `Point(x, y, z)`. Naturally, I *can* create them, but I'd prefer not to :/

nevik gravatar imagenevik ( 2013-07-31 23:23:48 -0500 )edit

Right. And those constructors *should* be available. Point(1,2,3) is even one of the test cases referenced in the ticket I linked. If you're on the current version of ROS and you cannot use Point(1,2,3), it's a bug and the ticket needs to be refiled.

tbh gravatar imagetbh ( 2013-08-01 03:17:06 -0500 )edit

That does not seem to work on Fuerte, unfortunately. Due to certain dependencies which don't work (out of the box) with newer ROS version, I cannot currently upgrade to a newer version, sadly. I'll be looking into that though, and hopefully get it done.

nevik gravatar imagenevik ( 2013-08-01 03:26:52 -0500 )edit
3

answered 2015-08-12 19:45:31 -0500

kwiesz91 gravatar image

updated 2015-08-12 19:48:13 -0500

Actually (in regards to your first point), after a couple frustrating hours, I do not believe that this is implemented in the roscpp client libraries. Check out this issue: https://github.com/ros/ros_comm/issue... . I do not believe they are planning on implementing it either...

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2013-07-31 01:01:37 -0500

Seen: 6,105 times

Last updated: Aug 12 '15