package module

pyRobots’ events implementation

class, var, value=None, becomes=None, above=None, below=None, increase=None, decrease=None, oneshot=False, max_firing_freq=10, blocking=True)[source]
ABOVE = '>'
BECOMES = 'becomes'
BELOW = '<'
VALUE = '='

Blocks until an event occurs.


Exposes high-level primitives to create and cancel event monitors.

robots.robot.GenericRobot creates and holds an instance of Events() that you can use: you should not need to instanciate yourself this class.


Cancels all event monitors and interrupt running event callbacks (if any).

every(var, max_firing_freq=10, blocking=True, **kwargs)[source]

Alias for whenever().

on(var, **kwargs)[source]

Creates a new EventMonitor to watch a given event model (one shot).

On the first time the event is fired, the monitor is removed.

Returns:a new instance of EventMonitor for this event.

Stops all event monitoring, but do not interrupt event callbacks, if any is running.

You may want to use stop_all_monitoring() instead of cancel_all() when you need to prevent new events of being raised from an event callback (cancel_all() would interrupt this callback as well).

whenever(var, max_firing_freq=10, blocking=True, **kwargs)[source]

Creates a new EventMonitor to continuously watch a given event.

var can either be a predicate or the name of an entry in the robot’s state container (robot.state). In the later case, a supplementary keyword argument amongst value=, become=, above=, below=, increase=, decrease= must be provided to define the behaviour of the monitor.


# using the robot state:
robot.whenever("touch_sensor", value = True).do(on_touched)
robot.whenever("sonar", below = 0.4).do(on_obstacle_near)
robot.whenever("bumper", becomes = True).do(on_hit_obstacle)

# using a predicate:
def is_tired(robot):
    # do any computation you want...
    now =
    evening = now.replace(hour=20, minute=0, second=0, microsecond=0)
    return robot.state["speed"] > 1.0 and now > evening

  • var – either a predicate (callable) or one of the key of robot.state.
  • max_firing_freq – set how many times pe second this event may be triggered (default to 10Hz. 0 means as many as possible).
  • blocking – if True, the event callback is blocking, preventing new event to be triggered until the callback has completed (defaults to True).
  • kwargs – the monitor behaviour (cf above)

a new instance of EventMonitor for this event.