6 from .logger
import Logger
10 """ Interface to states and behaviors that are subject to testing. """ 13 package = __import__(path, fromlist=[path])
14 clsmembers = inspect.getmembers(package,
lambda member: (
15 inspect.isclass(member)
and member.__module__ == package.__name__
17 self.
_class = next(c
for name, c
in clsmembers
if name == classname)
22 return issubclass(self.
_class, EventState)
25 return "state" if self.
is_state()
else "behavior" 34 Logger.print_positive(
'%s instantiated' % self.
get_base_name())
40 return self.
_class(**params)
44 if params
is not None:
45 for name, value
in params.items():
46 be.set_parameter(name, value)
47 be.set_up(id=0, autonomy_level=255, debug=
False)
52 def execute(self, userdata, spin_cb=None):
53 spin_cb = spin_cb
or (
lambda:
None)
58 Logger.print_positive(
'finished %s execution' % self.
get_base_name())
62 self._instance.on_start()
64 while outcome
is None and not rospy.is_shutdown():
65 outcome = self._instance.execute(userdata)
66 self._instance.sleep()
68 self._instance.on_stop()
72 self._instance.prepare_for_execution(userdata._data)
73 self._instance.confirm()
77 sm = self._instance._state_machine
78 while outcome
is None and not rospy.is_shutdown():
79 outcome = sm.execute(userdata)
def _execute_state(self, userdata, spin_cb)
def execute(self, userdata, spin_cb=None)
def _execute_behavior(self, userdata, spin_cb)
def instantiate(self, params=None)
def _instantiate_state(self, params=None)
def __init__(self, path, classname)
def _instantiate_behavior(self, params=None)