roslua: ROS client library for Lua

Module roslua

ROS language binding for Lua. This module and its sub-modules provides the necessary tools to write ROS nodes in the Lua programming language. It supports subscribing to and publishing topics, providing and calling services, and interacts with the standard ROS tools to provide introspection information.

Copyright© Tim Niemueller, Carnegie Mellon University, Intel Labs Pittsburgh, SRI International

Release: Released under BSD license

Functions

add_finalizer (finalizer) Add a finalizer.
add_spinner (spinner) Add a spinner.
assert_version (major, minor, micro) Assert a specific roslua version.
exit () Exit the program.
finalize () Finalize this node.
get_msgspec (msg_type) Get message specification.
get_name () Get node name.
get_slave_proxy (uri) Get a slave proxy.
get_srvspec (srv_type) Get service specification.
init_node (args) Initialize ROS node.
publisher (topic, type) Get a new publisher for a topic.
remove_finalizer (finalizer) Remove finalizer.
remove_spinner (spinner) Remove spinner.
run (loop_frequency, desired) Spin until program is stopped.
service (service, type, handler) Get a new service handler.
service_client (service, type, options) Get a service client.
sleep (sec_or_duration, sec) Sleep the given number of seconds.
subscriber (topic, type) Get a new subscriber for a topic.
timer (interval, callback) Create timer.


Functions

add_finalizer (finalizer)
Add a finalizer. The finalizer will be called when roslua.finalize() is executed.

Parameters

  • finalizer: function which is called without arguments on finalization
add_spinner (spinner)
Add a spinner. The spinner will be called in every loop after the other events have been processed.

Parameters

  • spinner: spinner to add, must be a function that is called without any arguments in each spin.
assert_version (major, minor, micro)
Assert a specific roslua version. Throws an error if minimum version requirements are not met.

Parameters

  • major: minimum required major version
  • minor: minimum required minor version (if major version is equal)
  • micro: minimum required micro version (if major and minor versions are equal)
exit ()
Exit the program. This sets the quit flag to true and will cause (proper) programs to exit.
finalize ()
Finalize this node. Call this function when existing the program to allow for proper unregistering of topic and services and to perform other cleanup tasks.
get_msgspec (msg_type)
Get message specification.

Parameters

  • msg_type: message type (e.g. std_msgs/String). The name must include the package.
get_name ()
Get node name.

Return value:

node name
get_slave_proxy (uri)
Get a slave proxy. Slave proxies are XML-RPC client-side wrappers to communicate with another ROS node via the XML-RPC protocol, e.g. for requesting information or topics. The proxies are maintained in a cache and there is always only one instance of a slave for a specific remote node.

Parameters

  • uri: URI of remote slave

Return value:

SlaveProxy instance

See also:

get_srvspec (srv_type)
Get service specification.

Parameters

  • srv_type: service type (e.g. std_msgs/String). The name must include the package.
init_node (args)
Initialize ROS node. This function must be called before any other interaction with ROS or roslua is possible. Note that the library can always accomodate only one ROS node per interpreter instance! A signal handler is set for SIGINT (e.g. after pressing Ctrl-C) to set the quit flag to true if the signal is received.

Parameters

  • args: a table with argument entries. The following fields are mandatory:
    master_uri
    The ROS master URI
    node_name
    the name of the node using the library
    The following fields are optional.
    no_rosout
    Do not log to /rosout.
    no_signal_handler
    Do not register default signal handler.
publisher (topic, type)
Get a new publisher for a topic. Request the creation of a publisher for a specific topic. Publishers are maintained in a cache, and for any one topic there is always at most one publisher which is shared.

Parameters

  • topic: name of topic to request publisher for
  • type: type of topic

Return value:

Publisher instance for the requested topic

See also:

remove_finalizer (finalizer)
Remove finalizer.

Parameters

  • finalizer: finalizer to remove
remove_spinner (spinner)
Remove spinner.

Parameters

  • spinner: spinner to remove
run (loop_frequency, desired)
Spin until program is stopped. This will spin infinitely until roslua.quit is set to true, e.g. by a interrupt signal after pressing Ctrl-C.

Parameters

  • loop_frequency:
  • desired: loop frequency in Hz. If set to anything less or equal to zero will run as fast as possible Warning, may cause high CPU load. Defaults to 25 Hz. You should increase the loop frequency if you need small communication latencies.
service (service, type, handler)
Get a new service handler. Request the creation of a new service, i.e. the server side or provider of the service. An error is thrown if the service has already been registered.

Parameters

  • service: name of the provided service
  • type: type of the provided service
  • handler: the service handler, this is either a function or a class instance which provides a service_call() method.

Return value:

Service instance for the requested service

See also:

service_client (service, type, options)
Get a service client. Request the creation of a new service client to access a ROS service. Service clients are not cached and a new client is created for every new creation request.

Parameters

  • service: name of the requested service
  • type: type of service
  • options: a table defining additional for the service. The possible valid fields are: persistent: true to request a persistent connection to the service simplified_return: true, to make the return value the unpacked array of the returned message. This is useful for services which have a small return value, e.g. just a boolean success flag or a few simple values. Note that complex types will be flattened in the return value.

See also:

sleep (sec_or_duration, sec)
Sleep the given number of seconds. During the sleep time events will be processed if the sleep time is at least 0.05 sec.

Parameters

  • sec_or_duration:
  • sec: time in seconds or duration to sleep
subscriber (topic, type)
Get a new subscriber for a topic. Request the creation of a subscriber for a specific topic. Subscribers are maintained in a cache, and for any one topic there is always at most one subscriber which is shared.

Parameters

  • topic: name of topic to request subscriber for
  • type: type of topic

Return value:

Subscriber instance for the requested topic

See also:

timer (interval, callback)
Create timer. Creates a timer and registers it for execution.

Parameters

  • interval: minimum time between invocations, i.e. the desired time interval between invocations. Either a number, which is considered as time in seconds, or an instance of Duration.
  • callback: function to execute when the timer is due

Valid XHTML 1.0!