src
flexbe_states
check_condition_state.py
Go to the documentation of this file.
1
#!/usr/bin/env python
2
from
flexbe_core
import
EventState, Logger
3
4
5
class
CheckConditionState
(EventState):
6
'''
7
Checks if the given condition is true and returns the corresponding outcome.
8
This state can be used if the further control flow of the behavior depends on a simple condition.
9
10
-- predicate function The condition whose truth value will be evaluated.
11
Has to expect one parameter which will be set to input_value and return a boolean.
12
13
># input_value object Input to the predicate function.
14
15
<= true Returned if the condition evaluates to True
16
<= false Returned if the condition evaluates to False
17
'''
18
19
def
__init__
(self, predicate):
20
super(CheckConditionState, self).
__init__
(outcomes=[
'true'
,
'false'
],
21
input_keys=[
'input_value'
])
22
self.
_predicate
= predicate
23
self.
_outcome
=
'false'
24
25
def
execute
(self, userdata):
26
return
self.
_outcome
27
28
def
on_enter
(self, userdata):
29
try
:
30
self.
_outcome
=
'true'
if
self.
_predicate
(userdata.input_value)
else
'false'
31
except
Exception
as
e:
32
Logger.logwarn(
'Failed to execute condition function!\n%s'
% str(e))
flexbe_states.check_condition_state.CheckConditionState.on_enter
def on_enter(self, userdata)
Definition:
check_condition_state.py:28
flexbe_states.check_condition_state.CheckConditionState.__init__
def __init__(self, predicate)
Definition:
check_condition_state.py:19
flexbe_states.check_condition_state.CheckConditionState._predicate
_predicate
Definition:
check_condition_state.py:22
flexbe_states.check_condition_state.CheckConditionState
Definition:
check_condition_state.py:5
flexbe_states.check_condition_state.CheckConditionState._outcome
_outcome
Definition:
check_condition_state.py:23
flexbe_states.check_condition_state.CheckConditionState.execute
def execute(self, userdata)
Definition:
check_condition_state.py:25
flexbe_states
Author(s): Philipp Schillinger
autogenerated on Fri Jul 21 2023 02:26:17