ros_state_machine.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 import rospy
3 from flexbe_core.proxy import ProxyPublisher, ProxySubscriberCached
4 
5 from flexbe_core.core.state_machine import StateMachine
6 
7 
9  """
10  A state machine to interface with ROS.
11  """
12 
13  def __init__(self, *args, **kwargs):
14  super(RosStateMachine, self).__init__(*args, **kwargs)
15  self._is_controlled = False
16 
17  self._pub = ProxyPublisher()
18  self._sub = ProxySubscriberCached()
19 
20  def wait(self, seconds=None, condition=None):
21  if seconds is not None:
22  rospy.sleep(seconds)
23  if condition is not None:
24  rate = rospy.Rate(100)
25  while not rospy.is_shutdown():
26  if condition():
27  break
28  rate.sleep()
29 
31  self._is_controlled = True
32  for state in self._states:
33  state._enable_ros_control()
34 
36  self._is_controlled = False
37  for state in self._states:
38  state._disable_ros_control()
def wait(self, seconds=None, condition=None)


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