Go to the documentation of this file.00001
00002 import numpy as np, math
00003 import copy
00004 import roslib; roslib.load_manifest('equilibrium_point_control')
00005 import rospy
00006 from std_msgs.msg import Bool
00007
00008
00009
00010
00011
00012
00013
00014 class EPGenerator(object):
00015
00016
00017
00018
00019
00020
00021 def generate_ep(self):
00022 raise RuntimeError('Unimplemented Function')
00023
00024
00025
00026
00027 def control_ep(self, ep):
00028 raise RuntimeError('Unimplemented Function')
00029
00030
00031
00032
00033
00034
00035 def clamp_ep(self, ep):
00036 return ep
00037
00038
00039
00040
00041
00042 def terminate_check(self):
00043 return EPStopConditions.CONTINUE
00044
00045
00046
00047
00048 class EPStopConditions:
00049 CONTINUE = ''
00050 ROSPY_SHUTDOWN = 'rospy shutdown'
00051 ROS_STOP = 'stop_command_over_ROS'
00052 TIMEOUT = 'timed out'
00053 RESET_TIMING = 'reset timing'
00054 SUCCESSFUL = 'epc motion successful'
00055 COLLISION = 'collision detected'
00056
00057
00058
00059 class EPC(object):
00060
00061
00062
00063 def __init__(self, epc_name = 'epc'):
00064 self.epc_name = epc_name
00065 self.stop_epc = False
00066 self.pause_epc = False
00067 rospy.Subscriber('/'+epc_name+'/stop', Bool, self._stop_cb)
00068 rospy.Subscriber('/'+epc_name+'/pause', Bool, self._pause_cb)
00069
00070
00071
00072 def _stop_cb(self, msg):
00073 self.stop_epc = msg.data
00074 self.pause_epc = False
00075
00076
00077
00078 def _pause_cb(self, msg):
00079 self.pause_epc = msg.data
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091 def epc_motion(self, ep_gen, time_step, timeout=np.inf):
00092 rospy.loginfo("[epc] epc_motion started")
00093 timeout_at = rospy.get_time() + timeout
00094 stop = EPStopConditions.CONTINUE
00095 ea = None
00096 while True:
00097
00098 if rospy.is_shutdown():
00099 stop = EPStopConditions.ROSPY_SHUTDOWN
00100 break
00101
00102
00103 if self.stop_epc:
00104 stop = EPStopConditions.ROS_STOP
00105 break
00106
00107
00108 stop = ep_gen.terminate_check()
00109 if stop != EPStopConditions.CONTINUE:
00110 break
00111
00112
00113 if self.pause_epc:
00114 rospy.sleep(0.1)
00115 timeout_at += 0.101
00116 continue
00117
00118
00119 if timeout_at < rospy.get_time():
00120 stop = EPStopConditions.TIMEOUT
00121 break
00122
00123
00124 stop, ep = ep_gen.generate_ep()
00125 if stop != EPStopConditions.CONTINUE:
00126 break
00127
00128
00129 ep = ep_gen.clamp_ep(ep)
00130
00131
00132 ep_gen.control_ep(ep)
00133
00134 rospy.sleep(time_step)
00135
00136 rospy.loginfo("[epc] epc_motion stopped with termination condition: %s" % stop)
00137 return stop, ea
00138
00139