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

Calculating distance using linear velocity and time.

asked 2017-08-27 21:44:54 -0500

sandhan26 gravatar image

The general simplest approach in ROS is to calculate the distance by multiplying the time elapsed with the linear velocity. As can be seen from this link http://wiki.ros.org/turtlesim/Tutoria...

Since, i am a beginner in ROS i tried the approach used in games. Which is adding the velocity every time to a current_distance variable initialized to zero. But this approach doesn't work well. Code here https://pastebin.com/c0dJB4XQ

if i want to travel 5 meters in the first method, i will have to enter 50,000 meters to travel the same distance on the screen. I don't seem to figure out this anomaly.

I used turtlesim for my practice and learning.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2017-08-27 22:34:43 -0500

ufr3c_tjc gravatar image

You have to enter 50,000 because you are running a while loop which adds the current velocity to a "distance", publishes a command, and then immediately repeats, with no delay. The while loop will run as fast as it can, repeating distance/linearVel times (ie, 100,000 times) and then exiting, no matter how far the turtle actually traveled. It just so happened that 50,000 was the magic number for you, and it has no real relationship to the desired 5 metres.

I don't know where your idea came from to take time out of the equation, but please forget it. Distance is always speed integrated over time. Never use anything else.

edit flag offensive delete link more

Comments

I think i got your point. Thanks.

sandhan26 gravatar image sandhan26  ( 2017-08-28 03:10:32 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2017-08-27 21:44:54 -0500

Seen: 902 times

Last updated: Aug 27 '17