Ask Your Question
1

Get Modelstate Information for Turlebot

asked 2018-01-08 11:31:07 -0600

Baumboon gravatar image

updated 2018-01-22 11:42:35 -0600

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

edit retag flag offensive close merge delete

Comments

1

Keep in mind that if you use the model state from gazebo, your code won't be usable on a real robot.

ahendrix gravatar imageahendrix ( 2018-01-09 19:15:07 -0600 )edit

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.

jayess gravatar imagejayess ( 2018-01-22 11:18:02 -0600 )edit

posted answer solved the problem, i messed up with correct msgs, thank u for fast reply

Baumboon gravatar imageBaumboon ( 2018-01-22 11:26:16 -0600 )edit

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.

jayess gravatar imagejayess ( 2018-01-22 11:28:52 -0600 )edit

2 Answers

Sort by ยป oldest newest most voted
1

answered 2018-01-22 11:25:46 -0600

Baumboon gravatar image

updated 2018-12-17 19:26:46 -0600

jayess gravatar image

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

edit flag offensive delete link more
1

answered 2018-01-09 17:43:25 -0600

jorge gravatar image

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.

edit flag offensive delete link more

Comments

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

?

Baumboon gravatar imageBaumboon ( 2018-01-21 06:26:30 -0600 )edit

Can u tell me how the subscriber should look like? I am relative new with coding in ros ...

Baumboon gravatar imageBaumboon ( 2018-01-21 06:27:36 -0600 )edit

The ROS tutorials cover perfectly the issue: http://wiki.ros.org/ROS/Tutorials/Wri...

jorge gravatar imagejorge ( 2018-01-21 14:04:45 -0600 )edit

updated question thank u for ur help got it now!

Baumboon gravatar imageBaumboon ( 2018-01-22 04:01:06 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2018-01-08 11:31:07 -0600

Seen: 843 times

Last updated: Dec 17 '18