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

Traveled Distance measurement

asked 2013-07-04 23:57:02 -0500

Lucile gravatar image

updated 2013-07-04 23:58:10 -0500

Hi !

I would like to measure the total distance the Turtlebot traveled while navigating. So I was wondering if there was a way to get this information from the odometry sensors ?

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted

answered 2013-07-05 00:10:57 -0500

Procópio gravatar image

updated 2013-07-05 00:13:42 -0500

You can subscribe to the publication of the pose topic and store each publication in a pose array, for example. Then you can process that array to sum the distances between each reading.

float path_length = 0.0;
std::vector<geometry_msgs::PoseStamped>::iterator it = plan.poses.begin();
geometry_msgs::PoseStamped last_pose;
last_pose = *it;
for (; it!=plan.poses.end(); ++it) {
   path_length += hypot(  (*it).pose.position.x - last_pose.pose.position.x, 
                         (*it).pose.position.y - last_pose.pose.position.y );
   last_pose = *it;
ROS_INFO("... path length: %6.3f", path_length);

source of this code

you can do the same with the odometry publications, but you may have an accumulated error there.

edit flag offensive delete link more


Yes, I thought about this solution :) But I hoped there was a way to get the data from wheels' odometry and that I just didn't find it. I'll do it like this then. Thanks.

Lucile gravatar image Lucile  ( 2013-07-05 01:58:46 -0500 )edit

you can do that, but you will have errors due to slippage, sensors, and others... if you want to try you have to find out what program is publishing the turtlebot odom, because it must access your sensors readings to build the message, so you can get those readings too and try to integrate them.

Procópio gravatar image Procópio  ( 2013-07-05 02:18:42 -0500 )edit

Hi, I have one question about what you said. I make sense the code you post, but how can calculate it in Matlab environment. Is there any easier way. Thanks.

Wentao gravatar image Wentao  ( 2017-10-31 08:26:56 -0500 )edit

Question Tools



Asked: 2013-07-04 23:57:02 -0500

Seen: 2,983 times

Last updated: Jan 13 '16