Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 15 additions & 17 deletions Localization/particle_filter/particle_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,9 @@ def pf_localization(px, pw, z, u):
xEst = px.dot(pw.T)
PEst = calc_covariance(xEst, px, pw)

px, pw = re_sampling(px, pw)

N_eff = 1.0 / (pw.dot(pw.T))[0, 0] # Effective particle number
if N_eff < NTh:
px, pw = re_sampling(px, pw)
return xEst, PEst, px, pw


Expand All @@ -138,21 +139,18 @@ def re_sampling(px, pw):
low variance re-sampling
"""

N_eff = 1.0 / (pw.dot(pw.T))[0, 0] # Effective particle number
if N_eff < NTh:
w_cum = np.cumsum(pw)
base = np.cumsum(pw * 0.0 + 1 / NP) - 1 / NP
re_sample_id = base + np.random.rand(base.shape[0]) / NP

indexes = []
ind = 0
for ip in range(NP):
while re_sample_id[ip] > w_cum[ind]:
ind += 1
indexes.append(ind)

px = px[:, indexes]
pw = np.zeros((1, NP)) + 1.0 / NP # init weight
w_cum = np.cumsum(pw)
base = np.arange(0.0, 1.0, 1/NP)
re_sample_id = base + np.random.uniform(0, 1/NP)
indexes = []
ind = 0
for ip in range(NP):
while re_sample_id[ip] > w_cum[ind]:
ind += 1
indexes.append(ind)

px = px[:, indexes]
pw = np.zeros((1, NP)) + 1.0 / NP # init weight

return px, pw

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def calc_obstacle_cost(trajectory, ob, config):
rot = np.transpose(rot, [2, 0, 1])
local_ob = ob[:, None] - trajectory[:, 0:2]
local_ob = local_ob.reshape(-1, local_ob.shape[-1])
local_ob = np.array([local_ob @ -x for x in rot])
local_ob = np.array([local_ob @ x for x in rot])
local_ob = local_ob.reshape(-1, local_ob.shape[-1])
upper_check = local_ob[:, 0] <= config.robot_length / 2
right_check = local_ob[:, 1] <= config.robot_width / 2
Expand Down
18 changes: 5 additions & 13 deletions SLAM/iterative_closest_point/iterative_closest_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,18 +93,10 @@ def nearest_neighbor_assosiation(ppoints, cpoints):
error = sum(d)

# calc index with nearest neighbor assosiation
inds = []
for i in range(cpoints.shape[1]):
minid = -1
mind = float("inf")
for ii in range(ppoints.shape[1]):
d = np.linalg.norm(ppoints[:, ii] - cpoints[:, i])

if mind >= d:
mind = d
minid = ii

inds.append(minid)
d = np.linalg.norm(
np.repeat(cpoints, ppoints.shape[1], axis=1) - np.tile(ppoints, (1,
cpoints.shape[1])), axis=0)
inds = np.argmin(d.reshape(cpoints.shape[1], ppoints.shape[1]), axis=1)

return inds, error

Expand Down Expand Up @@ -156,4 +148,4 @@ def main():


if __name__ == '__main__':
main()
main()