grepros 1.2.2
grep for ROS bag files and live topics
Loading...
Searching...
No Matches
ConditionMixin Class Reference

Provides topic conditions evaluation. More...

Inheritance diagram for ConditionMixin:
Inheritance graph

Classes

class  Empty
 Placeholder falsy object that raises NoMessageException on attribute access. More...
 
class  Message
 Object for current topic message in condition expressions. More...
 
class  NoMessageException
 
class  Topic
 Object for <topic x> replacements in condition expressions. More...
 

Public Member Functions

 __init__ (self, args=None, **kwargs)
 
 close_batch (self)
 Clears cached messages.
 
 conditions_get_topics (self)
 Returns a list of all topics used in conditions (may contain wildcards).
 
 conditions_register_message (self, topic, msg)
 Retains message for condition evaluation if in condition topic.
 
 conditions_set_topic_state (self, topic, pure)
 Sets whether topic is purely used for conditions not matching.
 
 has_conditions (self)
 Returns whether there are any conditions configured.
 
 is_conditions_topic (self, topic, pure=True)
 Returns whether topic is used for checking condition.
 
 is_processable (self, topic, msg, stamp, index=None)
 Returns whether message passes passes current state conditions, if any.
 
 validate (self)
 Returns whether conditions have valid syntax, sets options, prints errors.
 

Public Attributes

 args
 

Static Public Attributes

 DEFAULT_ARGS = dict(CONDITION=())
 Constructor argument defaults.
 
 TOPIC_RGX = re.compile(r"<topic\s+([^\s><]+)\s*>")
 

Detailed Description

Provides topic conditions evaluation.

Evaluates a set of Python expressions, with a namespace of:

  • msg: current message being checked
  • topic: current topic being read
  • <topic /any/name> messages in named or wildcarded topic

<topic ..> gets replaced with an object with the following behavior:

  • len(obj) -> number of messages processed in topic
  • bool(obj) -> whether there are any messages in topic
  • obj[pos] -> topic message at position (from latest if negative, first if positive)
  • obj.x -> attribute x of last message

All conditions need to evaluate as true for a message to be processable. If a condition tries to access attributes of a message not yet present, condition evaluates as false.

If a condition topic matches more than one real topic (by wildcard or by different types in one topic), evaluation is done for each set of topics separately, condition passing if any set passes.

Example <topic */control_enable>.data and <topic */cmd_vel>.linear.x > 0 and <topic */cmd_vel>.angular.z < 0.02.

Definition at line 286 of file inputs.py.

Constructor & Destructor Documentation

◆ __init__()

__init__ (   self,
  args = None,
**  kwargs 
)
Parameters
argsarguments as namespace or dictionary, case-insensitive
args.conditionPython expressions that must evaluate as true for message to be processable, see ConditionMixin
kwargsany and all arguments as keyword overrides, case-insensitive

Reimplemented in BagSource, LiveSource, and AppSource.

Definition at line 375 of file inputs.py.

Member Function Documentation

◆ close_batch()

close_batch (   self)

Clears cached messages.

Reimplemented in BagSource.

Definition at line 436 of file inputs.py.

◆ conditions_get_topics()

conditions_get_topics (   self)

Returns a list of all topics used in conditions (may contain wildcards).

Definition at line 445 of file inputs.py.

◆ conditions_register_message()

conditions_register_message (   self,
  topic,
  msg 
)

Retains message for condition evaluation if in condition topic.

Definition at line 467 of file inputs.py.

◆ conditions_set_topic_state()

conditions_set_topic_state (   self,
  topic,
  pure 
)

Sets whether topic is purely used for conditions not matching.

Definition at line 462 of file inputs.py.

◆ has_conditions()

has_conditions (   self)

Returns whether there are any conditions configured.

Definition at line 441 of file inputs.py.

◆ is_conditions_topic()

is_conditions_topic (   self,
  topic,
  pure = True 
)

Returns whether topic is used for checking condition.

Parameters
purewhether use should be solely for condition, not for matching at all

Definition at line 454 of file inputs.py.

◆ is_processable()

is_processable (   self,
  topic,
  msg,
  stamp,
  index = None 
)

Returns whether message passes passes current state conditions, if any.

Reimplemented in BagSource, LiveSource, and AppSource.

Definition at line 389 of file inputs.py.

◆ validate()

validate (   self)

Returns whether conditions have valid syntax, sets options, prints errors.

Reimplemented in BagSource, LiveSource, and AppSource.

Definition at line 417 of file inputs.py.

Member Data Documentation

◆ args

args

Definition at line 433 of file inputs.py.

◆ DEFAULT_ARGS

DEFAULT_ARGS = dict(CONDITION=())
static

Constructor argument defaults.

Definition at line 291 of file inputs.py.

◆ TOPIC_RGX

TOPIC_RGX = re.compile(r"<topic\s+([^\s><]+)\s*>")
static

Definition at line 288 of file inputs.py.


The documentation for this class was generated from the following file: