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 
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
Author(s): Philipp Schillinger
autogenerated on Wed Jun 5 2019 21:51:59