sender.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 __author__ = 'flier'
00003 
00004 import argparse
00005 
00006 import rospy
00007 import leap_interface
00008 from leap_motion.msg import leap
00009 from leap_motion.msg import leapros
00010 
00011 FREQUENCY_ROSTOPIC_DEFAULT = 0.01
00012 PARAMNAME_FREQ = '/leapmotion/freq'
00013 
00014 # Obviously, this method publishes the data defined in leapros.msg to /leapmotion/data
00015 def sender(freq=FREQUENCY_ROSTOPIC_DEFAULT):
00016     '''
00017     @param freq: Frequency to publish sensed info as ROS message
00018     '''
00019     rospy.set_param(PARAMNAME_FREQ, freq)
00020     rospy.loginfo("Parameter set on server: PARAMNAME_FREQ={}, freq={}".format(rospy.get_param(PARAMNAME_FREQ, FREQUENCY_ROSTOPIC_DEFAULT), freq))
00021 
00022     li = leap_interface.Runner()
00023     li.setDaemon(True)
00024     li.start()
00025     # pub     = rospy.Publisher('leapmotion/raw',leap)
00026     pub_ros   = rospy.Publisher('leapmotion/data',leapros)
00027     rospy.init_node('leap_pub')
00028 
00029     while not rospy.is_shutdown():
00030         hand_direction_   = li.get_hand_direction()
00031         hand_normal_      = li.get_hand_normal()
00032         hand_palm_pos_    = li.get_hand_palmpos()
00033         hand_pitch_       = li.get_hand_pitch()
00034         hand_roll_        = li.get_hand_roll()
00035         hand_yaw_         = li.get_hand_yaw()
00036         msg = leapros()
00037         msg.direction.x = hand_direction_[0]
00038         msg.direction.y = hand_direction_[1]
00039         msg.direction.z = hand_direction_[2]
00040         msg.normal.x = hand_normal_[0]
00041         msg.normal.y = hand_normal_[1]
00042         msg.normal.z = hand_normal_[2]
00043         msg.palmpos.x = hand_palm_pos_[0]
00044         msg.palmpos.y = hand_palm_pos_[1]
00045         msg.palmpos.z = hand_palm_pos_[2]
00046         msg.ypr.x = hand_yaw_
00047         msg.ypr.y = hand_pitch_
00048         msg.ypr.z = hand_roll_
00049         # We don't publish native data types, see ROS best practices
00050         # 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_)
00051         pub_ros.publish(msg)
00052         rospy.sleep(rospy.get_param(PARAMNAME_FREQ, FREQUENCY_ROSTOPIC_DEFAULT))
00053 
00054 
00055 if __name__ == '__main__':
00056     parser = argparse.ArgumentParser(description='LeapMotion ROS driver. Message Sender module to ROS world using LeapSDK.')
00057     parser.add_argument('--freq', help='Frequency to publish sensed info as ROS message', type=float)
00058     args, unknown = parser.parse_known_args()
00059     if not args.freq:
00060         args.freq = FREQUENCY_ROSTOPIC_DEFAULT
00061     try:
00062         sender(args.freq)
00063     except rospy.ROSInterruptException:
00064         pass


leap_motion
Author(s): Florian Lier
autogenerated on Thu Aug 27 2015 13:50:42