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

Understanding the messages API

asked 2013-09-04 21:02:27 -0500

Flavian gravatar image

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

ngrennan gravatar image

Hello everyone.

I read the very good tutorials on messages/services and publishers/subscribers. I am currently using roscpp but I guess this question is not limited to it. After going through the tutorials, I wanted to apply what I learnt to MoveIt: generate a trajectory through the JoinTrajectory message and publish it to the joint_action_trajectory topic.

I am trying to figure out:

  1. If there is an easy way to construct such a message which wouldn't require me filling every field by hand (can we feed an std::vector? Is there a constructor? How do I know so I can generalize to other messages?)
  2. What should I put in the "include", what should I put in package.xml and CMakeLists.txt (for catkin in my case)? Again, how do I find that out?

Thanks

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2013-09-30 15:10:19 -0500

Thomas gravatar image
  1. An std::vector only contains data of the same type. By definition a record-like structure such as a ROS message would not match as it contains various types of data. Usually what happens is that you do not use the ROS datatype directly because its semantic is poor due to the lack of expressivity of the ROS messages/services (or any other IDL language for that matter). So instead of building messages by hand, you usually convert them from a local datatype (aka pcl::PointCloud, an OpenCV image, etc.). What is unclear in this question is whether you are using or not the MoveIt! API in your project. If yes, then probably converting the message from/to a RobotTrajectory object would make sense. There is probably such a facility in MoveIt! API (but again I am no expert). On the opposite if you do not use MoveIt! in your node then building a local trajectory class with two functions handling the conversion from the ROS message to this class and the opposite would make sense. So the answer to your question no in the general case (in C++, Python has introspection so this would probably be doable) but many helpers are provided in ROS.
  2. Let's say your message is called "XXXX_msgs/foo". This means that the message is called "foo" and is provided by the "XXXX_msgs" package. The C++ header which needs to be included is "XXXX_msgs/foo.h". You will need to add the package "XXXX_msgs" as both a build and a runtime depend of your project in the package.xml file.
edit flag offensive delete link more

Comments

I was not aware of the existence of RobotTrajectory, which is interesting. So what you mean in short is that there is no general/automatic API for message construction. Instead, there exist ad hoc APIs such as RobotTrajectory to manage the messages.

Flavian gravatar image Flavian  ( 2013-09-30 23:07:35 -0500 )edit

Yes, exactly. Mainly because the way you want to store your data when it is sent between two nodes and the way you want it to be when you use it for your computations is often different.

Thomas gravatar image Thomas  ( 2013-09-30 23:25:33 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2013-09-04 21:02:27 -0500

Seen: 322 times

Last updated: Sep 30 '13