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

pparescasellas's profile - activity

2016-02-08 13:29:17 -0500 received badge  Great Question (source)
2014-01-28 17:22:42 -0500 marked best answer How to deserialize a ros message without knowing its type or content

Hey there,

I'm trying to serialize any ros message received using ros::serialization and once this is done I need a way to deserialize it again but without knowing the message type. I'll try to explain how I intend to do this and I'd like to know if there's a better way to accomplish it.

I need to do this just to fill an xml with all the data contained in the message received like so:

<message_a>
  <x type="float64" value="25.2" />
  <y type="float64" value="23.2" />
  etc..
</message_a>

I'm just bothering with all the serialization and deserialization because I don't seem to find another way to accomplish that without knowing the message type (I need to make a generic function that fills an xml no matter what the message looks like).

First of all, I serialize the message this way:

const std::string& publisher_name = event.getPublisherName() ;
const cola2_common::BhResponse::ConstPtr& msg = event.getMessage() ; //BhResponse is a message I have defined.

ROS_INFO( "BhResponse received from: [%s]", publisher_name.c_str() ) ;

uint32_t serial_size = ros::serialization::serializationLength( *msg ) ;
boost::shared_array< uint8_t > buffer( new uint8_t[ serial_size ] ) ;

ros::serialization::OStream stream( buffer.get(), serial_size ) ;
ros::serialization::serialize( stream, *msg ) ;

Once I have the serialized stream I'd like to deserialize it again but without knowing the message type (so I can't use ros::serialization::deserialize). I have thought to do that asking for the definition of the message (so I get the type and name of all the contained data) and then keep rebuilding manually.

If I ask for the definition of the previous message I get this:

ROS_INFO( "BhResponse message Definition: %s", msg->__getMessageDefinition().c_str() ) ;

/**BhResponse message Definition:
float64[6] setPoints
float64[6] activationLevels
int32      priority */

I find the first problem here: __getMessageDefinition() is deprecated; how do I get this information without calling this method?

And finally, once I have the serialized message and its definition, I was going to keep building the xml step by step; first I'd add the name of the variable, then I'd add the type and after that, manually deserialize the stream to get its value, etc.

I'd appreciate any help I can get! Thanks!

2014-01-28 17:22:34 -0500 marked best answer Calling ROS services in Python using yaml notation for the parameters?

Hey everybody! I was wondering if it was possible to call a ROS service from within a python node using YAML notation for the parameters like the console tool rosservice. Something like:

rosservice call /add_two_ints '{a:1, b:2}'

But from within a python node:

add_two_ints = rospy.ServiceProxy( 'add_two_ints', AddTwoInts )
add_two_ints( "{a:1, b:2}" )

I already know that the following is possible, but it's not what I'm looking for:

add_two_ints( a=1, b=2 )

Thank you!

2014-01-28 17:22:18 -0500 marked best answer How to get the publisher name from a received message in rospy?

Hey everybody,

I can't find anywhere how to get the publisher name from a received message using python. In C++ I just have to do the following:

void
callback( const ros::MessageEvent< cola2_common::BhResponse const >& event )
{
    const std::string& publisher_name = event.getPublisherName() ;
}

What's the equivalent in python? Thank you!

2014-01-28 17:22:18 -0500 marked best answer How to know where the next variable begins in a serialized message?

Hey everybody,

In the last few weeks I've been trying to serialize any ROS message received in some kind of listener node that's subscribed to all the existent topics. Once every message is serialized (using ros::serialize) I get an Ostream full of bytes. I need to deserialize this Ostream byte by byte (without using ros::deserialize) to rebuild all the containing data of any message and put the information into some xml-like format. My idea is to call __getMessageDefinition() (which is deprecated...) for each message to obtain the .msg definition so I get something like:

float64[6] a
float64[]  b
float64[]  x
int32      c

Once I have this information, I know that the first 8 bytes of the Ostream are a[0], the next 8 are a[1], etc. And the last 4 bytes belong to c. The problem would be solved if it wasn't for vectors without specified length and strings.

So my question is, how can I know how many bytes belong to a certain variable? In the example above, how can I know where b ends and x starts? There should be a way to do this right?

Thanks!

2014-01-28 17:22:14 -0500 marked best answer How to create a global listener for any ROS topic and extract all data from any message?

Hey everybody,

I am trying to build a ROS node that receives all the messages published by all the other nodes present in my software architecture. This new node should be able to receive any message (with different contents), extract all the data and log it (so it's important for me to be able to know all the contained data types and their values). Is there any good way to:

  • Convert any .msg to some "common" format, like XML (so I can treat all the messages as just one string and then do my parsing)?
  • If not, how do I to easily parse each contained data inside any message ( type and value )?. I want to treat all the messages as if they were generic; I don't want to manually extract all the data one variable at a time, this would force me to make one hardcoded callback for each topic.
  • Also, is there any better way to receive all the messages from any node with any topic without having to create a new subscriber and a callback for each new topic in my "listener" node?

Thanks!

2013-03-14 08:45:01 -0500 received badge  Good Question (source)
2012-12-16 21:29:50 -0500 received badge  Notable Question (source)
2012-12-16 21:29:50 -0500 received badge  Famous Question (source)
2012-12-16 21:29:50 -0500 received badge  Popular Question (source)
2012-10-09 20:14:57 -0500 received badge  Famous Question (source)
2012-10-09 20:14:57 -0500 received badge  Popular Question (source)
2012-10-09 20:14:57 -0500 received badge  Notable Question (source)
2012-09-21 21:53:33 -0500 received badge  Famous Question (source)
2012-09-05 04:29:12 -0500 received badge  Taxonomist
2012-08-19 23:31:27 -0500 received badge  Popular Question (source)
2012-08-19 23:31:27 -0500 received badge  Notable Question (source)
2012-08-19 23:31:27 -0500 received badge  Famous Question (source)
2012-08-19 23:29:26 -0500 received badge  Notable Question (source)
2012-08-19 23:29:26 -0500 received badge  Famous Question (source)
2012-08-18 04:09:08 -0500 received badge  Famous Question (source)
2012-06-21 15:31:12 -0500 received badge  Popular Question (source)
2012-06-20 14:21:28 -0500 marked best answer What's the best way to convert a ros message to a string or xml?

Hey everybody,

I would like to know what's the best way (if possible) to convert any message in ros into something similar to xml or just a string. Let's say I have this message defined:

float64[6] a
float64[]  b
int32      c

I'd like to parse it to something like:

<message>
  <a type="float64" value="1.0,2.0,3.0,4.0,5.0,6.0"/>
  <b type="float64" value="7.0,5.0,6.0"/>
  <c type="int32" value="4"/>
</message>

What's the best way to achieve that? I want it to be the most generic possible (so, I don't want to manually put my message.a, message.b, message.c into a string). I'm going to use this into some kind of listener node subscribed to many topics so I don't want to define one callback for each topic and having to unpack manually each message.

Edit: I have been hinted somewhere else to use Python to achieve this because it's easier. I'd like a C++ solution but if that's too hard then I'd appreciate someone explaining how can I easily parse ros messages in python to know all the names, values and types in a somewhat dynamic way.

Thanks a lot!

2012-04-26 01:31:33 -0500 received badge  Notable Question (source)
2012-03-19 11:26:55 -0500 received badge  Notable Question (source)
2011-11-22 03:49:47 -0500 received badge  Popular Question (source)