Main Page
Namespaces
Classes
Files
File List
src
flexbe_core
core
preemptable_state_machine.py
Go to the documentation of this file.
1
#!/usr/bin/env python
2
import
rospy
3
4
from
flexbe_core.core.loopback_state_machine
import
LoopbackStateMachine
5
from
flexbe_core.core.preemptable_state
import
PreemptableState
6
7
from
flexbe_core.proxy
import
ProxySubscriberCached
8
from
std_msgs.msg
import
Empty
9
10
11
class
PreemptableStateMachine
(
LoopbackStateMachine
):
12
"""
13
A state machine that can be preempted.
14
If preempted, the state machine will return the outcome preempted.
15
"""
16
17
_preempted_name =
'preempted'
18
19
def
__init__
(self, *args, **kwargs):
20
# add preempted outcome
21
if
len(args) > 0:
22
args[0].append(self.
_preempted_name
)
23
else
:
24
outcomes = kwargs.get(
'outcomes'
, [])
25
outcomes.append(self.
_preempted_name
)
26
kwargs[
'outcomes'
] = outcomes
27
28
super(PreemptableStateMachine, self).
__init__
(*args, **kwargs)
29
30
# always listen to preempt so that the behavior can be stopped even if unsupervised
31
self.
_preempt_topic
=
'flexbe/command/preempt'
32
self.
_sub
= ProxySubscriberCached({self.
_preempt_topic
: Empty})
33
self._sub.set_callback(self.
_preempt_topic
, self.
_preempt_cb
)
34
35
36
def
_preempt_cb
(self, msg):
37
if
not
self.
_is_controlled
:
38
PreemptableState.preempt =
True
flexbe_core.core.preemptable_state_machine.PreemptableStateMachine._preempt_cb
def _preempt_cb(self, msg)
Definition:
preemptable_state_machine.py:36
flexbe_core.core.preemptable_state_machine.PreemptableStateMachine._preempted_name
string _preempted_name
Definition:
preemptable_state_machine.py:17
flexbe_core.core.preemptable_state_machine.PreemptableStateMachine._preempt_topic
_preempt_topic
Definition:
preemptable_state_machine.py:31
flexbe_core.core.loopback_state_machine.LoopbackStateMachine
Definition:
loopback_state_machine.py:7
flexbe_core.core.loopback_state_machine
Definition:
loopback_state_machine.py:1
flexbe_core.core.preemptable_state_machine.PreemptableStateMachine
Definition:
preemptable_state_machine.py:11
flexbe_core.core.preemptable_state
Definition:
preemptable_state.py:1
flexbe_core.core.preemptable_state_machine.PreemptableStateMachine._sub
_sub
Definition:
preemptable_state_machine.py:32
flexbe_core.core.preemptable_state_machine.PreemptableStateMachine.__init__
def __init__(self, args, kwargs)
Definition:
preemptable_state_machine.py:19
flexbe_core.proxy
Definition:
proxy/__init__.py:1
flexbe_core.core.lockable_state_machine.LockableStateMachine._is_controlled
_is_controlled
Definition:
lockable_state_machine.py:23
flexbe_core
Author(s): Philipp Schillinger
autogenerated on Wed Jun 5 2019 21:51:59