Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
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
00052 rospy.Subscriber("gazebo/joint_states", JointState, callback)
00053
00054
00055 rospy.spin()
00056
00057 if __name__ == '__main__':
00058 listener()