sender.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 """ For backwards compatibility with the old driver files
4  Will be DELETED in the future """
5 
6 __author__ = 'flier'
7 
8 import argparse
9 
10 import rospy
11 import leap_interface
12 from leap_motion.msg import leap
13 from leap_motion.msg import leapros
14 
15 FREQUENCY_ROSTOPIC_DEFAULT = 0.01
16 NODENAME = 'leap_pub'
17 PARAMNAME_FREQ = 'freq'
18 PARAMNAME_FREQ_ENTIRE = '/' + NODENAME + '/' + PARAMNAME_FREQ
19 
20 def sender():
21  '''
22  This method publishes the data defined in leapros.msg to /leapmotion/data
23  '''
24  rospy.loginfo("Parameter set on server: PARAMNAME_FREQ={}".format(rospy.get_param(PARAMNAME_FREQ_ENTIRE, FREQUENCY_ROSTOPIC_DEFAULT)))
25 
27  li.setDaemon(True)
28  li.start()
29  # pub = rospy.Publisher('leapmotion/raw',leap)
30  pub_ros = rospy.Publisher('leapmotion/data',leapros, queue_size=2)
31  rospy.init_node(NODENAME)
32 
33  while not rospy.is_shutdown():
34  hand_direction_ = li.get_hand_direction()
35  hand_normal_ = li.get_hand_normal()
36  hand_palm_pos_ = li.get_hand_palmpos()
37  hand_pitch_ = li.get_hand_pitch()
38  hand_roll_ = li.get_hand_roll()
39  hand_yaw_ = li.get_hand_yaw()
40 
41  msg = leapros()
42  msg.direction.x = hand_direction_[0]
43  msg.direction.y = hand_direction_[1]
44  msg.direction.z = hand_direction_[2]
45  msg.normal.x = hand_normal_[0]
46  msg.normal.y = hand_normal_[1]
47  msg.normal.z = hand_normal_[2]
48  msg.palmpos.x = hand_palm_pos_[0]
49  msg.palmpos.y = hand_palm_pos_[1]
50  msg.palmpos.z = hand_palm_pos_[2]
51  msg.ypr.x = hand_yaw_
52  msg.ypr.y = hand_pitch_
53  msg.ypr.z = hand_roll_
54 
55  fingerNames = ['thumb', 'index', 'middle', 'ring', 'pinky']
56  fingerPointNames = ['metacarpal', 'proximal',
57  'intermediate', 'distal', 'tip']
58  for fingerName in fingerNames:
59  for fingerPointName in fingerPointNames:
60  pos = li.get_finger_point(fingerName, fingerPointName)
61  for iDim, dimName in enumerate(['x', 'y', 'z']):
62  setattr(getattr(msg, '%s_%s' % (fingerName, fingerPointName)),
63  dimName, pos[iDim])
64 
65  # We don't publish native data types, see ROS best practices
66  # 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_)
67  pub_ros.publish(msg)
68  rospy.sleep(rospy.get_param(PARAMNAME_FREQ_ENTIRE, FREQUENCY_ROSTOPIC_DEFAULT))
69 
70 
71 if __name__ == '__main__':
72  try:
73  sender()
74  except rospy.ROSInterruptException:
75  pass
def sender()
Definition: sender.py:20
Definition: sender.py:1


leap_motion
Author(s): Florian Lier , Mirza Shah , Isaac IY Saito
autogenerated on Tue Jun 2 2020 03:58:01