def callback(request): if not isinstance(request, AddTwoIntsRequest): return a = request.a b = request.b # 业务逻辑处理 c = a + b response = AddTwoIntsResponse() response.sum = c return response
def my_callback(request): h = request.a w = request.b if (h < 10 or w < 10): return AddTwoIntsResponse() global d if (h > w): d = h / float(34) else: d = w / float(34) global pose_result global roll, pitch, yaw orientation_q = pose_result.orientation orientation_list = [ orientation_q.x, orientation_q.y, orientation_q.z, orientation_q.w ] (roll, pitch, yaw) = euler_from_quaternion(orientation_list) bottle_pos = Point() bottle_pos.x = d * math.cos(yaw) + pose_result.position.x bottle_pos.y = d * math.sin(yaw) + pose_result.position.y bottle_pos.z = 0 print("--------------") print("h: " + str(h)) print("w: " + str(w)) print("d: " + str(d)) print("yaw: " + str(yaw)) print("x: " + str(pose_result.position.x)) print("y: " + str(pose_result.position.y)) print("bx: " + str(bottle_pos.x)) print("by: " + str(bottle_pos.y)) global liste th = 2 for pos in liste: if (bottle_pos.x - th < pos.x < bottle_pos.x + th): if (bottle_pos.y - th < pos.y < bottle_pos.y + th): return AddTwoIntsResponse() liste.append(bottle_pos) pub.publish(bottle_pos) return AddTwoIntsResponse()
def handle_request(self, req): if 'cookies' in req._connection_header: print("GOT", req._connection_header['cookies']) self.success = req._connection_header['cookies'] == 'peanut butter' return AddTwoIntsResponse(3)
def handle_add_two_ints(req): print "Returning [%s + %s = %s]" % (req.a, req.b, (req.a + req.b)) return AddTwoIntsResponse(req.a + req.b)