PDA

View Full Version : Python + ROS question regarding service response object



Pi Robot
12-08-2010, 09:51 AM
I'm guessing this is a question for Fergs but if anyone else knows the answer, please shout. For the life of me I can't figure out what's wrong with the following code. I am trying to use David Lu's arm_kinematics package and I am starting with forward kinematics on an arm with 4 joints. The following code barfs with the error:

AttributeError: 'GetKinematicSolverInfoResponse' object has no attribute 'joint_names'

on the line that reads:

for joint in solver_info.joint_names:

But the line just above it:

rospy.loginfo(solver_info)

prints out the following info which clearly shows that solver_info has the 'joint_names' list attribute!


[INFO] 1291822934.355028: kinematic_solver_info:
joint_names: ['left_shoulder_pan_joint', 'left_shoulder_lift_joint', 'left_elbow_joint', 'left_wrist_joint']
limits:
-
joint_name: left_shoulder_pan_joint
has_position_limits: 1
min_position: -1.57000005245
max_position: 1.57000005245
has_velocity_limits: 0
max_velocity: 0.0
has_acceleration_limits: 0
max_acceleration: 0.0
-
joint_name: left_shoulder_lift_joint
has_position_limits: 1
min_position: -1.57000005245
max_position: 1.57000005245
has_velocity_limits: 0
max_velocity: 0.0
has_acceleration_limits: 0
max_acceleration: 0.0
-
joint_name: left_elbow_joint
has_position_limits: 1
min_position: -1.57000005245
max_position: 1.57000005245
has_velocity_limits: 0
max_velocity: 0.0
has_acceleration_limits: 0
max_acceleration: 0.0
-
joint_name: left_wrist_joint
has_position_limits: 1
min_position: -1.57000005245
max_position: 1.57000005245
has_velocity_limits: 0
max_velocity: 0.0
has_acceleration_limits: 0
max_acceleration: 0.0
link_names: []Here is the code that generates the error when I run it with rosrun:


import roslib; roslib.load_manifest('pi_robot')
import rospy
from sensor_msgs.msg import JointState
from kinematics_msgs.msg import KinematicSolverInfo, PositionIKRequest
from kinematics_msgs.srv import GetKinematicSolverInfo, GetKinematicSolverInfoResponse, GetPositionFK, GetKinematicSolverInfo, GetPositionFKRequest, GetPositionFKResponse

import time

class get_fk():
def __init__(self):
rospy.init_node("pi_robot_get_fk")

self.rate = 1
r = rospy.Rate(self.rate)

rospy.wait_for_service('left_arm_kinematics/get_fk')
rospy.wait_for_service('left_arm_kinematics/get_fk_solver_info')

get_fk_proxy = rospy.ServiceProxy('left_arm_kinematics/get_fk', GetPositionFK, persistent=True)
get_fk_solver_info_proxy = rospy.ServiceProxy('left_arm_kinematics/get_fk_solver_info', GetKinematicSolverInfo)

solver_info = get_fk_solver_info_proxy()
rospy.loginfo(solver_info)

for joint in solver_info.joint_names:
self.left_arm_joints.append(joint)
rospy.loginfo("Adding joint " + str(joint))

self.request.robot_state.joint_state = JointState()
self.request.robot_state.joint_state.header.frame_ id = 'torso_link'
self.request.robot_state.joint_state.name = self.left_arm_joints
self.request.robot_state.joint_state.position = [0]*len(self.left_arm_joints)
self.request.robot_state.joint_state.position[0] = 1.0

self.request = GetPositionFKRequest()
self.request.fk_link_names = list()
self.request.fk_link_names.append("left_shoulder_pan_link")
self.request.fk_link_names.append("left_shoulder_left_link")
self.request.fk_link_names.append("left_elbow_link")
self.request.fk_link_names.append("left_wrist_link")
self.request.fk_link_names.append("left_hand_link")
self.request.fk_link_names.append("left_finger_link")
self.request.header.frame_id = "torso_link"

while not rospy.is_shutdown():
try:
response = get_fk_proxy(self.request)
rospy.loginfo(response)
except rospy.ServiceException, e:
print "Service call failed: %s"%e

r.sleep()


if __name__ == '__main__':
try:
get_fk()
except rospy.ROSInterruptException:
rospy.loginfo("Shutting down left arm forward kinematics node node...")

lnxfergy
12-08-2010, 10:16 AM
You have a message *inside* a service return. So, I think it should be:

for joint in solver_info.kinematic_solver_info.joint_names:

As solver_info is of type GetKinematicSolverInfoResponse, and has a kinematic_solver_info component that is supposed to be of type KinematicsMsgs/KinematicSolverInfo

-Fergs

Pi Robot
12-08-2010, 12:24 PM
Thanks Fergs--that was it exactly. The sad thing is I thought I already tried that but I kept persisting on a typo, using solver_info.kinematics_solver_info (with an "s") instead of solver_info.kinematic_solver_info (without an "s") which generated the same error as if "joint_names" did not exist. Crappy proof readers beware!

--patrick