当前位置: 首页>>代码示例>>Python>>正文


Python rospy.Time方法代码示例

本文整理汇总了Python中rospy.Time方法的典型用法代码示例。如果您正苦于以下问题:Python rospy.Time方法的具体用法?Python rospy.Time怎么用?Python rospy.Time使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在rospy的用法示例。


在下文中一共展示了rospy.Time方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: send_transform

# 需要导入模块: import rospy [as 别名]
# 或者: from rospy import Time [as 别名]
def send_transform(self, translation, rotation, time, child, parent):
        """
        :param translation: the translation of the transformation as a tuple (x, y, z)
        :param rotation: the rotation of the transformation as a tuple (x, y, z, w)
        :param time: the time of the transformation, as a rospy.Time()
        :param child: child frame in tf, string
        :param parent: parent frame in tf, string

        Broadcast the transformation from tf frame child to parent on ROS topic ``"/tf"``.
        """

        t = TransformStamped()
        t.header.frame_id = parent
        t.header.stamp = time
        t.child_frame_id = child
        t.transform.translation.x = translation[0]
        t.transform.translation.y = translation[1]
        t.transform.translation.z = translation[2]

        t.transform.rotation.x = rotation[0]
        t.transform.rotation.y = rotation[1]
        t.transform.rotation.z = rotation[2]
        t.transform.rotation.w = rotation[3]

        self.send_transform_message(t) 
开发者ID:OTL,项目名称:cozmo_driver,代码行数:27,代码来源:cozmo_driver.py

示例2: _publish_diagnostics

# 需要导入模块: import rospy [as 别名]
# 或者: from rospy import Time [as 别名]
def _publish_diagnostics(self):
        # alias
        diag_status = self._diag_array.status[0]

        # fill diagnostics array
        battery_voltage = self._cozmo.battery_voltage
        diag_status.values[0].value = '{:.2f} V'.format(battery_voltage)
        diag_status.values[1].value = '{:.2f} deg'.format(self._cozmo.head_angle.degrees)
        diag_status.values[2].value = '{:.2f} mm'.format(self._cozmo.lift_height.distance_mm)
        if battery_voltage > 3.5:
            diag_status.level = DiagnosticStatus.OK
            diag_status.message = 'Everything OK!'
        elif battery_voltage > 3.4:
            diag_status.level = DiagnosticStatus.WARN
            diag_status.message = 'Battery low! Go charge soon!'
        else:
            diag_status.level = DiagnosticStatus.ERROR
            diag_status.message = 'Battery very low! Cozmo will power off soon!'

        # update message stamp and publish
        self._diag_array.header.stamp = rospy.Time.now()
        self._diag_pub.publish(self._diag_array) 
开发者ID:OTL,项目名称:cozmo_driver,代码行数:24,代码来源:cozmo_driver.py

示例3: _publish_joint_state

# 需要导入模块: import rospy [as 别名]
# 或者: from rospy import Time [as 别名]
def _publish_joint_state(self):
        """
        Publish joint states as JointStates.

        """
        # only publish if we have a subscriber
        if self._joint_state_pub.get_num_connections() == 0:
            return

        js = JointState()
        js.header.stamp = rospy.Time.now()
        js.header.frame_id = 'cozmo'
        js.name = ['head', 'lift']
        js.position = [self._cozmo.head_angle.radians,
                       self._cozmo.lift_height.distance_mm * 0.001]
        js.velocity = [0.0, 0.0]
        js.effort = [0.0, 0.0]
        self._joint_state_pub.publish(js) 
开发者ID:OTL,项目名称:cozmo_driver,代码行数:20,代码来源:cozmo_driver.py

示例4: _publish_battery

# 需要导入模块: import rospy [as 别名]
# 或者: from rospy import Time [as 别名]
def _publish_battery(self):
        """
        Publish battery as BatteryState message.

        """
        # only publish if we have a subscriber
        if self._battery_pub.get_num_connections() == 0:
            return

        battery = BatteryState()
        battery.header.stamp = rospy.Time.now()
        battery.voltage = self._cozmo.battery_voltage
        battery.present = True
        if self._cozmo.is_on_charger:  # is_charging always return False
            battery.power_supply_status = BatteryState.POWER_SUPPLY_STATUS_CHARGING
        else:
            battery.power_supply_status = BatteryState.POWER_SUPPLY_STATUS_NOT_CHARGING
        self._battery_pub.publish(battery) 
开发者ID:OTL,项目名称:cozmo_driver,代码行数:20,代码来源:cozmo_driver.py

示例5: convert_pose

# 需要导入模块: import rospy [as 别名]
# 或者: from rospy import Time [as 别名]
def convert_pose(pose, from_frame, to_frame):
    """
    Convert a pose or transform between frames using tf.
        pose            -> A geometry_msgs.msg/Pose that defines the robots position and orientation in a reference_frame
        from_frame      -> A string that defines the original reference_frame of the robot
        to_frame        -> A string that defines the desired reference_frame of the robot to convert to
    """
    global tfBuffer, listener

    # Create Listener objet to recieve and buffer transformations
    trans = None

    try:
        trans = tfBuffer.lookup_transform(to_frame, from_frame, rospy.Time(0), rospy.Duration(1.0))
    except (tf2_ros.LookupException, tf2_ros.ConnectivityException, tf2_ros.ExtrapolationException), e:
        print(e)
        rospy.logerr('FAILED TO GET TRANSFORM FROM %s to %s' % (to_frame, from_frame))
        return None 
开发者ID:dougsm,项目名称:ggcnn_kinova_grasping,代码行数:20,代码来源:transforms.py

示例6: goto_joint_positions

# 需要导入模块: import rospy [as 别名]
# 或者: from rospy import Time [as 别名]
def goto_joint_positions(self, positions_goal):

        positions_cur = self.get_joint_positions()
        assert len(positions_goal) == len(positions_cur)

        duration = norm((r_[positions_goal] - r_[positions_cur]) / self.vel_limits, ord=inf)

        jt = tm.JointTrajectory()
        jt.joint_names = self.joint_names
        jt.header.stamp = rospy.Time.now()

        jtp = tm.JointTrajectoryPoint()
        jtp.positions = positions_goal
        jtp.velocities = zeros(len(positions_goal))
        jtp.time_from_start = rospy.Duration(duration)

        jt.points = [jtp]
        self.controller_pub.publish(jt)

        rospy.loginfo("%s: starting %.2f sec traj", self.controller_name, duration)
        self.pr2.start_thread(JustWaitThread(duration)) 
开发者ID:alexlee-gk,项目名称:visual_dynamics,代码行数:23,代码来源:PR2.py

示例7: follow_timed_joint_trajectory

# 需要导入模块: import rospy [as 别名]
# 或者: from rospy import Time [as 别名]
def follow_timed_joint_trajectory(self, positions, velocities, times):

        jt = tm.JointTrajectory()
        jt.joint_names = self.joint_names
        jt.header.stamp = rospy.Time.now()

        for (position, velocity, time) in zip(positions, velocities, times):
            jtp = tm.JointTrajectoryPoint()
            jtp.positions = position
            jtp.velocities = velocity
            jtp.time_from_start = rospy.Duration(time)
            jt.points.append(jtp)

        self.controller_pub.publish(jt)
        rospy.loginfo("%s: starting %.2f sec traj", self.controller_name, times[-1])
        self.pr2.start_thread(JustWaitThread(times[-1])) 
开发者ID:alexlee-gk,项目名称:visual_dynamics,代码行数:18,代码来源:PR2.py

示例8: follow_timed_trajectory

# 需要导入模块: import rospy [as 别名]
# 或者: from rospy import Time [as 别名]
def follow_timed_trajectory(self, times, angs):
        times_up = np.arange(0, times[-1] + 1e-4, .1)
        angs_up = np.interp(times_up, times, angs)

        jt = tm.JointTrajectory()
        jt.header.stamp = rospy.Time.now()
        jt.joint_names = ["%s_gripper_joint" % self.lr]
        for (t, a) in zip(times, angs):
            jtp = tm.JointTrajectoryPoint()
            jtp.time_from_start = rospy.Duration(t)
            jtp.positions = [a]
            jt.points.append(jtp)
        self.diag_pub.publish(jt)

        self.pr2.start_thread(GripperTrajectoryThread(self, times_up, angs_up))
        # self.pr2.start_thread(GripperTrajectoryThread(self, times, angs)) 
开发者ID:alexlee-gk,项目名称:visual_dynamics,代码行数:18,代码来源:PR2.py

示例9: __init__

# 需要导入模块: import rospy [as 别名]
# 或者: from rospy import Time [as 别名]
def __init__(self, limb, joint_names):
        self._joint_names = joint_names
        ns = 'robot/limb/' + limb + '/'
        self._client = actionlib.SimpleActionClient(
            ns + "follow_joint_trajectory",
            FollowJointTrajectoryAction,
        )
        self._goal = FollowJointTrajectoryGoal()
        self._goal_time_tolerance = rospy.Time(0.1)
        self._goal.goal_time_tolerance = self._goal_time_tolerance
        server_up = self._client.wait_for_server(timeout=rospy.Duration(10.0))
        if not server_up:
            rospy.logerr("Timed out waiting for Joint Trajectory"
                         " Action Server to connect. Start the action server"
                         " before running example.")
            rospy.signal_shutdown("Timed out waiting for Action Server")
            sys.exit(1)
        self.clear(limb) 
开发者ID:RethinkRobotics,项目名称:intera_sdk,代码行数:20,代码来源:joint_trajectory_client.py

示例10: __init__

# 需要导入模块: import rospy [as 别名]
# 或者: from rospy import Time [as 别名]
def __init__(self, P=1.0, I=0.0, D=0.0):
        self.P = P
        self.I = I
        self.D = D

        self.maxP = sys.float_info.max
        self.maxI = sys.float_info.max
        self.maxD = sys.float_info.max
        self.maxTotal = sys.float_info.max

        # Useful for I part
        self.error_sum = 0.0

        # Useful for D part
        self.last_time = rospy.Time.now()
        self.last_error = 0.0# sys.float_info.max
        self.last_output = 0.0
        return 
开发者ID:omwdunkley,项目名称:crazyflieROS,代码行数:20,代码来源:joy_driver_pid.py

示例11: _LocalToWorld

# 需要导入模块: import rospy [as 别名]
# 或者: from rospy import Time [as 别名]
def _LocalToWorld(self,pose):
        """
        Transform a pose from local frame to world frame
        @param pose The 4x4 transformation matrix containing the pose to transform
        @return The 4x4 transformation matrix describing the pose in world frame
        """
        import rospy
        #Get pose w.r.t world frame
        self.listener.waitForTransform(self.world_frame,self.detection_frame,
                                       rospy.Time(),rospy.Duration(10))
        t, r = self.listener.lookupTransform(self.world_frame,self.detection_frame,
                                             rospy.Time(0))
        
        #Get relative transform between frames
        offset_to_world = numpy.matrix(transformations.quaternion_matrix(r))
        offset_to_world[0,3] = t[0]
        offset_to_world[1,3] = t[1]
        offset_to_world[2,3] = t[2]
        
        #Compose with pose to get pose in world frame
        result = numpy.array(numpy.dot(offset_to_world, pose))
        
        return result 
开发者ID:personalrobotics,项目名称:prpy,代码行数:25,代码来源:simtrack.py

示例12: _LocalToWorld

# 需要导入模块: import rospy [as 别名]
# 或者: from rospy import Time [as 别名]
def _LocalToWorld(self,pose):
        """
        Transform a pose from local frame to world frame
        @param pose The 4x4 transformation matrix containing the pose to transform
        @return The 4x4 transformation matrix describing the pose in world frame
        """
        #Get pose w.r.t world frame
        self.listener.waitForTransform(self.world_frame,self.detection_frame,
                                       rospy.Time(),rospy.Duration(10))
        t, r = self.listener.lookupTransform(self.world_frame,self.detection_frame,
                                             rospy.Time(0))
        
        #Get relative transform between frames
        offset_to_world = numpy.matrix(transformations.quaternion_matrix(r))
        offset_to_world[0,3] = t[0]
        offset_to_world[1,3] = t[1]
        offset_to_world[2,3] = t[2]
        
        #Compose with pose to get pose in world frame
        result = numpy.array(numpy.dot(offset_to_world, pose))
        
        return result 
开发者ID:personalrobotics,项目名称:prpy,代码行数:24,代码来源:vncc.py

示例13: get_grip_transform

# 需要导入模块: import rospy [as 别名]
# 或者: from rospy import Time [as 别名]
def get_grip_transform(self, ws_name, robot_pose):
        """
        Retrieves the transform needed to create a grip supposing the object
        is placed on the origin of the given workspace.

        :param ws_name: name of the workspace the object is placed on
        :param robot_pose: pose of the robot's tool_link
        """
        # First apply transform for robot pose
        base_link_to_tool_link = self.transform_from_euler(
            robot_pose.position.x, robot_pose.position.y, robot_pose.position.z,
            robot_pose.rpy.roll, robot_pose.rpy.pitch, robot_pose.rpy.yaw,
            "base_link", "tool_link"
        )
        self.__tf_buffer.set_transform(base_link_to_tool_link,
                                       "default_authority")

        # Manually place object on origin
        self.set_relative_pose_object(ws_name, 0, 0, 0)

        # Lookup the grip
        t = self.__tf_buffer.lookup_transform("object_base", "tool_link",
                                              rospy.Time(0))
        t.child_frame_id = "tool_link_target"
        return t 
开发者ID:NiryoRobotics,项目名称:niryo_one_ros,代码行数:27,代码来源:transform_handler.py

示例14: convert_pose

# 需要导入模块: import rospy [as 别名]
# 或者: from rospy import Time [as 别名]
def convert_pose(pose, from_frame, to_frame):
    """
    Convert a pose or transform between frames using tf.
        pose            -> A geometry_msgs.msg/Pose that defines the robots position and orientation in a reference_frame
        from_frame      -> A string that defines the original reference_frame of the robot
        to_frame        -> A string that defines the desired reference_frame of the robot to convert to
    """
    global tfBuffer, listener

    if tfBuffer is None or listener is None:
        _init_tf()

    try:
        trans = tfBuffer.lookup_transform(to_frame, from_frame, rospy.Time(0), rospy.Duration(1.0))
    except (tf2_ros.LookupException, tf2_ros.ConnectivityException, tf2_ros.ExtrapolationException), e:
        print(e)
        rospy.logerr('FAILED TO GET TRANSFORM FROM %s to %s' % (to_frame, from_frame))
        return None 
开发者ID:dougsm,项目名称:mvp_grasp,代码行数:20,代码来源:tf_helpers.py

示例15: publish_stamped_transform

# 需要导入模块: import rospy [as 别名]
# 或者: from rospy import Time [as 别名]
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 
开发者ID:dougsm,项目名称:mvp_grasp,代码行数:23,代码来源:tf_helpers.py


注:本文中的rospy.Time方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。