0
$\begingroup$

Rosanswers logo

This code works in cpp.

 ros::ServiceClient client = n.serviceClient<gazebo_msgs::GetModelState>("/gazebo/get_model_state");
 gazebo_msgs::GetModelState getmodelstate;
 getmodelstate.request.model_name ="rrbot";
 client.call(getmodelstate);

But in python ...

 # Take pose from gazebo: ignore rviz pose: 
 rospy.wait_for_service("/gazebo/get_model_state")
 client = rospy.ServiceProxy("/gazebo/get_model_state", GetModelState)
 getmodelstate = client(model_name="rrbot")
 
 # Set starting data x,y and theta for odometry used in handelerJointControllerState
 self.theta = getmodelstate.response.pose.orientation.z  

I get the following error:

 self.theta = getmodelstate.response.pose.orientation.z
AttributeError: 'GetModelStateResponse' object has no attribute 'response'

Any thoughts on the nature of this error.


Originally posted by rnunziata on ROS Answers with karma: 713 on 2015-02-18

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

Take a look at this answer. Looks like you might need to add a relative_entity_name variable in the request and that the response does not have a response field, rather you should use self.theta = getmodelstate.pose.orientation.z. I have not tried the code from the linked answer, but it looks reasonable and was accepted as a solution for making the exact same service calls you are trying to make.

Also, the z field in orientation is part of a quaternion and not equal to yaw. See tf/transformations.py for how to convert quaternions to Euler angles.


Originally posted by Thomas D with karma: 4347 on 2015-02-18

This answer was ACCEPTED on the original site

Post score: 0


Original comments

Comment by rnunziata on 2015-02-18:
much thanks

Comment by UserK on 2016-12-12:
Could you explain what relative_entity_name is?

Comment by Thomas D on 2016-12-13:
The GetModelState service has a request portion that contains model_name and relative_entity_name. The service documentation states: return pose and twist relative to this entity.

Comment by UserK on 2016-12-13:
Thanks, basically thanks to this field you can specify in which frame the pose information should be expressed. You can leave it empty or specify for example "world"

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.