How to get robot velocity in gazebo
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.