Classes | Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes | List of all members
grepros.inputs.ConditionMixin Class Reference
Inheritance diagram for grepros.inputs.ConditionMixin:
Inheritance graph
[legend]

Classes

class  Empty
 
class  Message
 
class  NoMessageException
 
class  Topic
 

Public Member Functions

def __init__ (self, args=None, **kwargs)
 
def close_batch (self)
 
def conditions_get_topics (self)
 
def conditions_register_message (self, topic, msg)
 
def conditions_set_topic_state (self, topic, pure)
 
def has_conditions (self)
 
def is_conditions_topic (self, topic, pure=True)
 
def is_processable (self, topic, msg, stamp, index=None)
 

Static Public Attributes

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

Private Member Functions

def _configure_conditions (self, args)
 
def _get_topic_instance (self, topic, remap=None)
 

Private Attributes

 _conditions
 {condition with <topic x> as get_topic("x"): compiled code object} More...
 
 _firstmsgs
 
 _lastmsgs
 
 _topic_limits
 
 _topic_states
 
 _topics_per_condition
 
 _wildcard_topics
 

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 condition: `<topic */control_enable>.data and <topic */cmd_vel>.linear.x > 0`
                   `and <topic */cmd_vel>.angular.z < 0.02`.

Definition at line 195 of file inputs.py.

Constructor & Destructor Documentation

◆ __init__()

def grepros.inputs.ConditionMixin.__init__ (   self,
  args = None,
**  kwargs 
)
@param   args             arguments as namespace or dictionary, case-insensitive
@param   args.condition   Python expressions that must evaluate as true
                  for message to be processable, see ConditionMixin
@param   kwargs           any and all arguments as keyword overrides, case-insensitive

Reimplemented in grepros.inputs.AppSource, grepros.inputs.TopicSource, and grepros.inputs.BagSource.

Definition at line 302 of file inputs.py.

Member Function Documentation

◆ _configure_conditions()

def grepros.inputs.ConditionMixin._configure_conditions (   self,
  args 
)
private
Parses condition expressions and populates local structures.

Definition at line 407 of file inputs.py.

◆ _get_topic_instance()

def grepros.inputs.ConditionMixin._get_topic_instance (   self,
  topic,
  remap = None 
)
private
Returns Topic() by name.

@param   remap  optional remap dictionary as {topic1: (topic2, typename, typehash)}

Definition at line 392 of file inputs.py.

◆ close_batch()

def grepros.inputs.ConditionMixin.close_batch (   self)
Clears cached messages.

Reimplemented in grepros.inputs.BagSource.

Definition at line 351 of file inputs.py.

◆ conditions_get_topics()

def grepros.inputs.ConditionMixin.conditions_get_topics (   self)
Returns a list of all topics used in conditions (may contain wildcards).

Definition at line 360 of file inputs.py.

◆ conditions_register_message()

def grepros.inputs.ConditionMixin.conditions_register_message (   self,
  topic,
  msg 
)
Retains message for condition evaluation if in condition topic.

Definition at line 382 of file inputs.py.

◆ conditions_set_topic_state()

def grepros.inputs.ConditionMixin.conditions_set_topic_state (   self,
  topic,
  pure 
)
Sets whether topic is purely used for conditions not matching.

Definition at line 377 of file inputs.py.

◆ has_conditions()

def grepros.inputs.ConditionMixin.has_conditions (   self)
Returns whether there are any conditions configured.

Definition at line 356 of file inputs.py.

◆ is_conditions_topic()

def grepros.inputs.ConditionMixin.is_conditions_topic (   self,
  topic,
  pure = True 
)
Returns whether topic is used for checking condition.

@param   pure  whether use should be solely for condition, not for matching at all

Definition at line 364 of file inputs.py.

◆ is_processable()

def grepros.inputs.ConditionMixin.is_processable (   self,
  topic,
  msg,
  stamp,
  index = None 
)
Returns whether message passes passes current state conditions, if any.

Reimplemented in grepros.inputs.AppSource, grepros.inputs.TopicSource, and grepros.inputs.BagSource.

Definition at line 323 of file inputs.py.

Member Data Documentation

◆ _conditions

grepros.inputs.ConditionMixin._conditions
private

{condition with <topic x> as get_topic("x"): compiled code object}

Definition at line 320 of file inputs.py.

◆ _firstmsgs

grepros.inputs.ConditionMixin._firstmsgs
private

Definition at line 313 of file inputs.py.

◆ _lastmsgs

grepros.inputs.ConditionMixin._lastmsgs
private

Definition at line 315 of file inputs.py.

◆ _topic_limits

grepros.inputs.ConditionMixin._topic_limits
private

Definition at line 317 of file inputs.py.

◆ _topic_states

grepros.inputs.ConditionMixin._topic_states
private

Definition at line 309 of file inputs.py.

◆ _topics_per_condition

grepros.inputs.ConditionMixin._topics_per_condition
private

Definition at line 310 of file inputs.py.

◆ _wildcard_topics

grepros.inputs.ConditionMixin._wildcard_topics
private

Definition at line 311 of file inputs.py.

◆ DEFAULT_ARGS

grepros.inputs.ConditionMixin.DEFAULT_ARGS = dict(CONDITION=())
static

Constructor argument defaults.

Definition at line 225 of file inputs.py.

◆ TOPIC_RGX

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

Definition at line 222 of file inputs.py.


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


grepros
Author(s): Erki Suurjaak
autogenerated on Sat Jan 6 2024 03:11:30