I'm working in python within the ROS (Robot Operating System).
I have two paths in space defined like a list of x and y coords with a time value for each pair of coords.
Like a 3 tuple of (x,y,t)
Path one (ground_truth) is defined across time very densely with fairly regular spacing. Path two (amcl_pose) can either be sparse or dense depending on where you are on the path, but overall is defined at less points than the ground_truth.
the time vector for the ground truth is called ground_truth_time and the time vector for amcl_pose is called amcl_pose_time and similar names for their x vectors and y vectors:
What I have tried so far is something like:
from scipy.interpolate import griddata;`enter code here`
import numpy as np
method = ['nearest','linear','cubic']
time = np.linspace(0,tf,1000)
gt_x = griddata(ground_truth_time,ground_truth_x,time,method=method[1])
gt_y = griddata(ground_truth_time,ground_truth_y,time,method=method[1])
amcl_x = griddata(amcl_pose_time,amcl_pose_x,time,method=method[1])
amcl_y = griddata(amcl_pose_time,amcl_pose_y,time,method=method[1])
I would then like to calculate the distance between the paths at each point in time. Which would be really easy but something odd is happening.
I found by plotting slices of the paths on top of each other that the beginning of the curves do not lie on top of each other, nor do the ends, and nor do important features throughout the paths that should be near each other.
This is making my distance function which takes a time value and finds the distance between the paths at that time return a much larger number than it should.
This has been the major road block in getting something useful done this summer so any help would be hugely appreciated.
Also please let me know if there's any way I can reformat my question or extra information I should provide to help you help me, this is my first time asking a question here.
EDIT TO SHOW SECOND ATTEMPT IMPLEMENTING ADVICE: *I should point out that gt_t and amcl_t both start at time = 0 and end at nearly the same time: about 100secs. But amcl_t may switch from being sparse to dense throughout the vector it is not equally spaced out.
from scipy.interpolate import interp1d
import numpy as np
from matplotlib import pyplot as plt
#gt_t is an array of time corresponding to the list of points (gt_x,gt_y)
#amcl_t is an array of time corresponding to the list of points(amcl_x,amcl_y)
amcl_x_function = interp1d(amcl_t,amcl_x,kind='linear')
amcl_y_function = interp1d(amcl_t,amcl_y,kind='linear')
amcl_x_interped = amcl_x_function(gt_t)
amcl_y_interped = amcl_y_function(gt_t)
fig = plt.figure()
plt.plot(amcl_x_interped,amcl_y_interped)
plt.plot(gt_x,gt_y)
plt.show()
#this pair of coords are close together which is good
#since the two paths are always pretty close
print(amcl_x[0],amcl_y[0])
print(gt_x[0],gt_y[0]
#this pair is already so distant from eachother
#and I don't understand why as the two curves are always very close
#before interpolation
print(amcl_x[150],amcl_y[150])
print(gt_x[150],gt_y[150]
The plot this code produces creates two paths that always look very close to eachother. But the time values are so far off that you if you look at the distance between points at a particular point in time you'll find a huge distance. Because one of those points is back on an earlier part of the path while the second one is much further along. They should be near the same point but the interpolation is not working correctly.