

return_joint_states) 27 28 29 #thread function: listen for joint_states messages 30 def joint_states_listener( self): 31 rospy. Service( ' return_joint_states ', ReturnJointStates, self. init_node( ' joint_states_listener ') 18 self. load_manifest( ' joint_states_listener ') 7 import rospy 8 from joint_states_listener.srv import * 9 from sensor_msgs.msg import JointState 10 import threading 11 12 13 #holds the latest states obtained from joint_states messages 14 class LatestJointStates: 15 16 def _init_( self): 17 rospy. Put the following into nodes/joint_states_listener.py:ġ #!/usr/bin/env python 2 #spins off a thread to listen for joint_states messages 3 #and provides the same information (or subsets of) as a service 4 5 import roslib 6 roslib. In your CMakeLists.txt and type make in the joint_states_listener directory to generate the service message files. Put the following into srv/ReturnJointStates.srv: string name Now we need to define a service message that we can use to ask for specific joint angles, velocities, and efforts. Roscreate-pkg joint_states_listener rospy sensor_msgsĪfter this is done we'll need to roscd to the package we created, since we'll be using it as our workspace. To do this we'll use the handy roscreate-pkg command where we want to create the package directory: The first thing we'll need to do is create a package. The node we present in this tutorial listens to and keeps track of the most recent joint_states message, and offers a service that returns the current position, velocity, and effort for any set of desired joint names. If you happen to want to filter out only a few joint angles and obtain their joint values, you might want to write a server such as this one. If you type rostopic echo joint_statesĪt the command line after a real or simulated robot has been launched, you can see these messages as they are published. This message contains arrays of joint names (string name), along with the corresponding positions ( float64 position), velocities ( float64 velocity), and efforts ( float64 effort). The current positions and angles for the robot are by default being broadcast on a message topic called joint_states, of type sensor_msgs/JointState.
View joint angles postview how to#
In this tutorial, we will show you how to get the current joint angles for the PR2 robot (arm, head, torso, etc.) from within a ROS node, using sensor_msgs/JointState messages.īefore you begin, bring up a robot, either on the hardware or in gazebo.
