0
$\begingroup$

Rosanswers logo

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.


Originally posted by dmeltz on ROS Answers with karma: 192 on 2013-01-04

Post score: 1

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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


Originally posted by Georg with karma: 328 on 2013-01-05

This answer was ACCEPTED on the original site

Post score: 1

$\endgroup$

Your Answer

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