3 from __future__
import absolute_import
4 from __future__
import division
5 from __future__
import print_function
8 from termcolor
import colored
10 from geometry_msgs.msg
import PoseStamped
12 from std_srvs.srv
import Trigger
17 delta_x = pose1.position.x - pose2.position.x
18 delta_y = pose1.position.y - pose2.position.y
19 delta_z = pose1.position.z - pose2.position.z
20 delta_pos = np.linalg.norm([delta_x, delta_y, delta_z])
21 delta_x = pose1.orientation.x - pose2.orientation.x
22 delta_y = pose1.orientation.y - pose2.orientation.y
23 delta_z = pose1.orientation.z - pose2.orientation.z
24 delta_w = pose1.orientation.w - pose2.orientation.w
25 delta_ori = np.linalg.norm([delta_x, delta_y, delta_z, delta_w])
26 return delta_pos, delta_ori
32 self.
delta_pos = rospy.get_param(
'~delta_position', 0.03)
33 self.
delta_ori = rospy.get_param(
'~delta_orientation', 0.03)
38 rospy.loginfo(
"Waiting for service '{}'" 39 .format(rospy.resolve_name(
'~trigger')))
40 rospy.wait_for_service(
'~trigger')
41 self.
trigger = rospy.ServiceProxy(
'~trigger', Trigger)
42 self.
timer = rospy.Timer(rospy.Duration(1. / 100),
49 stamp = rospy.Time.now()
51 dst_frame =
'/head_mount_kinect_rgb_optical_frame' 53 self.listener.waitForTransform(src_frame, dst_frame, stamp,
54 timeout=rospy.Duration(1))
55 except Exception
as e:
58 dst_pose = self.listener.lookupTransform(src_frame, dst_frame, stamp)
59 pose_stamped = PoseStamped()
60 pose_stamped.header.frame_id = src_frame
61 pose_stamped.header.stamp = stamp
62 pose_stamped.pose.position.x = dst_pose[0][0]
63 pose_stamped.pose.position.y = dst_pose[0][1]
64 pose_stamped.pose.position.z = dst_pose[0][2]
65 pose_stamped.pose.orientation.x = dst_pose[1][0]
66 pose_stamped.pose.orientation.y = dst_pose[1][1]
67 pose_stamped.pose.orientation.z = dst_pose[1][2]
68 pose_stamped.pose.orientation.w = dst_pose[1][3]
71 delta_saving_pos, delta_saving_ori = np.inf, np.inf
72 vel_pos, vel_ori = 0, 0
75 pose_stamped.pose, self.last_pose_stamped.pose)
76 delta_time = stamp - self.last_pose_stamped.header.stamp
77 vel_pos = delta_pos / delta_time.to_sec()
78 vel_ori = delta_ori / delta_time.to_sec()
81 pose_stamped.pose, self.last_saved_pose_stamped.pose)
85 logging_msg = (
'delta_saving_pos: {}, delta_saving_ori: {}, ' 86 'vel_pos: {}, vel_ori: {}' 87 .format(delta_saving_pos,
88 delta_saving_ori, vel_pos, vel_ori))
94 rospy.loginfo(logging_msg)
95 rospy.loginfo(colored(
'Sending saving result',
'blue'))
97 rospy.loginfo(colored(
'Saving request result success: {}' 99 'green' if res.success
else 'red'))
103 rospy.loginfo_throttle(1, logging_msg)
107 rospy.init_node(
'camera_coords_change_trigger')
112 if __name__ ==
'__main__':
def timer_callback(self, event)
def compute_pose_delta(pose1, pose2)