我们从Python开源项目中,提取了以下23个代码示例,用于说明如何使用tf.Exception()。
def get_odom(self): # Get the current transform between the odom and base frames try: (trans, rot) = self.tf_listener.lookupTransform(self.odom_frame, self.base_frame, rospy.Time(0)) except (tf.Exception, tf.ConnectivityException, tf.LookupException): rospy.loginfo("TF Exception") return return (Point(*trans), quat_to_angle(Quaternion(*rot)))
def get_position(self): # Get the current transform between the odom and base frames try: (trans, rot) = self.tf_listener.lookupTransform(self.odom_frame, self.base_frame, rospy.Time(0)) except (tf.Exception, tf.ConnectivityException, tf.LookupException): rospy.loginfo("TF Exception") return return Point(*trans)
def get_odom_angle(self): # Get the current transform between the odom and base frames try: (trans, rot) = self.tf_listener.lookupTransform(self.odom_frame, self.base_frame, rospy.Time(0)) except (tf.Exception, tf.ConnectivityException, tf.LookupException): rospy.loginfo("TF Exception") return # Convert the rotation from a quaternion to an Euler angle return quat_to_angle(Quaternion(*rot))
def range_cb(self, rng): self.ranges[rng.header.frame_id] = rng.range if len(self.tag_order) < len(self.tag_range_topics): self.tag_order.append(rng.header.frame_id) try: (trans, _) = self.listener.lookupTransform( self.frame_id, rng.header.frame_id, rospy.Time(0)) self.tag_pos[rng.header.frame_id] = np.array(trans[:3]) self.uwb_state[len(self.tag_order)-1, :] = \ np.array([trans[0], trans[1], trans[2], 0, 0, 0]) except tf.Exception: return
def get_position(self): try: (trans,rot) = self.tf_listener.lookupTransform(self.odom_frame, self.base_frame, rospy.Time(0)) except (tf.Exception, tf.ConnectivityException, tf.lookupException): rospy.loginfo("TF Exception") return return Point(*trans)
def get_odom_angle(self): try: (trans, rot) = self.tf_listener.lookupTransform(self.odom_frame, self.base_frame, rospy.Time(0)) except (tf.Exception, tf.ConnectivityException, tf.LookupException): rospy.loginfo("TF Exception") return "succeeded" return self.quat_to_angle(Quaternion(*rot))
def get_odom_angle(self): try: (trans, rot) = self.tf_listener.lookupTransform(self.odom_frame, self.base_frame, rospy.Time(0)) except (tf.Exception, tf.ConnectivityException, tf.LookupException): rospy.loginfo("TF Exception") return return self.quat_to_angle(Quaternion(*rot))
def save_transforms(self): transformations = {} for frame in self.frames: try: lct = self.tfl.getLatestCommonTime(self.world, frame) transform = self.tfl.lookupTransform(self.world, frame, lct) except tf.Exception, e: transformations[frame] = {"visible": False} else: transformations[frame] = {"visible": True, "pose": transform} sample = {"time": (rospy.Time.now() - self.start_time).to_sec(), "objects": transformations} self.transforms.append(sample)
def record_tf(self, event): if self.active: try: self.listener.waitForTransform(self.root_frame, self.measured_frame, rospy.Time(0), rospy.Duration.from_sec(1 / (2*self.tf_sampling_freq))) (trans, rot) = self.listener.lookupTransform(self.root_frame, self.measured_frame, rospy.Time(0)) except (tf.Exception, tf.LookupException, tf.ConnectivityException) as e: rospy.logwarn(e) pass else: if self.first_value: self.trans_old = trans self.rot_old = rot self.first_value = False return #print "transformations: \n", "trans[0]", trans[0], "self.trans_old[0]",self.trans_old[0], "trans[1]", trans[1], "self.trans_old[1]",self.trans_old[1], "trans[2]",trans[2], "self.trans_old[2]",self.trans_old[2], "\n ------------------------------------------------ " path_increment = math.sqrt((trans[0] - self.trans_old[0]) ** 2 + (trans[1] - self.trans_old[1]) ** 2 + (trans[2] - self.trans_old[2]) ** 2) if(path_increment < 1): #rospy.logwarn("Transformation: %s, Path Increment: %s",str(trans), str(path_increment)) self.path_length += path_increment else: rospy.logwarn("Transformation Failed! \n Transformation: %s, Path Increment: %s",str(trans), str(path_increment)) self.trans_old = trans self.rot_old = rot
def __init__(self): # Give the node a name rospy.init_node('quat_to_angle', anonymous=False) # Publisher to control the robot's speed self.turtlebot_angle = rospy.Publisher('/turtlebot_angle', Float64, queue_size=5) self.turtlebot_posex = rospy.Publisher('/turtlebot_posex', Float64, queue_size=5) self.turtlebot_posey = rospy.Publisher('/turtlebot_posey', Float64, queue_size=5) #goal.target_pose.pose = Pose(Point(float(data["point"]["x"]), float(data["point"]["y"]), float(data["point"]["z"])), Quaternion(float(data["quat"]["x"]), float(data["quat"]["y"]), float(data["quat"]["z"]), float(data["quat"]["w"]))) # How fast will we update the robot's movement? rate = 20 # Set the equivalent ROS rate variable r = rospy.Rate(rate) # Initialize the tf listener self.tf_listener = tf.TransformListener() # Give tf some time to fill its buffer rospy.sleep(2) # Set the odom frame self.odom_frame = '/odom' # Find out if the robot uses /base_link or /base_footprint try: self.tf_listener.waitForTransform(self.odom_frame, '/base_footprint', rospy.Time(), rospy.Duration(1.0)) self.base_frame = '/base_footprint' except (tf.Exception, tf.ConnectivityException, tf.LookupException): try: self.tf_listener.waitForTransform(self.odom_frame, '/base_link', rospy.Time(), rospy.Duration(1.0)) self.base_frame = '/base_link' except (tf.Exception, tf.ConnectivityException, tf.LookupException): rospy.loginfo("Cannot find transform between /odom and /base_link or /base_footprint") rospy.signal_shutdown("tf Exception") # Initialize the position variable as a Point type position = Point() while not rospy.is_shutdown(): (position, rotation) = self.get_odom() print(position) self.turtlebot_angle.publish(rotation) #print(str(position).split('x: ')[1].split('\ny:')[0]) x = float(str(position).split('x: ')[1].split('\ny:')[0]) y = float(str(position).split('y: ')[1].split('\nz:')[0]) self.turtlebot_posex.publish(x) self.turtlebot_posey.publish(y) #print(rotation) rospy.sleep(5)