Gazebo | Ignition | Community
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to receive a GzString

Hi all

I'm trying to send a string via the Gazebo transport system. I managed to write a plugin that publishes the string I want as a GzString message. I now want to write a receiver that does something with the string. My starting point for this is this listener example.

The problem I have is that I don't know what to do with my received string in the call back function (called cb in the above example). I have changed the call back function to accommodate for the fact that the message is a GzString as follows, but the change was essentially just a guess (replacing ConstWorldStatisticsPtr with ConstWorldStatisticsPtr) and I don't know if this is actually what I need to do. I can't find any documentation regarding this.

void cb(ConstWorldStatisticsPtr &_msg)
{
  // Dump the message contents to stdout.
  std::cout << _msg->DebugString();
}

The ->DebugString(); does not necessarily seem appropriate for a string, but I don't know what else to use or where to find documentation about this.

Can somebody help me or point me to where this is described?

Thanks,

Nick

P.S: What I'm trying to accomplish is to communicate joint angles back and forth. I would like to be able to have one message type that is able to handle a different number of joints. Right now, I just write the joint names and angle values into the string and parse them out on the receiving side. I realize that this is not very elegant but I couldn't figure out a better way. If you can offer help in doing this differently, I would also be open to suggestions.

How to receive a GzString

Hi all

I'm trying to send a string via the Gazebo transport system. I managed to write a plugin that publishes the string I want as a GzString message. I now want to write a receiver that does something with the string. My starting point for this is this listener example.

The problem I have is that I don't know what to do with my received string in the call back function (called cb in the above example). I have changed the call back function to accommodate for the fact that the message is a GzString as follows, but the change was essentially just a guess (replacing ConstWorldStatisticsPtr with ConstWorldStatisticsPtr) and I don't know if this is actually what I need to do. I can't find any documentation regarding this.

void cb(ConstWorldStatisticsPtr &_msg)
{
  // Dump the message contents to stdout.
  std::cout << _msg->DebugString();
}

The ->DebugString(); does not necessarily seem appropriate for a string, but I don't know what else to use or where to find documentation about this.

Can somebody help me or point me to where this is described?

Thanks,

Nick

P.S: What I'm trying to accomplish is to communicate joint angles back and forth. I would like to be able to have one message type that is able to handle a different number of joints. Right now, I just write the joint names and angle values into the string and parse them out on the receiving side. I realize that this is not very elegant but I couldn't figure out a better way. If you can offer help in doing this differently, I would also be open to suggestions.