roslua: ROS client library for Lua

Module roslua.message

ROS message representation. This class incorporates a ROS message that can be sent and received over a TCPROS connection. A message is created via the MsgSpec:instantiate() method.

A message has two important fields. One is the spec field. It contains a reference a a MsgSpec instance describing this message. Further there is a field values which is a dict table. It contains entries for the names of the message fields storing the appropriate. The values array has to be filled appropriately before sending a message, and on deserializing a received message it will contain the received values.

Copyright© Tim Niemueller, Carnegie Mellon University, Intel Research Pittsburgh

Release: Released under BSD license

Functions

Message:deserialize (buffer, i) Deserialize received message.
Message:format_string (buffer, i, farray, prefix, format) Generate format string.
Message:generate_value_array (flat_array, array) Generate a value array from the stored values.
Message:new (spec, no_prefill) Constructor.
Message:plain_value_table () Get plain value table.
Message:print (indent) Print message.
Message:read_values (values, start) Read values into values field.
Message:serialize () Serialize message.
Message:set_from_array (arr) Set message values from array.
Message:split_format (format) Format splitting iterator.


Functions

Message:deserialize (buffer, i)
Deserialize received message. This will deserialize the message according to the message specification. Not that it is the users obligation to make sure that the buffer is correctly typed for the message, especially that the buffer has the appropriate size.

Parameters

  • buffer: buffer that contains the message as read from the TCPROS connection
  • i: Index from where to start parsing in the buffer, optional argument that defaults to 1
Message:format_string (buffer, i, farray, prefix, format)
Generate format string. The format string is based on the base format of the message specification, but takes into account actual array sizes, replicating array parts as necessary.

Parameters

  • buffer: incoming buffer to be deserialized
  • i: index from where to start reading buffer
  • farray: base format array from message spec, if nil the one from internal spec is used (recursion parameter)
  • prefix:
  • format: prefix if nil set to little endian and 1 byte alignment (recursion parameter)
Message:generate_value_array (flat_array, array)
Generate a value array from the stored values. This is used for serialization, but also during execution of service calls.

Parameters

  • flat_array: if set to true (the default) will generate a flat array, which means that the resulting value array from complex sub-messages are folded into the array at the place where the field is defined. If set to false the value arrays for the sub-messages are integrated verbatim as array at the appropriate position.
  • array:

Return value:

positional array of values, output depends on flat_array param, see above.
Message:new (spec, no_prefill)
Constructor.

Parameters

  • spec: message specification
  • no_prefill:
Message:plain_value_table ()
Get plain value table. This creates a new table which contains all the values from the values field. The major difference is that this will be done recursively for sub-message types.

Return value:

value table
Message:print (indent)
Print message.

Parameters

  • indent: string (normally spaces) to put before every line of output
Message:read_values (values, start)
Read values into values field. This iterates over the given array and copies the values to the internal values field, instantiating sub-classes as necessary.

Parameters

  • values: array, flat array with all values of the message
  • start: index from where to start reading the values array
Message:serialize ()
Serialize message.

Return value:

three values, the serialized string appropriate for sending over a TCPROS connection, the used struct format, and the array of values
Message:set_from_array (arr)
Set message values from array. Set the values field from the given array. Assumes a non-flat array layout where positions of complex sub-messages contain an appropriate array of values for the message (possibly recursively having arrays again).

Parameters

  • arr: array of values
Message:split_format (format)
Format splitting iterator. Splits the struct format after 200 characters (up to 202 if a string definition would otherwise be illegal, e.g. a 'c' not followed by a 0, or an i/I without the number of bytes).

Parameters

  • format: format to split

Return value:

iterator function

Valid XHTML 1.0!