preemptable_state_machine.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 from flexbe_core.core.preemptable_state import PreemptableState
3 from flexbe_core.proxy import ProxySubscriberCached
4 
5 from std_msgs.msg import Empty
6 
7 from flexbe_core.core.lockable_state_machine import LockableStateMachine
8 
9 
11  """
12  A state machine that can be preempted.
13  If preempted, the state machine will return the outcome preempted.
14  """
15 
16  _preempted_name = 'preempted'
17 
18  def __init__(self, *args, **kwargs):
19  super(PreemptableStateMachine, self).__init__(*args, **kwargs)
20  # always listen to preempt so that the behavior can be stopped even if unsupervised
21  self._preempt_topic = 'flexbe/command/preempt'
22  self._sub = ProxySubscriberCached({self._preempt_topic: Empty})
23  self._sub.set_callback(self._preempt_topic, self._preempt_cb)
24 
25  def _preempt_cb(self, msg):
26  if not self._is_controlled:
27  PreemptableState.preempt = True
28 
29  @staticmethod
30  def add(label, state, transitions=None, remapping=None):
31  transitions[PreemptableState._preempted_name] = PreemptableStateMachine._preempted_name
32  LockableStateMachine.add(label, state, transitions, remapping)
33 
34  @property
35  def _valid_targets(self):
36  return super(PreemptableStateMachine, self)._valid_targets + [PreemptableStateMachine._preempted_name]


flexbe_core
Author(s): Philipp Schillinger
autogenerated on Sun Dec 13 2020 04:01:39