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


Python JointState.position[index[k]]方法代码示例

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


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

示例1: talker

# 需要导入模块: from sensor_msgs.msg import JointState [as 别名]
# 或者: from sensor_msgs.msg.JointState import position[index[k]] [as 别名]
def talker():
    global joy_value
    global last_joy
    global joint_state
    rospy.init_node('vsv_arm_teleop_raw')
    sub = rospy.Subscriber('~joy', Joy, joy_cb)
    jsub = rospy.Subscriber('~joint_state', JointState, joint_cb)
    joint = rospy.Publisher('~joint_command', JointState)
    axis={}
    axis["ArmPan"] = [int(s) for s in str(rospy.get_param("~axis_pan","6")).split(",")]
    axis["ArmTilt"] = [int(s) for s in str(rospy.get_param("~axis_tilt","7")).split(",")]
    axis["ArmFold"] = [int(s) for s in str(rospy.get_param("~axis_fold","4,5")).split(",")]
    axis["ArmExtend"] = [int(s) for s in str(rospy.get_param("~axis_extend","0,3")).split(",")]
    axis["ToolRotate"] = [int(s) for s in str(rospy.get_param("~axis_rotate","2,1")).split(",")]
    step_value = {"ArmPan":1*pi/180., "ArmTilt":5*pi/180.,
            "ArmFold":2*pi/180., "ArmExtend":0.05, "ToolRotate":5*pi/180.}
    timeout = True
    rate = rospy.Rate(10)
    while not rospy.is_shutdown() and not joint_state:
        rate.sleep()
    if rospy.is_shutdown():
        return
    command = JointState()
    command.header = joint_state.header
    command.name = joint_state.name
    command.velocity = [0.0] * len(joint_state.name)
    command.effort = [0.0] * len(joint_state.name)
    command.position = [x for x in joint_state.position]
    index = dict(zip(command.name,range(0,len(command.name))))
    while not rospy.is_shutdown():
        if (rospy.rostime.get_time() - last_joy) < 0.5: 
            if timeout:
                timeout = False
                rospy.loginfo("Accepting joystick commands")
            for k in axis.keys():
                if len(axis[k])==1:
                    # Axis
                    command.position[index[k]] = sat(command.position[index[k]]+joy_value.axes[axis[k][0]]*step_value[k],
                            joint_state.position[index[k]],step_value[k])
                else:
                    # Buttons
                    if joy_value.buttons[axis[k][0]]:
                        command.position[index[k]] = sat(command.position[index[k]]-step_value[k],
                            joint_state.position[index[k]],step_value[k])
                    elif joy_value.buttons[axis[k][1]]:
                        command.position[index[k]] = sat(command.position[index[k]]+step_value[k],
                            joint_state.position[index[k]],step_value[k])

            # if twist.linear.x < 0:
            #     twist.angular.z = - twist.angular.z
        else:
            if not timeout:
                timeout = True
                rospy.loginfo("Timeout: ignoring joystick commands")
        joint.publish(command)
        rate.sleep()
开发者ID:cedricpradalier,项目名称:vsv_stack,代码行数:58,代码来源:teleop_raw.py


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