robots.events package¶
robots.events.events module¶
pyRobots’ events implementation
-
class
robots.events.events.
EventMonitor
(robot, 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
= '<'¶
-
DECREASE
= '-='¶
-
INCREASE
= '+='¶
-
VALUE
= '='¶
-
-
class
robots.events.events.
Events
(robot)[source]¶ Exposes high-level primitives to create and cancel event monitors.
robots.robot.GenericRobot
creates and holds an instance ofEvents()
that you can use: you should not need to instanciate yourself this class.-
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.
-
stop_all_monitoring
()[source]¶ Stops all event monitoring, but do not interrupt event callbacks, if any is running.
You may want to use
stop_all_monitoring()
instead ofcancel_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 amongstvalue=
,become=
,above=
,below=
,increase=
,decrease=
must be provided to define the behaviour of the monitor.Example:
# 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 = datetime.datetime.now() evening = now.replace(hour=20, minute=0, second=0, microsecond=0) return robot.state["speed"] > 1.0 and now > evening robot.whenever(is_tired).do(go_to_sleep)
Parameters: - 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 toTrue
). - kwargs – the monitor behaviour (cf above)
Returns: a new instance of
EventMonitor
for this event.- var – either a predicate (callable) or one of the key of
-