ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
1

How to get robot velocity in gazebo

asked 2013-01-04 07:19:19 -0500

dmeltz gravatar image

updated 2013-01-04 20:28:29 -0500

Hello all.

I have built a little vehicle robot which can be controlled using keyboard. Now i am interested to get the robot velocity in order to close control loop on it.

The question is what is the best way to do that ?

Is there a special sensor that I can include in my robot URDF model ?

Or, should I try to get it directly from the /gazebo/model_states topic ?

update :

I tried to subscribing to /gazebo/model_states topic using the following code :

ros::Subscriber vehicle_velocity_sub_;

vehicle_velocity_sub_ = nh_.subscribe<geometry_msgs::Twist>("/gazebo/model_states/twist[2]", 1000, &Dany_Obstacle_Avoidance_Commander::twist_data_processor, this);

But i got the following error :

terminate called after throwing an instance of 'ros::InvalidNameException' what(): Character [[] at element [26] is not valid in Graph Resource Name [/gazebo/model_states/twist[2]]. Valid characters are a-z, A-Z, 0-9, / and _. Aborted (core dumped)

It seems that ROS does not understand the vector operator "[]" used with topics.

nevertheless if I try to use it in rostopic command :

rostopic echo /gazebo/model_states/twist[2]

from the terminal it works fine.

Does anyone know what I doing wrong ?

thanks.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2013-01-04 23:30:44 -0500

Georg gravatar image

Yousubscribe to a twist message, so /gazebo/model_states/twist is the topic name, you should then read the value you want from the geometry_msgs::Twist object you receive in the callback!

Best Georg

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2013-01-04 07:19:19 -0500

Seen: 2,930 times

Last updated: Jan 04 '13