• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python msg.Joy类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: compare_all

def compare_all(data):
    global k 
    
    last_row = csv_data[k-frequency_offset]

    diff = Quaternion()
    diff.x = round(float(last_row[1])-convert_ppm(data.channels[3]),4)
    diff.y = round(float(last_row[2])-convert_ppm(data.channels[1]),4)
    diff.z = round(float(last_row[4])-convert_ppm(data.channels[0]),4)
    diff.w = round(float(last_row[5])+convert_ppm(data.channels[2]),4)
    
    testing_pub.publish(diff)

    if (k < len(csv_data)):
        row = csv_data[k]
        #log for post processing
        #joystick log
        c = csv.writer(open("/home/jinahadam/catkin_ws/src/testing/gps_joy.csv", "ab"))
        c.writerow([data.header.stamp.secs,row[1],row[2],row[4],row[5]])
        #rc Inn log
        c = csv.writer(open("/home/jinahadam/catkin_ws/src/testing/rc_in.csv", "ab"))
        c.writerow([data.header.stamp.secs,convert_ppm(data.channels[3]),convert_ppm(data.channels[1]),convert_ppm(data.channels[0]),convert_ppm(data.channels[2])])


        msg = Joy()
	msg.axes = (float(row[1]),float(row[2]),float(row[3]),float(row[4]),float(row[5]),float(row[6]),float(row[7]))
        msg.buttons = (0,0,0,0,0,0,0,0,0,0,0)
	k = k + 1
        pub.publish(msg)       
    else:
        #k = 0
        print("Joystick & RC In data logged with GPS Time")
        exit()
开发者ID:avetics,项目名称:ros_testing,代码行数:33,代码来源:joytest.py


示例2: publish

    def publish(self):
	cmd = Joy()
	cmd.header.stamp = rospy.Time.now()
	cmd.axes = self.axes_data
	cmd.buttons = self.button_data
	if self.debug: print cmd
	self.pub.publish(cmd)
开发者ID:alishuja,项目名称:ipa_lcrob,代码行数:7,代码来源:evjoy.py


示例3: talker

def talker():
    pub = rospy.Publisher('joy', Joy, queue_size=20)
    rospy.init_node('test', anonymous=True)
    rate = rospy.Rate(100) # 10hz 
    bits=[]    
    #print axis,buttons
    while not rospy.is_shutdown():
        data = s.recvfrom(6144)
        app_data = data[0]
        app_data_addr = data[1]
        app_data=app_data.strip("[]")  
        app_data=app_data.split(",")
        app_data=map(int,app_data)  
        #print app_data  
        #app_data=[10,10,0,0,0,0,0,0,0,0] 
        recv = robot1.receiver(app_data)
        app_axis_data,app_button_data=recv.sort_data()
        axis,buttons=recv.joystick_data(app_axis_data,app_button_data)
        joy=Joy()
        joy.axes=axis
        joy.buttons=buttons
        #hello_str = "hello world %s" % rospy.get_time()
        rospy.loginfo(app_data)
        rospy.loginfo(buttons)
        pub.publish(joy)
        rate.sleep()
开发者ID:arvinasokan,项目名称:Robot-Tele-Op-Controller,代码行数:26,代码来源:receiver_node.py


示例4: joy_callback

 def joy_callback(self, data):
   joy = Joy()
   joy.header.stamp = rospy.Time.now()
   joy.axes = self.convert(data.axes)
   joy.buttons = data.buttons
   self.prev_input_axes = list(data.axes)
   joy_pub = rospy.Publisher("/joy_relative/page_" + str(self.crt_page), Joy)
   joy_pub.publish(joy)
开发者ID:YoheiKakiuchi,项目名称:jsk_control,代码行数:8,代码来源:joy_relative_converter.py


示例5: callback

def callback(data):
    pub = rospy.Publisher('joy', Joy)
    buttons = [0] * (trigger_button + 1)
    buttons[trigger_button] = 1

    joy_msg = Joy()
    joy_msg.buttons = buttons
    pub.publish(joy_msg)
开发者ID:crainiarc,项目名称:ros_data_collectors,代码行数:8,代码来源:joystick_trigger.py


示例6: run

    def run(self):
        """Loop that obtains the latest wiimote state, publishes the joystick data, and sleeps.
        
        The Joy.msg message types calls for just two fields: float32[] axes, and int32[] buttons.
        """
        
        rospy.loginfo("Wiimote joystick publisher starting (topic wiijoy).")
        self.threadName = "Joy topic Publisher"
        try:
            while not rospy.is_shutdown():
                (canonicalAccel, canonicalNunchukAccel, canonicalAngleRate) = self.obtainWiimoteData()
                
                msg = Joy(header=None,
                          axes=[canonicalAccel[X], canonicalAccel[Y], canonicalAccel[Z]],
                          buttons=None)
                
                # If a gyro is attached to the Wiimote, we add the
                # gyro information:
                if self.wiistate.motionPlusPresent:
                    msg.axes.extend([canonicalAngleRate[PHI], canonicalAngleRate[THETA], canonicalAngleRate[PSI]])
                          
                # Fill in the ROS message's buttons field (there *must* be
                #     a better way in python to declare an array of 11 zeroes...]

                theButtons = [False,False,False,False,False,False,False,False,False,False,False]
                theButtons[State.MSG_BTN_1]     = self.wiistate.buttons[BTN_1]
                theButtons[State.MSG_BTN_2]     = self.wiistate.buttons[BTN_2]
                theButtons[State.MSG_BTN_A]     = self.wiistate.buttons[BTN_A]
                theButtons[State.MSG_BTN_B]     = self.wiistate.buttons[BTN_B]
                theButtons[State.MSG_BTN_PLUS]  = self.wiistate.buttons[BTN_PLUS]
                theButtons[State.MSG_BTN_MINUS] = self.wiistate.buttons[BTN_MINUS]
                theButtons[State.MSG_BTN_LEFT]  = self.wiistate.buttons[BTN_LEFT]
                theButtons[State.MSG_BTN_RIGHT] = self.wiistate.buttons[BTN_RIGHT]
                theButtons[State.MSG_BTN_UP]    = self.wiistate.buttons[BTN_UP]
                theButtons[State.MSG_BTN_DOWN]  = self.wiistate.buttons[BTN_DOWN]
                theButtons[State.MSG_BTN_HOME]  = self.wiistate.buttons[BTN_HOME]

                msg.buttons = theButtons
                
                measureTime = self.wiistate.time
                timeSecs = int(measureTime)
                timeNSecs = int(abs(timeSecs - measureTime) * 10**9)
                # Add the timestamp
                msg.header.stamp.secs = timeSecs
                msg.header.stamp.nsecs = timeNSecs
                
		try:
		  self.pub.publish(msg)
		except rospy.ROSException:
		  rospy.loginfo("Topic wiijoy closed. Shutting down Joy sender.")
		  exit(0)

                #rospy.logdebug("Joystick state:")
                #rospy.logdebug("    Joy buttons: " + str(theButtons) + "\n    Joy accel: " + str(canonicalAccel) + "\n    Joy angular rate: " + str(canonicalAngleRate))
                rospy.sleep(self.sleepDuration)
        except rospy.ROSInterruptException:
            rospy.loginfo("Shutdown request. Shutting down Joy sender.")
            exit(0)
开发者ID:10daysnobath,项目名称:joystick_drivers,代码行数:58,代码来源:wiimote_node.py


示例7: on_message

    def on_message(self, message_raw):
        message = json.loads(message_raw)
        if message['msg']=='lag':
            self.send( json.dumps({
                'start':message['start'],
                }))

        if message['msg']=='joy':
            msg = Joy()
            msg.header.stamp = rospy.Time.now()
            msg.axes = message['axes']
            msg.buttons = message['buttons']
            joy_pub.publish(msg)
开发者ID:strawlab,项目名称:browser_joystick,代码行数:13,代码来源:web_control.py


示例8: send

 def send(self):
     joy_msg = Joy()
     joy_msg.header.stamp = rospy.Time.now()
     buttons = (self.ui.button_0, self.ui.button_1, self.ui.button_2, self.ui.button_3, self.ui.button_4, 
                self.ui.button_5, self.ui.button_6, self.ui.button_7, self.ui.button_8, self.ui.button_9, 
                self.ui.button_10, self.ui.button_11)
     joy_msg.buttons = [b.isChecked() for b in buttons]
     joy_msg.axes = [mult*s.value()/100.0 for s, mult in 
                     zip((self.ui.rollSlider, self.ui.pitchSlider, self.ui.yawSlider, self.ui.altSlider), (-1.0, 1.0, -1.0, 1.0))]
     for label, value in zip((self.ui.rollLabel, self.ui.pitchLabel, self.ui.yawLabel, self.ui.altLabel), joy_msg.axes):
         label.setText('%0.2f' % value)
     
     self.pub.publish(joy_msg)
开发者ID:weiqinggu,项目名称:obstacle-avoidance-from-ros,代码行数:13,代码来源:soft_joystick.py


示例9: run

 def run(self):
     blub=Joy()
     while(self.run):
         data=ord(self.ser.read(1))
         if data==255:
             data=ord(self.ser.read(1))
             if data==255:
                 data=ord(self.ser.read(1))
                 if data==255:
                     data=ord(self.ser.read(1))
                     if data==24:
                         data=self.ser.read(7)
                         axes = struct.unpack('BBBBBBB', data)
                         for x in axes:
                             blub.axes.append((x-128)/127.0)
                         print blub.axes
                         data=self.ser.read(2)
                         button = struct.unpack('H', data)[0]
                         blub.buttons.insert(0,int(button/2048))
                         button-=(int(button/2048))*button
                         blub.buttons.insert(0,int(button/1024))
                         button-=(int(button/1024))*button
                         blub.buttons.insert(0,int(button/512))
                         button-=(int(button/512))*button
                         blub.buttons.insert(0,int(button/256))
                         button-=(int(button/256))*button
                         blub.buttons.insert(0,int(button/128))
                         button-=(int(button/128))*button
                         blub.buttons.insert(0,int(button/64))
                         button-=(int(button/64))*button
                         blub.buttons.insert(0,int(button/32))
                         button-=(int(button/32))*button
                         blub.buttons.insert(0,int(button/16))
                         button-=(int(button/16))*button
                         blub.buttons.insert(0,int(button/8))
                         button-=(int(button/8))*button
                         blub.buttons.insert(0,int(button/4))
                         button-=(int(button/4))*button
                         blub.buttons.insert(0,int(button/2))
                         button-=(int(button/2))*button
                         blub.buttons.insert(0,int(button))
                         print blub
                         blub.axes=list()
                         blub.buttons=list()
                        
     self.ser.close()
开发者ID:xaedes,项目名称:OttoCar-PC,代码行数:46,代码来源:rf_stick.py


示例10: comapre_single_channel

def comapre_single_channel(data):
    global k 
    
    last_row = csv_data[k-frequency_offset]

    lat = Pose2D()
    lat.x = float(last_row[1])
    lat.y = convert_ppm(data.channels[3])
    lat.theta = 0
    
    latency_ch.publish(lat)

    if (k < len(csv_data)):
        row = csv_data[k]
        msg = Joy()
        msg.axes = (float(row[1]),float(row[2]),float(row[3]),float(row[4]),float(row[5]),float(row[6]),float(row[7]))
        msg.buttons = (0,0,0,0,0,0,0,0,0,0,0)
        k = k + 1
        pub.publish(msg)       
    else:
        k = 0
开发者ID:avetics,项目名称:ros_testing,代码行数:21,代码来源:joytest.py


示例11: main

def main():
    rospy.sleep(1)
    rospy.init_node('trackpoint_joy')
    trackpoint_joy_pub = rospy.Publisher('/trackpoint/joy', Joy)
    tp_file = open( "/dev/input/mice", "rb" )

    while not rospy.is_shutdown():
        buf = tp_file.read(3)
        button = ord( buf[0] )
        bLeft = button & 0x1
        bMiddle = ( button & 0x4 ) > 0
        bRight = ( button & 0x2 ) > 0
        x,y = struct.unpack( "bb", buf[1:] )
        rospy.loginfo("L:%d, M: %d, R: %d, x: %d, y: %d\n" % (bLeft, bMiddle, bRight, x, y) )
        joy_msg = Joy()
        joy_msg.header.stamp = rospy.Time.now()
        joy_msg.axes = [x, y]
        joy_msg.buttons = [bLeft, bMiddle, bRight]
        trackpoint_joy_pub.publish(joy_msg)
        # rospy.sleep(0.1)
    tp_file.close();
开发者ID:aginika,项目名称:jsk_control,代码行数:21,代码来源:trackpoint_joy.py


示例12: main

def main():
	pub = rospy.Publisher('ernest_sensors/imu', Imu, queue_size=10)
	eyes = rospy.Publisher('ernest_sensors/eyes', Range, queue_size=10)
	nunchuck = rospy.Publisher('ernest_sensors/joy', Joy, queue_size=10)
	nunchuck_giro = rospy.Publisher('ernest_sensors/joy_giro', Imu, queue_size=10)
	comm = ArduinoCommunicator()
	rospy.init_node('ernest_sensors')
	for line in comm.loop():
		print line
		try:
			x, y, z, dis, joy_x, joy_y, giro_x, giro_y, giro_z, but_c, but_z = line.split(",")
			imu = Imu()
			imu.header.frame_id = "imu"
			imu.linear_acceleration.x = -float(x)
			imu.linear_acceleration.y = float(z)
			imu.linear_acceleration.z = float(y)
			r = Range()
			r.header.frame_id = "imu"
			r.radiation_type = 1
			r.field_of_view = 0.5
			r.min_range = 0.20
			r.max_range = 3
			r.range = float(dis)/100.0
			j = Joy()
			j.axes = [
				maprange(float(joy_x), 25, 226, -1, 1), 
				maprange(float(joy_y), 32, 223, -1, 1)
			]
			j.buttons = [int(but_c), int(but_z)]
			imu2 = Imu()
			imu2.header.frame_id = "imu"
			imu2.linear_acceleration.x = (float(giro_y) - 512) / 512.0
			imu2.linear_acceleration.y = -(float(giro_x) - 512) / 512.0
			imu2.linear_acceleration.z = -(float(giro_z) - 512) / 512.0
			pub.publish(imu)
			eyes.publish(r)
			nunchuck.publish(j)
			nunchuck_giro.publish(imu2)
		except ValueError:
			continue
开发者ID:simkim,项目名称:ernest,代码行数:40,代码来源:sensors.py


示例13: diff

def diff(data):
    global k 
    
    last_row = csv_data[k-frequency_offset]

    diff = Quaternion()
    diff.x = round(float(last_row[1])-convert_ppm(data.channels[3]),4)
    diff.y = round(float(last_row[2])-convert_ppm(data.channels[1]),4)
    diff.z = round(float(last_row[4])-convert_ppm(data.channels[0]),4)
    diff.w = round(float(last_row[5])+convert_ppm(data.channels[2]),4)
    
    testing_pub.publish(diff)

    if (k < len(csv_data)):
        row = csv_data[k]
        msg = Joy()
     	msg.axes = (float(row[1]),float(row[2]),float(row[3]),float(row[4]),float(row[5]),float(row[6]),float(row[7]))
        msg.buttons = (0,0,0,0,0,0,0,0,0,0,0)
	k = k + 1
        pub.publish(msg)       
    else:
        k = 0
开发者ID:avetics,项目名称:ros_testing,代码行数:22,代码来源:joytest.py


示例14: ready

def ready(pub):
	msg = Joy()
	msg.header.stamp = rospy.Time.now()
	valueAxe = 0.0
	valueButton = 0
	standup_time = 20 #2 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.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()
开发者ID:IkerZamora,项目名称:ros_erle_spider_voice_control,代码行数:24,代码来源:voice_control.py


示例15: right

def right(pub):
	msg = Joy()
	msg.header.stamp = rospy.Time.now()
	valueAxe = 0.0
	valueButton = 0
	turning_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[2] =  -1
	i=0
	bo=True
	print "TURNING RIGHT"
	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()
开发者ID:IkerZamora,项目名称:ros_erle_spider_voice_control,代码行数:24,代码来源:voice_control.py


示例16: backwards

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,代码行数:24,代码来源:voice_control.py


示例17: handler

    def handler(data):

        try:
            recived = byteify(json.loads(data))

            if 'trans' in recived and 'rot' in recived:
                # Send joystic data
                joy = Joy()
                joy.axes = (recived['trans'] + recived['rot'])
                joy_pub.publish(joy)

                # Send twists data
                twist = Twist()
                twist.angular.x = recived['rot'][0]
                twist.angular.y = recived['rot'][1]
                twist.angular.z = recived['rot'][2]

                twist.linear.x = recived['trans'][0]
                twist.linear.y = recived['trans'][1]
                twist.linear.z = recived['trans'][2]

                twist_pub.publish(twist)
        except AttributeError, e:
            print e
开发者ID:EndPointCorp,项目名称:lg_ros_nodes,代码行数:24,代码来源:server.py


示例18: main

def main():
    print "Started"
    rospy.init_node("mock_server", anonymous=True)
    joy_pub = rospy.Publisher("/joy", Joy)
    joy_msg = Joy()
    for i in range(7):
        joy_msg.axes.append(0.0)
    for j in range(12):
        joy_msg.buttons.append(0)
    joy_msg.axes[6] = 1
    # rospy.loginfo('joystick vehicle controller starting')

    print "Setting Host"
    # myHost = '192.168.88.202'
    # myPort = 1234
    myHost = rospy.get_param("/ip", "192.168.88.202")
    myPort = rospy.get_param("/port", 8080)
    print "My Host : " + myHost
    print "My Port : " + str(myPort)
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)  # create a TCP socket
    try:
        s.bind((myHost, myPort))
    except socket.error, msg:
        print "Bind failed. Error Code : " + str(msg[0]) + " Message " + msg[1]  # bind it to the server port
开发者ID:roboskel,项目名称:SekApps,代码行数:24,代码来源:mock_server.py


示例19: main

def main(device_name, autorepeat_rate, frame_id):
    rospy.loginfo("reading %s" % (device_name))
    joy_pub = rospy.Publisher('joy', Joy)
    with open(device_name, "rb" ) as tp_file:
        prev_bLeft = 0
        prev_bMiddle = 0
        prev_bRight = 0
        while not rospy.is_shutdown():
            if autorepeat_rate == 0:
                buf = tp_file.read(3)
            else:
                r,w,e = select.select([tp_file], [], [], 1.0 / autorepeat_rate)
                if tp_file in r:
                    buf = os.read(tp_file.fileno(), 3)
                else:
                    buf = None
            if buf == None:
                x, y = (0, 0)
                bLeft = prev_bLeft
                bMiddle = prev_bMiddle
                bRight = prev_bRight
            else:
                button = ord( buf[0] )
                bLeft = button & 0x1
                bMiddle = ( button & 0x4 ) > 0
                bRight = ( button & 0x2 ) > 0
                x,y = struct.unpack( "bb", buf[1:] )
            joy_msg = Joy()
            joy_msg.header.stamp = rospy.Time.now()
            joy_msg.header.frame_id = frame_id
            joy_msg.axes = [x, y]
            joy_msg.buttons = [bLeft, bMiddle, bRight]
            joy_pub.publish(joy_msg)
            prev_bLeft = bLeft
            prev_bMiddle = bMiddle
            prev_bRight = bRight
开发者ID:YuOhara,项目名称:jsk_control,代码行数:36,代码来源:joy.py


示例20: publish

 def publish(self, active_keys):
     logdebug("Publishing!")
     # in_event = self._device.read_one()
     # while in_event is None:
     # #     rospy.sleep(0.1)
     #     in_event = self._device.read_one()
     #     if in_event is None:
     #         continue
     #     if in_event.type == ecodes.EV_KEY:
     #         break
     #     else:
     #         in_event = None
     # if in_event is None:
     #     return
     # if in_event.type == ecodes.EV_KEY:
     msg = Joy(header=Header(stamp=Time.now()))
     msg.axes = [0.0] * self._axes_count
     msg.buttons = [0] * self._button_count
     # active_keys = self._device.active_keys(verbose=False)
     loginfo("active_keys : {}".format(active_keys))
     for k in active_keys:
         msg.buttons[key_map[k]] = 1
     loginfo("msg.buttons : {}".format(msg.buttons))
     self._pub.publish(msg)
开发者ID:daiemna,项目名称:robocup_home_working,代码行数:24,代码来源:vr_remote.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python msg.LaserScan类代码示例发布时间:2022-05-27
下一篇:
Python msg.JointState类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap