本文整理汇总了Python中sensor_msgs.msg.Joy.channels[steer_channel]方法的典型用法代码示例。如果您正苦于以下问题:Python Joy.channels[steer_channel]方法的具体用法?Python Joy.channels[steer_channel]怎么用?Python Joy.channels[steer_channel]使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sensor_msgs.msg.Joy
的用法示例。
在下文中一共展示了Joy.channels[steer_channel]方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: onMessage
# 需要导入模块: from sensor_msgs.msg import Joy [as 别名]
# 或者: from sensor_msgs.msg.Joy import channels[steer_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)