Weird behavior when instantiating SimpleActionClient right after initializing node in rospy
Hi all,
I ran into a problem when I ran python scripts where an actionlib action client is intantiated right after the node a the wait_for_server() function does not seem to work always properly (it just does not wait).
For example:
if __name__ == '__main__':
rospy.init_node('test_manipulation')
#rospy.sleep(1.0)
trajClient = actionlib.SimpleActionClient("r_arm_controller/joint_trajectory_action", pr2_controllers_msgs.msg.JointTrajectoryAction)
if not trajClient.wait_for_server(rospy.Duration(10.0)):
rospy.logerr("Could not connect to actionserver " )
exit(1)
will return immediately, ie. it goes into the if branch and prints the "Could not connect to actionserver " error statement, even though I would expect it to wait 10s. If I uncomment rospy.sleep(1.0), everything works always as expected. Is there a more elegant solution to this?
It seems like it is not always reproducable, but I have seen it on happen on my machine and the PR2 running Diamondback and Lucid.
Chris