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!
Originally posted by jotator on ROS Answers with karma: 60 on 2018-06-01
Post score: 0
Original comments
Comment by gvdhoorn on 2018-06-01:
Just a comment here: std_msgs/String
contains a single field data
of type string
, which in C++ gets mapped to std::string
(see wiki/msg).
So in the end msg->data
is just a std::string
. Makes perfect sense that you can then call c_str()
, no?
Comment by jotator on 2018-06-01:
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!