38 import roslib; roslib.load_manifest(
'velma_task_cs_ros_interface')
46 from velma_look_at_action_msgs.msg
import LookAtAction, LookAtFeedback, LookAtResult
53 if not points
is None:
69 elif x > pt[0]
and x < self.
__points__[idx+1][0]:
72 elif x == pt[0]
or x == self.
__points__[idx+1][0]:
73 raise Exception(
'Added point with the same x twice')
78 raise Exception(
'Could not interpolate the function with only one point')
81 raise Exception(
'x is below the domain range')
86 elif x >= pt[0]
and x <= self.
__points__[idx+1][0]:
87 f = (x - pt[0]) / (self.
__points__[idx+1][0] - pt[0])
88 return (1.0-f) * pt[1] + f * self.
__points__[idx+1][1]
89 raise Exception(
'x is above the domain range: ' + str(x) +
', points: ' + str(self.
__points__))
93 yaw = math.atan2( pt.y, pt.x ) - torso_angle
96 xy_dist = math.sqrt( pt.x**2 + pt.y**2 )
98 pitch = -math.atan2( pt.z - head_z, xy_dist )
103 horizontal_fov = 1.047
104 horizontal_fov_margin = math.radians(10.0)
105 head_pan_limits = [-1.56, 1.56]
108 (head_pan_limits[0] - horizontal_fov + horizontal_fov_margin, 0),
109 (head_pan_limits[0], 1),
110 (head_pan_limits[1], 1),
111 (head_pan_limits[1] + horizontal_fov - horizontal_fov_margin, 0),
113 return func.interpolate( head_q[0] )
117 __feedback = LookAtFeedback()
118 __result = LookAtResult()
125 print(
'VelmaLookAtAction: Waiting for VelmaInterface initialization...')
126 if not self.
__velma.waitForInit(timeout_s=10.0):
128 print(
'VelmaLookAtAction: Could not initialize VelmaInterface')
131 print(
'VelmaLookAtAction: Initialization of VelmaInterface ok!')
140 print(
'VelmaLookAtAction: Initialization of action server ok!')
141 print(
'VelmaLookAtAction: Action name: {}'.format(self.
__action_name))
144 return not self.
__velma is None 156 print(
'VelmaLookAtAction: Received a new goal: {} ({}, {}, {})'.format(goal.frame_id,
157 goal.target.x, goal.target.y, goal.target.z))
159 assert goal.frame_id ==
'torso_base' 161 js = self.
__velma.getLastJointState()
173 self.
__result.error_code = LookAtResult.OUT_OF_RANGE
174 print(
'VelmaLookAtAction: rejected goal: OUT_OF_RANGE')
178 diag = self.
__velma.getCoreCsDiag()
179 if (
not diag.inStateCartImp())
and (
not diag.inStateJntImp()):
180 self.
__result.error_code = LookAtResult.WRONG_BEHAVIOUR
181 print(
'VelmaLookAtAction: rejected goal: WRONG_BEHAVIOUR')
190 dist = max( abs( js[1][
'head_pan_joint']-head_q[0] ), abs(js[1][
'head_tilt_joint']-head_q[1]) )
192 time = dist / max_vel
193 self.
__velma.moveHead(head_q, time, start_time=0.5)
194 while not rospy.is_shutdown():
195 result = self.
__velma.waitForHead(timeout_s=0.1)
196 if not result
is None:
200 self.
__result.error_code = LookAtResult.MOTION_FAILED
201 print(
'VelmaLookAtAction: aborted: MOTION_FAILED')
205 if self.
__as.is_preempt_requested():
207 js = self.
__velma.getLastJointState()
208 print "js: ", js[1][
'head_pan_joint'],js[1][
'head_tilt_joint']
211 self.
__velma.moveHead((js[1][
'head_pan_joint'],js[1][
'head_tilt_joint']), time, start_time=0.01)
212 while not rospy.is_shutdown():
213 result = self.
__velma.waitForHead(timeout_s=0.1)
214 if not result
is None:
218 self.
__result.error_code = LookAtResult.MOTION_FAILED
219 print(
'VelmaLookAtAction: aborted: MOTION_FAILED')
222 self.
__result.error_code = LookAtResult.CANCELLED
228 self.
__result.error_code = LookAtResult.SUCCESSFUL
229 print(
'VelmaLookAtAction: reached the goal: SUCCESSFUL')
232 if __name__ ==
'__main__':
241 rospy.init_node(
'velma_look_at_action')
def calculateViewQuality(head_q)
def execute_cb(self, goal)
def __init__(self, points=None)
def addPoint(self, x, val)
ROS-based, Python interface class for WUT Velma Robot.
def simplifiedHeadIK(torso_angle, pt)