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


Python msg.Joy类代码示例

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


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


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