Skip to content
chris-smith edited this page Aug 27, 2013 · 11 revisions

Locate the primitives folder. Each of the listed primitive types can be used to build out more complete libraries of message parsing. The primitive vis listed are automatically adapting polymorphic vis – for each primitive type there is one vi to parse scalar values and one to parse array values. The parsing vis all pass the string containing the message between them. To parse out a string, pull the parse_string.vi into your diagram and wire it as shown.

Parse String

Multiple values can be parsed by wiring in series like this.

Multiple String Parse

When parsing arrays, it is necessary that you specify if the array is of variable or fixed length. Fixed length arrays are specified in the message definition by including a number in the brackets (looks like string[4] rather than string[]). Just because you expect to always receive the same number of array elements back does not mean the array size is fixed. To specify that you want to parse an array, wire an array of the correct type into the “type” terminal on the vi. If the array has a fixed size, you also need to wire in the number of elements in your array.

Parsing Arrays

Let’s use the geometry_msgs/Twist as an example. Twist is made up of two geometry_msgs/Vector3 data fields. So to parse a Vector3, we make a vi that looks like this

Parsing Vector3

Then to parse a Twist message, our vi just looks like this

Parsing Twist

These vis can also be seen in the Parsing/geometry_msgs folder.

It is highly recommended that all parsing vis carry through the string controls and indicators, since ROS messages can contain other messages. This allows for easier parsing of complex message types. It is also a smart idea to pass through the error indicators. An error will be raised if the parser is unable to parse out the data type required. For example, if you attempt to parse out a uint32, but there are only 3 bytes of data left in the msg, an error will be raised. Lastly, by convention, parsing function names should be appended to "parse_" and placed in an appropriate folder. So the parsing function for geometry_msgs/Twist goes in a folder called "geometry_msgs" and is named "parse_twist.vi". This is done to avoid file naming conflicts.

Clone this wiki locally