0
$\begingroup$

Rosanswers logo

Hello Guys,

I run ros Kinetic with gazebo 7.0. My project is a turtlebot who should drive to several objects and try to push them away after a try he should drive to the middle of the room again and drive to the next object. I tried Odometry for get information about the position of the robot but i need accurated position so i need model state.

So i think it should have a higher accuracy when i use modelstates.

I got my odometry information with following piece of code:

def newOdom(msg):
    global x
    global y
    global theta
    
    x = msg.pose.pose.position.x
    y = msg.pose.pose.position.y

    rot_q = msg.pose.pose.orientation
    (roll,pitch,theta) = euler_from_quaternion ([rot_q.x,rot_q.y,rot_q.z,rot_q.w])
rospy.init_node("speed_controller")
sub = rospy.Subscriber("/odom",Odometry,newOdom)

My question is: It is correct to make the same with the gazebo_msgs/ModelState I updated my code to :

def newModel(msg):
    global x
    global y
    global theta
    
    x = msg.pose[1].pose.position.x
    y = msg.pose.pose[1].position.y

    rot_q = msg.pose[1].pose.orientation
    (roll,pitch,theta) = euler_from_quaternion ([rot_q.x,rot_q.y,rot_q.z,rot_q.w])
rospy.init_node("speed_controller")
sub = rospy.Subscriber("/gazebo/ModelStates",ModelState,newModel)

I looked in publishing message and mobile base is at position 2 so it should be index 1. But all i got as x and y value is 0 even if i move the robot. Any further help?

With the subscriber note above i got no error but not the correct values.

I even tried out :

sub = rospy.Subscriber("/gazebo/model_states",ModelState,newModel)

If u use this i got following error:

[ERROR] [1430752035.526287969, 184.707000000]: Client [/listener] wants topic /gazebo/model_states to have datatype/md5sum [gazebo_msgs/ModelState/9330fd35f2fcd82d457e54bd54e10593], but our version has [gazebo_msgs/ModelStates/48c080191eb15c41858319b4d8a609c2]. Dropping connection.

This is also solved at Modelstate error


Originally posted by Baumboon on ROS Answers with karma: 206 on 2018-01-08

Post score: 2


Original comments

Comment by ahendrix on 2018-01-09:
Keep in mind that if you use the model state from gazebo, your code won't be usable on a real robot.

Comment by jayess on 2018-01-22:
Can you please update your question with a copy and paste of the error instead of a screenshot? Text is searchable, images are not. Thanks.

Comment by Baumboon on 2018-01-22:
posted answer solved the problem, i messed up with correct msgs, thank u for fast reply

Comment by jayess on 2018-01-22:
Could you please still take a moment to update your question with a copy and paste of the error? This will help others to solve similar problems. Thanks.

$\endgroup$

2 Answers 2

0
$\begingroup$

Rosanswers logo

Yes, /gazebo/model_states topic. You need to find the index of mobile_base in the models list, e.g. 6 in the amcl_demo:

name: [bookshelf, jersey_barrier, ground_plane_0, unit_cylinder_1, Dumpster, cube_20k, mobile_base]

and use this index to access the list of poses. (e.g. msg.pose[6])

Odometry is not valid as global pose, as it accumulates error as the robot moves. Specially if the wheels glide, like when pushing heavy objects.


Originally posted by jorge with karma: 2284 on 2018-01-09

This answer was NOT ACCEPTED on the original site

Post score: 1


Original comments

Comment by Baumboon on 2018-01-21:
so if i understand u right it should look like:

def newModelState(msg):
    global x
    global y
    global theta

    x = msg.pose[6].pose.position.x
    y = msg.pose[6].pose.position.y

    rot_q = msg.pose[6].pose.orientation

?

Comment by Baumboon on 2018-01-21:
Can u tell me how the subscriber should look like? I am relative new with coding in ros ...

Comment by jorge on 2018-01-21:
The ROS tutorials cover perfectly the issue: http://wiki.ros.org/ROS/Tutorials/WritingPublisherSubscriber%28python%29

Comment by Baumboon on 2018-01-22:
updated question thank u for ur help got it now!

$\endgroup$
0
$\begingroup$

Rosanswers logo

Hello guys , solved this problem by myself. The problem was there are to messages.

I made the mistake with :

sub = rospy.Subscriber("/gazebo/ModelStates",ModelState,newModel)

the correct one is :

sub = rospy.Subscriber("/gazebo/model_states",ModelStates,newModel)

Fixing this solved the error and i can run my program now without any problems


Originally posted by Baumboon with karma: 206 on 2018-01-22

This answer was ACCEPTED on the original site

Post score: 2

$\endgroup$

Your Answer

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