objectdetection_tf_publisher.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 import rospy
3 import roslib
4 roslib.load_manifest("posedetection_msgs")
5 roslib.load_manifest("dynamic_tf_publisher")
6 from posedetection_msgs.msg import ObjectDetection
7 from geometry_msgs.msg import Transform
8 from geometry_msgs.msg import PoseStamped
9 from dynamic_tf_publisher.srv import *
10 import tf
11 
13  def __init__(self):
14 
15  if rospy.get_param('~use_simple_tf', False):
17  self.subscriber = rospy.Subscriber("ObjectDetection", ObjectDetection, self.simple_callback);
18  else:
20  self.frame_id = rospy.get_param("~frame_id", "object")
21  self.subscriber = rospy.Subscriber("ObjectDetection", ObjectDetection, self.callback);
22 
24  if rospy.has_param('~checker_board_params/position_x'):
25  position_x = rospy.get_param('~checker_board_params/position_x', 0)
26  position_y = rospy.get_param('~checker_board_params/position_y', 0)
27  position_z = rospy.get_param('~checker_board_params/position_z', 0)
28  orientation_x = rospy.get_param('~checker_board_params/orientation_x', 0)
29  orientation_y = rospy.get_param('~checker_board_params/orientation_y', 0)
30  orientation_z = rospy.get_param('~checker_board_params/orientation_z', 0)
31  orientation_w = rospy.get_param('~checker_board_params/orientation_w', 0)
32  rospy.loginfo("objectdetection_tf_publisher load the calibration params :")
33  rospy.loginfo(" pos : %f %f %f orientation %f %f %f %f", position_x, position_y, position_z, orientation_x, orientation_y, orientation_z, orientation_w)
34 
35  self.send_dynamic_tf_request(position_x, position_y, position_z,
36  orientation_x,orientation_y,orientation_z,orientation_w,
37  rospy.get_param('~checker_board_params/header_frame'),
38  self.frame_id
39  )
40  else:
41  rospy.loginfo("No parameters (~checker_board_params) was found for object detection")
42 
43  def simple_callback(self, msg):
44  if msg.objects:
45  for detected_object in msg.objects:
46  self.br.sendTransform((detected_object.pose.position.x, detected_object.pose.position.y, detected_object.pose.position.z),
47  (detected_object.pose.orientation.x, detected_object.pose.orientation.y, detected_object.pose.orientation.z, detected_object.pose.orientation.w),
48  msg.header.stamp,
49  detected_object.type,
50  msg.header.frame_id)
51 
52  def callback(self, msg):
53  if msg.objects:
54  for detected_object in msg.objects:
56  detected_object.pose.position.x,
57  detected_object.pose.position.y,
58  detected_object.pose.position.z,
59  detected_object.pose.orientation.x,
60  detected_object.pose.orientation.y,
61  detected_object.pose.orientation.z,
62  detected_object.pose.orientation.w,
63  msg.header.frame_id,
64  self.frame_id
65  )
66 
67  def send_dynamic_tf_request(self, pos_x, pos_y, pos_z, ori_x, ori_y, ori_z, ori_w, parent_frame_id, child_frame_id):
68  transform = Transform()
69  transform.translation.x = pos_x
70  transform.translation.y = pos_y
71  transform.translation.z = pos_z
72  transform.rotation.x = ori_x
73  transform.rotation.y = ori_y
74  transform.rotation.z = ori_z
75  transform.rotation.w = ori_w
76 
77  set_tf_request = SetDynamicTFRequest()
78  set_tf_request.freq = 10
79  set_tf_request.cur_tf.header.stamp = rospy.get_rostime()
80  set_tf_request.cur_tf.header.frame_id = parent_frame_id
81  set_tf_request.cur_tf.child_frame_id = child_frame_id
82  set_tf_request.cur_tf.transform = transform
83 
84  rospy.wait_for_service('/set_dynamic_tf')
85  set_dynamic_tf = rospy.ServiceProxy('/set_dynamic_tf', SetDynamicTF)
86  try:
87  res = set_dynamic_tf(set_tf_request)
88  except rospy.ServiceException as exc:
89  print(("Service did not process request: " + str(exc)))
90 
91 if __name__== '__main__':
92  rospy.init_node('objectdetection_tf_publisher', anonymous=True)
93  object_detection_tf_publisher = ObjectDetectionTfPublisher()
94  rospy.spin()
def send_dynamic_tf_request(self, pos_x, pos_y, pos_z, ori_x, ori_y, ori_z, ori_w, parent_frame_id, child_frame_id)
RaveTransform< dReal > Transform
Definition: math.h:444


checkerboard_detector
Author(s): Rosen Diankov (rdiankov@cs.cmu.edu)
autogenerated on Mon May 3 2021 03:03:00