sender.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 """ For backwards compatibility with the old driver files
00004                 Will be DELETED in the future               """
00005 
00006 __author__ = 'flier'
00007 
00008 import argparse
00009 
00010 import rospy
00011 import leap_interface
00012 from leap_motion.msg import leap
00013 from leap_motion.msg import leapros
00014 
00015 FREQUENCY_ROSTOPIC_DEFAULT = 0.01
00016 NODENAME = 'leap_pub'
00017 PARAMNAME_FREQ = 'freq'
00018 PARAMNAME_FREQ_ENTIRE = '/' + NODENAME + '/' + PARAMNAME_FREQ
00019 
00020 def sender():
00021     '''
00022     This method publishes the data defined in leapros.msg to /leapmotion/data
00023     '''
00024     rospy.loginfo("Parameter set on server: PARAMNAME_FREQ={}".format(rospy.get_param(PARAMNAME_FREQ_ENTIRE, FREQUENCY_ROSTOPIC_DEFAULT)))
00025 
00026     li = leap_interface.Runner()
00027     li.setDaemon(True)
00028     li.start()
00029     # pub     = rospy.Publisher('leapmotion/raw',leap)
00030     pub_ros   = rospy.Publisher('leapmotion/data',leapros, queue_size=2)
00031     rospy.init_node(NODENAME)
00032 
00033     while not rospy.is_shutdown():
00034         hand_direction_   = li.get_hand_direction()
00035         hand_normal_      = li.get_hand_normal()
00036         hand_palm_pos_    = li.get_hand_palmpos()
00037         hand_pitch_       = li.get_hand_pitch()
00038         hand_roll_        = li.get_hand_roll()
00039         hand_yaw_         = li.get_hand_yaw()
00040 
00041         msg = leapros()
00042         msg.direction.x = hand_direction_[0]
00043         msg.direction.y = hand_direction_[1]
00044         msg.direction.z = hand_direction_[2]
00045         msg.normal.x = hand_normal_[0]
00046         msg.normal.y = hand_normal_[1]
00047         msg.normal.z = hand_normal_[2]
00048         msg.palmpos.x = hand_palm_pos_[0]
00049         msg.palmpos.y = hand_palm_pos_[1]
00050         msg.palmpos.z = hand_palm_pos_[2]
00051         msg.ypr.x = hand_yaw_
00052         msg.ypr.y = hand_pitch_
00053         msg.ypr.z = hand_roll_
00054 
00055         fingerNames = ['thumb', 'index', 'middle', 'ring', 'pinky']
00056         fingerPointNames = ['metacarpal', 'proximal',
00057                             'intermediate', 'distal', 'tip']
00058         for fingerName in fingerNames:
00059             for fingerPointName in fingerPointNames:
00060                 pos = li.get_finger_point(fingerName, fingerPointName)
00061                 for iDim, dimName in enumerate(['x', 'y', 'z']):
00062                     setattr(getattr(msg, '%s_%s' % (fingerName, fingerPointName)),
00063                             dimName, pos[iDim])
00064 
00065         # We don't publish native data types, see ROS best practices
00066         # pub.publish(hand_direction=hand_direction_,hand_normal = hand_normal_, hand_palm_pos = hand_palm_pos_, hand_pitch = hand_pitch_, hand_roll = hand_roll_, hand_yaw = hand_yaw_)
00067         pub_ros.publish(msg)
00068         rospy.sleep(rospy.get_param(PARAMNAME_FREQ_ENTIRE, FREQUENCY_ROSTOPIC_DEFAULT))
00069 
00070 
00071 if __name__ == '__main__':
00072     try:
00073         sender()
00074     except rospy.ROSInterruptException:
00075         pass


leap_motion
Author(s): Florian Lier , Mirza Shah , Isaac IY Saito
autogenerated on Sat Jun 8 2019 18:47:25