state.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 from flexbe_core.core.exceptions import StateError
3 
4 
5 def _remove_duplicates(input_list):
6  output_list = list()
7  for entry in input_list:
8  if entry not in output_list:
9  output_list.append(entry)
10  return output_list
11 
12 
13 class State(object):
14 
15  def __init__(self, *args, **kwargs):
16  self._outcomes = _remove_duplicates(kwargs.get('outcomes', []))
17  io_keys = kwargs.get('io_keys', [])
18  self._input_keys = _remove_duplicates(kwargs.get('input_keys', []) + io_keys)
19  self._output_keys = _remove_duplicates(kwargs.get('output_keys', []) + io_keys)
20  # properties of instances of a state machine
21  self._name = None
22  self._parent = None
23 
24  def execute(self, userdata):
25  pass
26 
27  def sleep(self):
28  pass
29 
30  @property
31  def sleep_duration(self):
32  return 0.
33 
34  @property
35  def outcomes(self):
36  return self._outcomes
37 
38  @property
39  def input_keys(self):
40  return self._input_keys
41 
42  @property
43  def output_keys(self):
44  return self._output_keys
45 
46  # instance properties
47 
48  @property
49  def name(self):
50  return self._name
51 
52  def set_name(self, value):
53  if self._name is not None:
54  raise StateError("Cannot change the name of a state!")
55  else:
56  self._name = value
57 
58  @property
59  def parent(self):
60  return self._parent
61 
62  def set_parent(self, value):
63  if self._parent is not None:
64  raise StateError("Cannot change the parent of a state!")
65  else:
66  self._parent = value
67 
68  @property
69  def path(self):
70  return "" if self.parent is None else self.parent.path + "/" + self.name
def _remove_duplicates(input_list)
Definition: state.py:5
def __init__(self, args, kwargs)
Definition: state.py:15
def set_parent(self, value)
Definition: state.py:62
def set_name(self, value)
Definition: state.py:52
def sleep_duration(self)
Definition: state.py:31
def execute(self, userdata)
Definition: state.py:24


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