roslua: ROS client library for Lua

Module roslua.timer

Timer. This module contains the Timer class for periodical execution of a function. A time period is given, in which the function should be executed. Due to the nature of Lua, especially because it is inherently single-threaded, the times cannot be guaranteed, rather, a minimum time between calls to the function is defined.

During spinning the all timers are evaluated and executed if the minimum time has gone by. Make sure that timer callbacks are functions that run quickly and have a very short duration as not to influence the overall system performance negatively.

The rate at which the spinning function is called defines the minimum period for which timers can be called somewhat accurately. For example, if the roslua.spin() function is called once every 30ms, then these 30ms are the very minimum duration of a timer, a shorter time is not possible. You will see increasing offsets between the current_expected and current_real times which will periodically get small once the offset approaches half the spinning time.

The callback is invoked with a table as parameter of the following entries: * last_expected Time when the last callback should have happened * last_real Time when the last callback actually happened * current_expected Time when the current callback should have happened * current_real Time at the start of the current execution * last_duration Time in seconds the last callback ran

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

Release: Released under BSD license

Functions

Timer:finalize () Finalize instance.
Timer:new (period, callback) Constructor.
Timer:spin () Check time and execute callback if due.


Functions

Timer:finalize ()
Finalize instance.
Timer:new (period, callback)
Constructor. Create a new Timer instance.

Parameters

  • period: 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
Timer:spin ()
Check time and execute callback if due.

Valid XHTML 1.0!