How to calculate closest coordinate from spawn point - turtlesim
I'm new to ROS and I want to write a python program that calculates the closest coordinate to the spawn point from a list of coordinates. I know i need to use actionlib and Pose to do so but I am not sure where to start.
Asked by topological on 2022-08-15 14:55:22 UTC
Answers
Assuming you have the starting position p_0 = (x,y,z)
from ROS message called Pose
and it's field Position and a list of coordinates = [(x_1, y_1, z_1), (x_2, y_2, z_2), ..., (x_n, y_n, z_n)]
, you can get the closest point by calculating a list of the lengths, e.g.
lengths = [vector3_length(p_0 - p) for p in coordinates]
,
where you have your function for vector3_length
(2nd root of the sum of squared differences x_0-x_i
, y_0-y_i
and z_0-z_i
)), then taking the minimum value with its index (enumerate
etc.) - use it to choose the correct closest point.
If you want to get a more ROS-based answer, you should give us more material - as mentioned by @Ravi Joshi in the comments, ROS Tutorials is an excellent place to start.
Asked by ljaniec on 2022-08-16 08:25:45 UTC
Comments
http://wiki.ros.org/ROS/Tutorials
Asked by ravijoshi on 2022-08-16 05:01:56 UTC