Python geometry_msgs.msg.TransformStamped() Examples
The following are 20
code examples of geometry_msgs.msg.TransformStamped().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
geometry_msgs.msg
, or try the search function
.
Example #1
Source File: tf_bag.py From tf_bag with GNU Lesser General Public License v3.0 | 6 votes |
def replicateTransformOverTime(self, transf, orig_frame, dest_frame, frequency, start_time=None, end_time=None): """ Adds a new transform to the graph with the specified value This can be useful to add calibration a-posteriori. :param transf: value of the transform :param orig_frame: the source tf frame of the transform of interest :param dest_frame: the target tf frame of the transform of interest :param frequency: frequency at which the transform should be published :param start_time: the time the transform should be published from :param end_time: the time the transform should be published until :return: """ if start_time is None: start_time = self.getStartTime() if end_time is None: end_time = self.getEndTime() transl, quat = transf time_delta = rospy.Duration(1 / frequency) t_msg = TransformStamped(header=Header(frame_id=orig_frame), child_frame_id=dest_frame, transform=Transform(translation=Vector3(*transl), rotation=Quaternion(*quat))) def createMsg(time_nsec): time = rospy.Time(time_nsec / 1000000000) t_msg2 = copy.deepcopy(t_msg) t_msg2.header.stamp = time return t_msg2 new_msgs = [createMsg(t) for t in range(start_time.to_nsec(), end_time.to_nsec(), time_delta.to_nsec())] self.tf_messages += new_msgs self.tf_messages.sort(key=lambda tfm: tfm.header.stamp.to_nsec()) self.tf_times = np.array(list((tfm.header.stamp.to_nsec() for tfm in self.tf_messages))) self.all_transform_tuples.add((orig_frame, dest_frame))
Example #2
Source File: transforms.py From ggcnn_kinova_grasping with BSD 3-Clause "New" or "Revised" License | 6 votes |
def publish_pose_as_transform(pose, reference_frame, name, seconds=1): """ Publish a pose as a transform so that it is visualised in rviz. pose -> A geometry_msgs.msg/Pose to be converted into a transform and published reference_frame -> A string defining the reference_frame of the pose name -> A string defining the child frame of the transform seconds -> An int32 that defines the duration the transform will be broadcast for """ # Create a broadcast node and a stamped transform to broadcast br = tf2_ros.TransformBroadcaster() t = gmsg.TransformStamped() # Prepare broadcast message t.header.frame_id = reference_frame t.child_frame_id = name # Copy in pose values to transform t.transform.translation = pose.position t.transform.rotation = pose.orientation # Call the publish_stamped_transform function publish_stamped_transform(t, seconds)
Example #3
Source File: actor.py From ros-bridge with MIT License | 6 votes |
def get_ros_transform(self, transform=None, frame_id=None, child_frame_id=None): """ Function to provide the current ROS transform :return: the ROS transfrom :rtype: geometry_msgs.msg.TransformStamped """ tf_msg = TransformStamped() if frame_id: tf_msg.header = self.get_msg_header(frame_id) else: tf_msg.header = self.get_msg_header("map") if child_frame_id: tf_msg.child_frame_id = child_frame_id else: tf_msg.child_frame_id = self.get_prefix() if transform: tf_msg.transform = transform else: tf_msg.transform = trans.carla_transform_to_ros_transform( self.carla_actor.get_transform()) return tf_msg
Example #4
Source File: tf_helpers.py From mvp_grasp with BSD 3-Clause "New" or "Revised" License | 6 votes |
def publish_stamped_transform(stamped_transform, seconds=1): """ Publish a stamped transform for debugging purposes. stamped_transform -> A geometry_msgs/TransformStamped to be published seconds -> An int32 that defines the duration the transform will be broadcast for """ # Create broadcast node br = tf2_ros.TransformBroadcaster() # Publish once first. stamped_transform.header.stamp = rospy.Time.now() br.sendTransform(stamped_transform) # Publish transform for set time. i = 0 iterations = seconds/0.05 while not rospy.is_shutdown() and i < iterations: stamped_transform.header.stamp = rospy.Time.now() br.sendTransform(stamped_transform) rospy.sleep(0.05) i += 1
Example #5
Source File: tf_helpers.py From mvp_grasp with BSD 3-Clause "New" or "Revised" License | 6 votes |
def publish_pose_as_transform(pose, reference_frame, name, seconds=1): """ Publish a pose as a transform so that it is visualised in rviz. pose -> A geometry_msgs.msg/Pose to be converted into a transform and published reference_frame -> A string defining the reference_frame of the pose name -> A string defining the child frame of the transform seconds -> An int32 that defines the duration the transform will be broadcast for """ # Create a broadcast node and a stamped transform to broadcast t = gmsg.TransformStamped() # Prepare broadcast message t.header.frame_id = reference_frame t.child_frame_id = name # Copy in pose values to transform t.transform.translation = pose.position t.transform.rotation = pose.orientation # Call the publish_stamped_transform function publish_stamped_transform(t, seconds)
Example #6
Source File: localization.py From naoqi_bridge with BSD 3-Clause "New" or "Revised" License | 5 votes |
def get_navigation_tf(self, navigation_pose): navigation_tf = TransformStamped() navigation_tf.header.frame_id = "/map" navigation_tf.header.stamp = rospy.Time.now() navigation_tf.child_frame_id = "/odom" navigation_tf.transform.translation .x = navigation_pose.x navigation_tf.transform.translation .y = navigation_pose.y navigation_tf.transform.rotation = self.get_ros_quaternion( almath.Quaternion_fromAngleAndAxisRotation(navigation_pose.theta, 0, 0, 1)) return navigation_tf
Example #7
Source File: kitti2bag.py From SARosPerceptionKitti with MIT License | 5 votes |
def get_static_transform(from_frame_id, to_frame_id, transform): t = transform[0:3, 3] q = tf.transformations.quaternion_from_matrix(transform) tf_msg = TransformStamped() tf_msg.header.frame_id = from_frame_id tf_msg.child_frame_id = to_frame_id tf_msg.transform.translation.x = float(t[0]) tf_msg.transform.translation.y = float(t[1]) tf_msg.transform.translation.z = float(t[2]) tf_msg.transform.rotation.x = float(q[0]) tf_msg.transform.rotation.y = float(q[1]) tf_msg.transform.rotation.z = float(q[2]) tf_msg.transform.rotation.w = float(q[3]) return tf_msg
Example #8
Source File: ros_wrapper.py From qibullet with Apache License 2.0 | 5 votes |
def _broadcastOdometry(self, odometry_publisher): """ INTERNAL METHOD, computes an odometry message based on the robot's position, and broadcast it Parameters: odometry_publisher - The ROS publisher for the odometry message """ # Send Transform odom x, y, theta = self.robot.getPosition() odom_trans = TransformStamped() odom_trans.header.frame_id = "odom" odom_trans.child_frame_id = "base_link" odom_trans.header.stamp = rospy.get_rostime() odom_trans.transform.translation.x = x odom_trans.transform.translation.y = y odom_trans.transform.translation.z = 0 quaternion = pybullet.getQuaternionFromEuler([0, 0, theta]) odom_trans.transform.rotation.x = quaternion[0] odom_trans.transform.rotation.y = quaternion[1] odom_trans.transform.rotation.z = quaternion[2] odom_trans.transform.rotation.w = quaternion[3] self.transform_broadcaster.sendTransform(odom_trans) # Set up the odometry odom = Odometry() odom.header.stamp = rospy.get_rostime() odom.header.frame_id = "odom" odom.pose.pose.position.x = x odom.pose.pose.position.y = y odom.pose.pose.position.z = 0.0 odom.pose.pose.orientation = odom_trans.transform.rotation odom.child_frame_id = "base_link" [vx, vy, vz], [wx, wy, wz] = pybullet.getBaseVelocity( self.robot.getRobotModel(), self.robot.getPhysicsClientId()) odom.twist.twist.linear.x = vx odom.twist.twist.linear.y = vy odom.twist.twist.angular.z = wz odometry_publisher.publish(odom)
Example #9
Source File: kitti2bag.py From kitti2bag with MIT License | 5 votes |
def get_static_transform(from_frame_id, to_frame_id, transform): t = transform[0:3, 3] q = tf.transformations.quaternion_from_matrix(transform) tf_msg = TransformStamped() tf_msg.header.frame_id = from_frame_id tf_msg.child_frame_id = to_frame_id tf_msg.transform.translation.x = float(t[0]) tf_msg.transform.translation.y = float(t[1]) tf_msg.transform.translation.z = float(t[2]) tf_msg.transform.rotation.x = float(q[0]) tf_msg.transform.rotation.y = float(q[1]) tf_msg.transform.rotation.z = float(q[2]) tf_msg.transform.rotation.w = float(q[3]) return tf_msg
Example #10
Source File: handeye_calibration.py From easy_handeye with GNU Lesser General Public License v3.0 | 5 votes |
def from_dict(self, in_dict): """ Sets values parsed from a given dictionary. :param in_dict: input dictionary. :type in_dict: dict[string, string|dict[string,float]] :rtype: None """ self.eye_on_hand = in_dict['eye_on_hand'] self.transformation = TransformStamped( child_frame_id=in_dict['tracking_base_frame'], transform=Transform( Vector3(in_dict['transformation']['x'], in_dict['transformation']['y'], in_dict['transformation']['z']), Quaternion(in_dict['transformation']['qx'], in_dict['transformation']['qy'], in_dict['transformation']['qz'], in_dict['transformation']['qw']) ) ) if self.eye_on_hand: self.transformation.header.frame_id = in_dict['robot_effector_frame'] else: self.transformation.header.frame_id = in_dict['robot_base_frame']
Example #11
Source File: transforms.py From ggcnn_kinova_grasping with BSD 3-Clause "New" or "Revised" License | 5 votes |
def publish_stamped_transform(stamped_transform, seconds=1): """ Publish a stamped transform for debugging purposes. stamped_transform -> A geometry_msgs/TransformStamped to be published seconds -> An int32 that defines the duration the transform will be broadcast for """ # Create broadcast node br = tf2_ros.TransformBroadcaster() # Publish once first. stamped_transform.header.stamp = rospy.Time.now() br.sendTransform(stamped_transform) # Publish transform for set time. i = 0 iterations = seconds/0.05 while not rospy.is_shutdown() and i < iterations: stamped_transform.header.stamp = rospy.Time.now() br.sendTransform(stamped_transform) rospy.sleep(0.05) i += 1
Example #12
Source File: costar_hyper_prediction.py From costar_plan with Apache License 2.0 | 5 votes |
def main(_): """ Main function, starts predictor. """ print('main') rospy.init_node('costar_hyper_prediction') predictor = CostarHyperPosePredictor() broadcaster = tf2.TransformBroadcaster() transform_name = 'predicted_goal_' + predictor.ee_frame rospy.loginfo('costar_hyper_prediction transform predictions will be broadcast as: ' + str(transform_name)) update_rate = 0.25 rate = rospy.Rate(update_rate) progbar = tqdm() while not rospy.is_shutdown(): rate.sleep() start_time = time.clock() prediction_xyz_qxyzw, prediction_input_data_time = predictor() tick_time = time.clock() b_to_e = TransformStamped() b_to_e.header.stamp = prediction_input_data_time b_to_e.header.frame_id = predictor.base_link b_to_e.child_frame_id = transform_name b_to_e.transform.translation.x = prediction_xyz_qxyzw[0] b_to_e.transform.translation.y = prediction_xyz_qxyzw[1] b_to_e.transform.translation.z = prediction_xyz_qxyzw[2] b_to_e.transform.rotation.x = prediction_xyz_qxyzw[3] b_to_e.transform.rotation.y = prediction_xyz_qxyzw[4] b_to_e.transform.rotation.z = prediction_xyz_qxyzw[5] b_to_e.transform.rotation.w = prediction_xyz_qxyzw[6] broadcaster.sendTransform(b_to_e) update_time = time.clock() # figure out where the time has gone time_str = ('Total tick + log time: {:04} sec, ' 'Robot Prediction: {:04} sec, ' 'Sending Results: {:04} sec'.format(update_time - start_time, tick_time - start_time, update_time - tick_time)) verify_update_rate(update_time_remaining=rate.remaining(), update_rate=update_rate, info=time_str) progbar.update()
Example #13
Source File: tf_helpers.py From mvp_grasp with BSD 3-Clause "New" or "Revised" License | 5 votes |
def publish_transform(transform, reference_frame, name, seconds=1): """ Publish a Transform for debugging purposes. transform -> A geometry_msgs/Transform to be published reference_frame -> A string defining the reference frame of the transform seconds -> An int32 that defines the duration the transform will be broadcast for """ # Create a stamped_transform and store the transform in it st = gmsg.TransformStamped() st.transform = transform st.header.frame_id = reference_frame st.child_frame_id = name # Call the publish_stamped_transform function publish_stamped_transform(st, seconds)
Example #14
Source File: grip_manager.py From niryo_one_ros with GNU General Public License v3.0 | 5 votes |
def from_dict(cls, dict_): t = TransformStamped() t.transform.translation.x = dict_["transform"]["translation"][0] t.transform.translation.y = dict_["transform"]["translation"][1] t.transform.translation.z = dict_["transform"]["translation"][2] t.transform.rotation.x = dict_["transform"]["quaternion"][0] t.transform.rotation.y = dict_["transform"]["quaternion"][1] t.transform.rotation.z = dict_["transform"]["quaternion"][2] t.transform.rotation.w = dict_["transform"]["quaternion"][3] t.header.frame_id = dict_["transform"]["header_frame_id"] t.child_frame_id = dict_["transform"]["child_frame_id"] return cls(dict_["name"], t)
Example #15
Source File: transform_handler.py From niryo_one_ros with GNU General Public License v3.0 | 5 votes |
def transform_from_euler(x, y, z, roll, pitch, yaw, header_frame_id, child_frame_id): """ Creates a new stamped transform from translation and euler-orientation :param x: x translation :param y: y translation :param z: z translation :param roll: orientation roll :param pitch: orientation pitch :param yaw: orientation yaw :param header_frame_id: transform from this frame :param child_frame_id: transform to this frame :returns: transform """ t = TransformStamped() t.transform.translation.x = x t.transform.translation.y = y t.transform.translation.z = z q = transformations.quaternion_from_euler(roll, pitch, yaw) t.transform.rotation.x = q[0] t.transform.rotation.y = q[1] t.transform.rotation.z = q[2] t.transform.rotation.w = q[3] t.header.frame_id = header_frame_id t.child_frame_id = child_frame_id return t
Example #16
Source File: transforms.py From ggcnn_kinova_grasping with BSD 3-Clause "New" or "Revised" License | 5 votes |
def publish_transform(transform, reference_frame, name, seconds=1): """ Publish a Transform for debugging purposes. transform -> A geometry_msgs/Transform to be published reference_frame -> A string defining the reference frame of the transform seconds -> An int32 that defines the duration the transform will be broadcast for """ # Create a stamped_transform and store the transform in it st = gmsg.TransformStamped() st.transform = transform st.header.frame_id = reference_frame st.child_frame_id = name # Call the publish_stamped_transform function publish_stamped_transform(st, seconds)
Example #17
Source File: handeye_calibration.py From easy_handeye with GNU Lesser General Public License v3.0 | 4 votes |
def __init__(self, eye_on_hand=False, robot_base_frame=None, robot_effector_frame=None, tracking_base_frame=None, transformation=None): """ Creates a HandeyeCalibration object. :param eye_on_hand: if false, it is a eye-on-base calibration :type eye_on_hand: bool :param robot_base_frame: needed only for eye-on-base calibrations: robot base link tf name :type robot_base_frame: string :param robot_effector_frame: needed only for eye-on-hand calibrations: robot tool tf name :type robot_effector_frame: string :param tracking_base_frame: tracking system tf name :type tracking_base_frame: string :param transformation: transformation between optical origin and base/tool robot frame as tf tuple :type transformation: ((float, float, float), (float, float, float, float)) :return: a HandeyeCalibration object :rtype: easy_handeye.handeye_calibration.HandeyeCalibration """ if transformation is None: transformation = ((0, 0, 0), (0, 0, 0, 1)) self.eye_on_hand = eye_on_hand """ if false, it is a eye-on-base calibration :type: bool """ self.transformation = TransformStamped(transform=Transform( Vector3(*transformation[0]), Quaternion(*transformation[1]))) """ transformation between optical origin and base/tool robot frame :type: geometry_msgs.msg.TransformedStamped """ # tf names if self.eye_on_hand: self.transformation.header.frame_id = robot_effector_frame else: self.transformation.header.frame_id = robot_base_frame self.transformation.child_frame_id = tracking_base_frame self.filename = HandeyeCalibration.DIRECTORY + '/' + rospy.get_namespace().rstrip('/').split('/')[-1] + '.yaml'
Example #18
Source File: kitti2bag.py From kitti2bag with MIT License | 4 votes |
def save_dynamic_tf(bag, kitti, kitti_type, initial_time): print("Exporting time dependent transformations") if kitti_type.find("raw") != -1: for timestamp, oxts in zip(kitti.timestamps, kitti.oxts): tf_oxts_msg = TFMessage() tf_oxts_transform = TransformStamped() tf_oxts_transform.header.stamp = rospy.Time.from_sec(float(timestamp.strftime("%s.%f"))) tf_oxts_transform.header.frame_id = 'world' tf_oxts_transform.child_frame_id = 'base_link' transform = (oxts.T_w_imu) t = transform[0:3, 3] q = tf.transformations.quaternion_from_matrix(transform) oxts_tf = Transform() oxts_tf.translation.x = t[0] oxts_tf.translation.y = t[1] oxts_tf.translation.z = t[2] oxts_tf.rotation.x = q[0] oxts_tf.rotation.y = q[1] oxts_tf.rotation.z = q[2] oxts_tf.rotation.w = q[3] tf_oxts_transform.transform = oxts_tf tf_oxts_msg.transforms.append(tf_oxts_transform) bag.write('/tf', tf_oxts_msg, tf_oxts_msg.transforms[0].header.stamp) elif kitti_type.find("odom") != -1: timestamps = map(lambda x: initial_time + x.total_seconds(), kitti.timestamps) for timestamp, tf_matrix in zip(timestamps, kitti.T_w_cam0): tf_msg = TFMessage() tf_stamped = TransformStamped() tf_stamped.header.stamp = rospy.Time.from_sec(timestamp) tf_stamped.header.frame_id = 'world' tf_stamped.child_frame_id = 'camera_left' t = tf_matrix[0:3, 3] q = tf.transformations.quaternion_from_matrix(tf_matrix) transform = Transform() transform.translation.x = t[0] transform.translation.y = t[1] transform.translation.z = t[2] transform.rotation.x = q[0] transform.rotation.y = q[1] transform.rotation.z = q[2] transform.rotation.w = q[3] tf_stamped.transform = transform tf_msg.transforms.append(tf_stamped) bag.write('/tf', tf_msg, tf_msg.transforms[0].header.stamp)
Example #19
Source File: kitti2bag.py From SARosPerceptionKitti with MIT License | 4 votes |
def save_dynamic_tf(bag, kitti, kitti_type, initial_time): print("Exporting time dependent transformations") if kitti_type.find("raw") != -1: for timestamp, oxts in zip(kitti.timestamps, kitti.oxts): tf_oxts_msg = TFMessage() tf_oxts_transform = TransformStamped() tf_oxts_transform.header.stamp = rospy.Time.from_sec(float(timestamp.strftime("%s.%f"))) tf_oxts_transform.header.frame_id = 'world' tf_oxts_transform.child_frame_id = 'base_link' transform = (oxts.T_w_imu) t = transform[0:3, 3] q = tf.transformations.quaternion_from_matrix(transform) oxts_tf = Transform() oxts_tf.translation.x = t[0] oxts_tf.translation.y = t[1] oxts_tf.translation.z = t[2] oxts_tf.rotation.x = q[0] oxts_tf.rotation.y = q[1] oxts_tf.rotation.z = q[2] oxts_tf.rotation.w = q[3] tf_oxts_transform.transform = oxts_tf tf_oxts_msg.transforms.append(tf_oxts_transform) bag.write('/tf', tf_oxts_msg, tf_oxts_msg.transforms[0].header.stamp) elif kitti_type.find("odom") != -1: timestamps = map(lambda x: initial_time + x.total_seconds(), kitti.timestamps) for timestamp, tf_matrix in zip(timestamps, kitti.T_w_cam0): tf_msg = TFMessage() tf_stamped = TransformStamped() tf_stamped.header.stamp = rospy.Time.from_sec(timestamp) tf_stamped.header.frame_id = 'world' tf_stamped.child_frame_id = 'camera_left' t = tf_matrix[0:3, 3] q = tf.transformations.quaternion_from_matrix(tf_matrix) transform = Transform() transform.translation.x = t[0] transform.translation.y = t[1] transform.translation.z = t[2] transform.rotation.x = q[0] transform.rotation.y = q[1] transform.rotation.z = q[2] transform.rotation.w = q[3] tf_stamped.transform = transform tf_msg.transforms.append(tf_stamped) bag.write('/tf', tf_msg, tf_msg.transforms[0].header.stamp)
Example #20
Source File: transform_handler.py From niryo_one_ros with GNU General Public License v3.0 | 4 votes |
def set_relative_pose_object(self, workspace, x_rel, y_rel, yaw_rel, yaw_center=None): """ Updates the transform base_link -> object_base in local tfBuffer :param workspace: reference workspace object :param x_rel: object base x position relative to workspace :param y_rel: object base y position relative to workspace :param yaw_rel: object base rotation on z relative to workspace :param yaw_center: Avoid over rotation """ position = np.dot(workspace.position_matrix, np.array([x_rel, y_rel, 1])) camera_rotation = transformations.euler_matrix(0, 0, yaw_rel) # Here we correct the object orientation to be similar to base_link if # the object in on the ground. Not neccessarily needed to be honest... convention_rotation = np.array([[0, -1, 0, 0], [-1, 0, 0, 0], [0, 0, -1, 0], [0, 0, 0, 1]]) object_rotation = transformations.concatenate_matrices( workspace.rotation_matrix, camera_rotation, convention_rotation) roll, pitch, yaw = transformations.euler_from_matrix(object_rotation) # Correcting yaw to avoid out of reach targets if yaw_center is not None: if yaw < yaw_center - np.pi / 2: yaw += np.pi elif yaw > yaw_center + np.pi / 2: yaw -= np.pi q = transformations.quaternion_from_euler(roll, pitch, yaw) t = TransformStamped() t.transform.translation.x = position[0] t.transform.translation.y = position[1] t.transform.translation.z = position[2] t.transform.rotation.x = q[0] t.transform.rotation.y = q[1] t.transform.rotation.z = q[2] t.transform.rotation.w = q[3] t.header.frame_id = "base_link" t.child_frame_id = "object_base" self.__tf_buffer.set_transform(t, "default_authority")