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


Python Joy.axes[1]方法代码示例

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


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

示例1: toPS3Msg

# 需要导入模块: from sensor_msgs.msg import Joy [as 别名]
# 或者: from sensor_msgs.msg.Joy import axes[1] [as 别名]
 def toPS3Msg(self):
     joy = Joy()
     joy.header = self.orig_msg.header
     joy.buttons = [0] * 17
     joy.axes = [0] * 20
     if self.center:
         joy.buttons[16] = 1
     if self.select:
         joy.buttons[0] = 1
     if self.start:
         joy.buttons[3] = 1
     if self.L3:
         joy.buttons[1] = 1
     if self.R3:
         joy.buttons[2] = 1
     if self.square:
         joy.axes[15] = -1.0
         joy.buttons[15] = 1
     if self.up:
         joy.axes[4] = -1.0
         joy.buttons[4] = 1
     if self.down:
         joy.axes[6] = -1.0
         joy.buttons[6] = 1
     if self.left:
         joy.axes[7] = -1.0
         joy.buttons[7] = 1
     if self.right:
         joy.axes[5] = -1.0
         joy.buttons[5] = 1
     if self.triangle:
         joy.axes[12] = -1.0
         joy.buttons[12] = 1
     if self.cross:
         joy.axes[14] = -1.0
         joy.buttons[14] = 1
     if self.circle:
         joy.axes[13] = -1.0
         joy.buttons[13] = 1
     if self.L1:
         joy.axes[10] = -1.0
         joy.buttons[10] = 1
     if self.R1:
         joy.axes[11] = -1.0
         joy.buttons[11] = 1
     if self.L2:
         joy.axes[8] = -1.0
         joy.buttons[8] = 1
     if self.R2:
         joy.axes[9] = -1.0
         joy.buttons[9] = 1
     joy.axes[0] = self.left_analog_x
     joy.axes[1] = self.left_analog_y
     joy.axes[2] = self.right_analog_x
     joy.axes[3] = self.right_analog_y
     return joy
开发者ID:YuOhara,项目名称:jsk_control,代码行数:58,代码来源:joy_status.py

示例2: backwards

# 需要导入模块: from sensor_msgs.msg import Joy [as 别名]
# 或者: from sensor_msgs.msg.Joy import axes[1] [as 别名]
def backwards(pub):
	msg = Joy()
	msg.header.stamp = rospy.Time.now()
	valueAxe = 0.0
	valueButton = 0
	walking_time = 30 #3 seconds
	for i in range (0, 20):
		msg.axes.append(valueAxe)
	for e in range (0, 17):
		msg.buttons.append(valueButton)
	rate = rospy.Rate(10)
	time.sleep(1)

	msg.axes[1] =  -1
	i=0
	bo=True
	print "WALKING BACKWARDS"
	while not rospy.is_shutdown() and bo:
		i=i+1
		if (i>walking_time):
			bo=False
			msg.axes[1] = 0
		pub.publish(msg)
		rate.sleep()
开发者ID:IkerZamora,项目名称:ros_erle_spider_voice_control,代码行数:26,代码来源:voice_control.py

示例3: publish_joy

# 需要导入模块: from sensor_msgs.msg import Joy [as 别名]
# 或者: from sensor_msgs.msg.Joy import axes[1] [as 别名]
 def publish_joy(self):
     '''
     Publishes current stick/button state as a Joy object, to be handled by navigator_emergency.py node
     '''
     current_joy = Joy()
     current_joy.axes.extend([0] * 4)
     current_joy.buttons.extend([0] * 16)
     for stick in self.sticks:
         if self.sticks[stick] >= 0x8000:  # Convert 2's complement hex to signed decimal if negative
             self.sticks[stick] -= 0x10000
     current_joy.axes[0] = np.float32(self.sticks['UD']) / 2048
     current_joy.axes[1] = np.float32(self.sticks['LR']) / 2048
     current_joy.axes[3] = np.float32(self.sticks['TQ']) / 2048
     current_joy.buttons[7] = np.int32(self.buttons['START'])
     current_joy.buttons[3] = np.int32(self.buttons['Y'])
     current_joy.buttons[2] = np.int32(self.buttons['X'])
     current_joy.buttons[0] = np.int32(self.buttons['A'])
     current_joy.buttons[1] = np.int32(self.buttons['B'])
     current_joy.buttons[11] = np.int32(self.buttons['DL'])  # Dpad Left
     current_joy.buttons[12] = np.int32(self.buttons['DR'])  # Dpad Right
     current_joy.header.frame_id = "/base_link"
     current_joy.header.stamp = rospy.Time.now()
     self.joy_pub.publish(current_joy)
开发者ID:ironmig,项目名称:Navigator,代码行数:25,代码来源:kill_board_driver.py

示例4: Joy

# 需要导入模块: from sensor_msgs.msg import Joy [as 别名]
# 或者: from sensor_msgs.msg.Joy import axes[1] [as 别名]
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)

################
##    WALK    ##
################
walking_time=float(seconds)+0.4 ##manual time calibration

start = time.time()

msg.axes[1] = 1

bo=True
while not rospy.is_shutdown() and bo:
 sample_time = time.time()
 if ((sample_time - start) > walking_time):
  bo=False
  msg.axes[0] = 0
  msg.axes[1] = 0
 pub.publish(msg)
 rate.sleep()
开发者ID:fjpaxkm,项目名称:crab_project,代码行数:32,代码来源:spider_forward.py

示例5: talker

# 需要导入模块: from sensor_msgs.msg import Joy [as 别名]
# 或者: from sensor_msgs.msg.Joy import axes[1] [as 别名]
def talker():

##PARAMS:
  standup_time=20
  walking_time=120
  turning_time=125

 
  rospy.init_node("joy_simulate", anonymous=True)
  pub = rospy.Publisher("/joy", Joy, queue_size=10)
  msg = Joy()
  msg.header.stamp = rospy.Time.now()
  rate = rospy.Rate(10)
 
################
## INITIALIZE ##
################
  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)

  time.sleep(1)

####################
## PONERSE EN PIE ##
####################
  msg.buttons[3] = 1
  i=0
  bo=True
  print "STAND_UP"
  while not rospy.is_shutdown() and bo:
    i=i+1
    if (i>standup_time):
      bo=False
      msg.buttons[3] = 0
    pub.publish(msg)
    rate.sleep()

  time.sleep(2)


#################
## ANDAR 30 CM ##
#################
  msg.axes[1] =  1
  i=0
  bo=True
  print "WALKING"
  while not rospy.is_shutdown() and bo:
    i=i+1
    if (i>walking_time):
      bo=False
      msg.axes[1] = 0
    pub.publish(msg)
    rate.sleep()


###########
## GIRAR ##
###########
  msg.axes[2] = -1
  i=0
  bo=True
  print "TURN"
  while not rospy.is_shutdown() and bo:
    i=i+1
    if (i>turning_time):
      bo=False
      msg.axes[2] = 0
    pub.publish(msg)
    rate.sleep()


#################
## ANDAR 30 CM ##
#################
  msg.axes[1] =  1
  i=0
  bo=True
  print "WALKING"
  while not rospy.is_shutdown() and bo:
    i=i+1
    if (i>walking_time):
      bo=False
      msg.axes[1] = 0
    pub.publish(msg)
    rate.sleep()


####################
## SENTARSE ##
####################
  msg.buttons[3] = 1
  i=0
  bo=True
  standup_time=standup_time/3
  print "SEAT_DOWN"
#.........这里部分代码省略.........
开发者ID:IkerZamora,项目名称:ros_erle_spider,代码行数:103,代码来源:demo1.py

示例6: onMessage

# 需要导入模块: from sensor_msgs.msg import Joy [as 别名]
# 或者: from sensor_msgs.msg.Joy import axes[1] [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.axes[1]方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。