How to access contents of a custom message
Hello everyone,
I am working on an application that, among other things, must include a ROS node that connects to an off-board ROS network (where the Master runs) and publishes and subscribes to some custom messages (some of them kind of big) with another node. The node I develop must be attached to an already developed C application that has to encode the received messages into some form of C structure, serialize it and send it to yet another application, and viceversa.
The approach I have in mind is to communicate the ROS node and the C application with shared memory (this is because the current design of the C app already uses it), but I am new to C++ and looking at the ROS C++ tutorial I can't clearly see how to access the data fields in a complex message that is three or four fields deep. I fact, I am already thrown off by the fact that the "String" message shown in the publisher/subscriber example only contains one data field but still a "c_str()" function is used as if the message object had member functions and not just the "data" field.
Thank you!
Just a comment here:
std_msgs/String
contains a single fielddata
of typestring
, which in C++ gets mapped tostd::string
(see wiki/msg).So in the end
msg->data
is just astd::string
. Makes perfect sense that you can then callc_str()
, no?That is one of the reasons why I explicitly mentioned my current lack of experience with C++, I have worked with C only until now. Does that mean that, if my custom messages only contain fields that ultimately "resolve" to basic types, I can access them like I would with a C structure?
Thank you!