get_joint_states.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 # Copyright 2011 Shadow Robot Company Ltd.
4 #
5 # This program is free software: you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by the Free
7 # Software Foundation version 2 of the License.
8 #
9 # This program is distributed in the hope that it will be useful, but WITHOUT
10 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 # more details.
13 #
14 # You should have received a copy of the GNU General Public License along
15 # with this program. If not, see <http://www.gnu.org/licenses/>.
16 
17 import rospy
18 from sensor_msgs.msg import JointState
19 from sr_utilities.srv import getJointState
20 import thread
21 
22 RATE = 100
23 
24 
25 class GetJointState(object):
26  def __init__(self):
27  rospy.init_node('get_joint_state_service', anonymous=True)
28 
29  self.subs_1 = rospy.Subscriber("/joint_states", JointState, self.callback1)
30  self.serv = rospy.Service('/getJointState', getJointState, self.getJointStateCB)
31 
32  self.joint_state_msg = JointState()
33 
34  self.mutex = thread.allocate_lock()
35 
36  r = rospy.Rate(RATE)
37  while not rospy.is_shutdown():
38  r.sleep()
39 
40  def callback1(self, data):
41  self.joint_state_msg = data
42 
43  def getJointStateCB(self, req):
44  res = self.joint_state_msg
45  return res
46 
47 if __name__ == '__main__':
48  service = GetJointState()


sr_utilities
Author(s): Ugo Cupcic
autogenerated on Mon Feb 28 2022 23:52:19