本文整理汇总了Python中sensor_msgs.msg.Joy.channels[1]方法的典型用法代码示例。如果您正苦于以下问题:Python Joy.channels[1]方法的具体用法?Python Joy.channels[1]怎么用?Python Joy.channels[1]使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sensor_msgs.msg.Joy
的用法示例。
在下文中一共展示了Joy.channels[1]方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: onMessage
# 需要导入模块: from sensor_msgs.msg import Joy [as 别名]
# 或者: from sensor_msgs.msg.Joy import channels[1] [as 别名]
def onMessage(self, payload, isBinary):
# Debug
if isBinary:
print("Binary message received: {0} bytes".format(len(payload)))
else:
print("Text message received: {0}".format(payload.decode('utf8')))
# Do stuff
# pub = rospy.Publisher('blockly', String, queue_size=10)
# time.sleep(1)
# pub.publish("blockly says: "+payload.decode('utf8'))
# Simple text protocol for communication
# first line is the name of the method
# next lines are body of message
message_text = payload.decode('utf8')
message_data = message_text.split('\n', 1)
if len(message_data) > 0:
method_name = message_data[0]
if len(message_data) > 1:
method_body = message_data[1]
if method_name.startswith('play'):
CodeStatus.set_current_status(CodeStatus.RUNNING)
BlocklyServerProtocol.build_ros_node(method_body)
rospy.loginfo('The file generated contains...')
os.system('cat test.py')
if method_name == 'play2':
CodeExecution.run_process(['python', 'test.py'])
elif method_name == 'play3':
CodeExecution.run_process(['python3', 'test.py'])
else:
rospy.logerr('Called unknown method %s', method_name)
else:
if 'pause' == method_name:
CodeStatus.set_current_status(CodeStatus.PAUSED)
elif 'resume' == method_name:
CodeStatus.set_current_status(CodeStatus.RUNNING)
elif 'end' == method_name:
#End test.py execution
global pid
print("@@@@@@@@@@@@@@@@@@")
try:
print("kill pid="+str(pid))
os.kill(pid, signal.SIGKILL)
ros_nodes = rosnode.get_node_names()
except NameError:
print("execution script not running.")
pass
if '/imu_talker' in ros_nodes: #brain
##set default values
pub = rospy.Publisher('/statusleds', String, queue_size=10, latch=True)
msg = 'blue_off'
pub.publish(msg)
msg = 'orange_off'
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):
#.........这里部分代码省略.........