is_already_there.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 import rospy
00004 import sensor_msgs.msg
00005 import play_motion_msgs.srv as PMS
00006 
00007 class IsAlreadyThere:
00008     def __init__(self):
00009         self.srv = rospy.Service("play_motion/is_already_there",
00010                                  PMS.IsAlreadyThere,
00011                                  self.is_already_there)
00012         self.joint_sub = rospy.Subscriber("joint_states",
00013                                           sensor_msgs.msg.JointState,
00014                                           self.joint_state_cb)
00015         self.joint_states = {}
00016 
00017     def joint_state_cb(self, data):
00018         for i in range(len(data.name)):
00019             self.joint_states[data.name[i]] = data.position[i]
00020 
00021     def is_already_there(self, data):
00022         param = "play_motion/motions/{}".format(data.motion_name)
00023         if not rospy.has_param(param):
00024             rospy.logdebug("could not find motion {}".format(data.motion_name))
00025             return False
00026         motion = rospy.get_param(param)
00027         for i in range(len(motion['joints'])):
00028             joint_name = motion['joints'][i]
00029             if joint_name not in self.joint_states:
00030                 rospy.logdebug("could not find state of joint {}".format(joint_name))
00031                 return False
00032             if abs(motion['points'][0]['positions'][i]
00033                    - self.joint_states[joint_name]) > data.tolerance:
00034                 rospy.logdebug("tolerance exceeded fot joint {}, {} vs {}"
00035                               .format(joint_name,
00036                                       motion['points'][0]['positions'][i],
00037                                       self.joint_states[joint_name]))
00038                 return False
00039         return True
00040 
00041 
00042 if __name__ == "__main__":
00043     rospy.init_node("is_already_there")
00044     iat = IsAlreadyThere()
00045     rospy.spin()


play_motion
Author(s): Paul Mathieu
autogenerated on Wed Aug 26 2015 15:29:25