shadowhand_subscriber.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 #
00003 # Copyright 2011 Shadow Robot Company Ltd.
00004 #
00005 # This program is free software: you can redistribute it and/or modify it
00006 # under the terms of the GNU General Public License as published by the Free
00007 # Software Foundation, either version 2 of the License, or (at your option)
00008 # any later version.
00009 #
00010 # This program is distributed in the hope that it will be useful, but WITHOUT
00011 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
00013 # more details.
00014 #
00015 # You should have received a copy of the GNU General Public License along
00016 # with this program.  If not, see <http://www.gnu.org/licenses/>.
00017 #
00018 
00019 """
00020 This is a simple subscriber example, subscribing to the joint_states topic and printing out the data in a per-joint basis
00021 To see how the joint_states topic looks like you can type the following in a terminal:
00022 for the simulated hand
00023 > rostopic echo /gazebo/joint_states
00024 
00025 for the real hand
00026 > rostopic echo /joint_states
00027 
00028 """
00029 
00030 import roslib; roslib.load_manifest('sr_example')
00031 import rospy
00032 import math
00033 from sensor_msgs.msg import JointState
00034 
00035 def callback(joint_state):
00036     """
00037     The callback function for the topic gazebo/joint_states (or joint_states if the real shadow hand is being used).
00038     It just displays the received information on the console.
00039     
00040     @param joint_state: the message containing the joints data.
00041     """
00042     for joint_name, position, velocity, effort in zip(joint_state.name, joint_state.position, joint_state.velocity, joint_state.effort):
00043         rospy.loginfo("[%s] : Pos = %f | Pos_deg = %f | Vel = %f | Effort = %f",
00044                       joint_name, position, math.degrees(position), velocity, effort)
00045 
00046 def listener():
00047     """
00048     Initialize the ROS node and the topic to which it subscribes.
00049     """
00050     rospy.init_node('shadowhand_joint_states_subscriber_python', anonymous=True)
00051     #For the simulated hand (running on the gazebo simulator)
00052     rospy.Subscriber("gazebo/joint_states", JointState, callback)
00053     #For the real shadow hand
00054     #rospy.Subscriber("joint_states", JointState, callback)
00055     rospy.spin()
00056 
00057 if __name__ == '__main__':
00058     listener()


sr_example
Author(s): Ugo Cupcic
autogenerated on Mon Oct 6 2014 07:49:30