$search
00001 #!/usr/bin/env python 00002 ################################################################# 00003 ##\file 00004 # 00005 # \note 00006 # Copyright (c) 2011-2012 \n 00007 # Fraunhofer Institute for Manufacturing Engineering 00008 # and Automation (IPA) \n\n 00009 # 00010 ################################################################# 00011 # 00012 # \note 00013 # Project name: care-o-bot 00014 # \note 00015 # ROS stack name: cob_calibration 00016 # \note 00017 # ROS package name: cob_calibration_executive 00018 # 00019 # \author 00020 # Author: Sebastian Haug, email:sebhaug@gmail.com 00021 # \author 00022 # Supervised by: Florian Weisshardt, email:florian.weisshardt@ipa.fhg.de 00023 # 00024 # \date Date of creation: January 2012 00025 # 00026 ################################################################# 00027 # 00028 # Redistribution and use in source and binary forms, with or without 00029 # modification, are permitted provided that the following conditions are met: 00030 # 00031 # - Redistributions of source code must retain the above copyright 00032 # notice, this list of conditions and the following disclaimer. \n 00033 # - Redistributions in binary form must reproduce the above copyright 00034 # notice, this list of conditions and the following disclaimer in the 00035 # documentation and/or other materials provided with the distribution. \n 00036 # - Neither the name of the Fraunhofer Institute for Manufacturing 00037 # Engineering and Automation (IPA) nor the names of its 00038 # contributors may be used to endorse or promote products derived from 00039 # this software without specific prior written permission. \n 00040 # 00041 # This program is free software: you can redistribute it and/or modify 00042 # it under the terms of the GNU Lesser General Public License LGPL as 00043 # published by the Free Software Foundation, either version 3 of the 00044 # License, or (at your option) any later version. 00045 # 00046 # This program is distributed in the hope that it will be useful, 00047 # but WITHOUT ANY WARRANTY; without even the implied warranty of 00048 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00049 # GNU Lesser General Public License LGPL for more details. 00050 # 00051 # You should have received a copy of the GNU Lesser General Public 00052 # License LGPL along with this program. 00053 # If not, see <http://www.gnu.org/licenses/>. 00054 # 00055 ################################################################# 00056 PKG = 'cob_calibration_executive' 00057 NODE = 'joint_state_listener_arm' 00058 import roslib; roslib.load_manifest(PKG) 00059 import rospy 00060 import sensor_msgs.msg 00061 00062 ''' 00063 Print joint states for cob arm. 00064 00065 Listens to /joints_states topic for joint state messages from arm controller 00066 and prints them. 00067 ''' 00068 def main(): 00069 rospy.init_node(NODE) 00070 print "==> %s started " % NODE 00071 00072 # get joint names for arm from parameter server 00073 joint_names = None 00074 try: joint_names = rospy.get_param("arm_controller/joint_names") # real hardware 00075 except KeyError: pass 00076 try: joint_names = rospy.get_param("arm_controller/joints") # simulation 00077 except KeyError: pass 00078 if joint_names == None: 00079 print "Could not get joint names from parameter server. exiting..." 00080 exit(-1) 00081 print joint_names 00082 00083 while not rospy.is_shutdown(): 00084 if rospy.is_shutdown(): exit(0) 00085 00086 # try getting /joint_states message 00087 try: 00088 msg = rospy.wait_for_message("/joint_states", sensor_msgs.msg.JointState) 00089 except rospy.exceptions.ROSInterruptException: 00090 exit(0) 00091 if joint_names[0] in msg.name: 00092 # message is from arm 00093 angles = [] 00094 for name in joint_names: 00095 angles.append(msg.position[msg.name.index(name)]) 00096 # nicely print joint angles with 8 digits 00097 print "[" + ", ".join(["%0.8f" % i for i in angles]) + "]" 00098 00099 if __name__ == '__main__': 00100 main()