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


Python Joy.channels[throttle_channel]方法代码示例

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


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

示例1: onMessage

# 需要导入模块: from sensor_msgs.msg import Joy [as 别名]
# 或者: from sensor_msgs.msg.Joy import channels[throttle_channel] [as 别名]

#.........这里部分代码省略.........
                            pub.publish(msg)
                        if '/crab_leg_kinematics' in ros_nodes: #spider
                            print("spider running")
                            pub = rospy.Publisher('/joy', Joy, queue_size=10, latch=True)
                            msg = Joy()
                            msg.header.stamp = rospy.Time.now()
                            rate = rospy.Rate(10)
                            valueAxe = 0.0
                            valueButton = 0
                            for i in range (0, 20):
                                msg.axes.append(valueAxe)
                            for e in range (0, 17):
                                msg.buttons.append(valueButton)
                            pub.publish(msg)
                            print("DEFAULT MESSAGES SENT")
                        if '/mavros' in ros_nodes: #rover
                            print("rover")
                            pub = rospy.Publisher('/mavros/rc/override', OverrideRCIn, queue_size=10)
                            msg = OverrideRCIn()
                            msg.channels[0] = 1500
                            msg.channels[1] = 0
                            msg.channels[2] = 1500
                            msg.channels[3] = 0
                            msg.channels[4] = 0
                            msg.channels[5] = 0
                            msg.channels[6] = 0
                            msg.channels[7] = 0
                            pub.publish(msg)
                        print("@@@@@@@@@@@@@@@@@@")

                    elif method_name.startswith('control'):
                        robot = method_name.split('control_')[1]
                        if robot.startswith('spider'):
                            direction = robot.split('spider_')[1]
                            pub = rospy.Publisher('/joy', Joy, queue_size=10)
                            msg = Joy()
                            msg.header.stamp = rospy.Time.now()
                            rate = rospy.Rate(10)
                               
                            valueAxe = 0.0
                            valueButton = 0
                            for i in range (0, 20):
                                msg.axes.append(valueAxe)
                            for e in range (0, 17):
                                msg.buttons.append(valueButton)

                            if direction == 'up':#forward
                                msg.axes[1] = 1
                            elif direction == 'down':#backwards
                                msg.axes[1] = -1
                            elif direction == 'left':#turn left
                                #msg.axes[0] = 1
                                msg.axes[2] = 1
                            elif direction == 'right':#turn rigth
                                #msg.axes[0] = -1
                                msg.axes[2] = -1

                            pub.publish(msg)
                            rate.sleep()

                        elif robot.startswith('rover'):
                            direction = robot.split('rover_')[1]   
                            rospy.wait_for_service('/mavros/set_mode')
                            change_mode = rospy.ServiceProxy('/mavros/set_mode', SetMode)
                            resp1 = change_mode(custom_mode='manual')
                            print (resp1)
                            if 'True' in str(resp1):
                                pub = rospy.Publisher('mavros/rc/override', OverrideRCIn, queue_size=10)
                                r = rospy.Rate(10) #2hz
                                msg = OverrideRCIn()
                                throttle_channel=2
                                steer_channel=0

                                speed_slow = 1558
                                #speed_turbo = 2000 #dangerous
                                speed = speed_slow

                                if direction == 'up':#forward
                                    msg.channels[throttle_channel]=speed
                                    msg.channels[steer_channel]=1385 #straight
                                elif direction == 'down':#backwards
                                    msg.channels[throttle_channel]=1450 #slow
                                    msg.channels[steer_channel]=1385 #straight
                                elif direction == 'left':#turn left
                                    msg.channels[throttle_channel]=speed
                                    msg.channels[steer_channel]=1285
                                elif direction == 'right':#turn rigth
                                    msg.channels[throttle_channel]=speed
                                    msg.channels[steer_channel]=1485

                                start = time.time()
                                flag=True
                                while not rospy.is_shutdown() and flag:
                                    sample_time=time.time()
                                    if ((sample_time - start) > 0.5):
                                        flag=False
                                    pub.publish(msg)
                                    r.sleep()
                    else:
                        rospy.logerr('Called unknown method %s', method_name)
开发者ID:Nestor94Gonzalez,项目名称:robot_blockly,代码行数:104,代码来源:robot_blockly_backend.py


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