11"""
22Iterative Closest Point (ICP) SLAM example
3- author: Atsushi Sakai (@Atsushi_twi)
3+ author: Atsushi Sakai (@Atsushi_twi), Göktuğ Karakaşlı
44"""
55
66import math
@@ -39,7 +39,7 @@ def ICP_matching(ppoints, cpoints):
3939 plt .plot (cpoints [0 , :], cpoints [1 , :], ".b" )
4040 plt .plot (0.0 , 0.0 , "xr" )
4141 plt .axis ("equal" )
42- plt .pause (1.0 )
42+ plt .pause (0.1 )
4343
4444 inds , error = nearest_neighbor_assosiation (ppoints , cpoints )
4545 Rt , Tt = SVD_motion_estimation (ppoints [:, inds ], cpoints )
@@ -93,18 +93,10 @@ def nearest_neighbor_assosiation(ppoints, cpoints):
9393 error = sum (d )
9494
9595 # calc index with nearest neighbor assosiation
96- inds = []
97- for i in range (cpoints .shape [1 ]):
98- minid = - 1
99- mind = float ("inf" )
100- for ii in range (ppoints .shape [1 ]):
101- d = np .linalg .norm (ppoints [:, ii ] - cpoints [:, i ])
102-
103- if mind >= d :
104- mind = d
105- minid = ii
106-
107- inds .append (minid )
96+ d = np .linalg .norm (
97+ np .repeat (cpoints , ppoints .shape [1 ], axis = 1 ) - np .tile (ppoints , (1 ,
98+ cpoints .shape [1 ])), axis = 0 )
99+ inds = np .argmin (d .reshape (cpoints .shape [1 ], ppoints .shape [1 ]), axis = 1 )
108100
109101 return inds , error
110102
@@ -130,7 +122,7 @@ def main():
130122 print (__file__ + " start!!" )
131123
132124 # simulation parameters
133- nPoint = 10
125+ nPoint = 1000
134126 fieldLength = 50.0
135127 motion = [0.5 , 2.0 , np .deg2rad (- 10.0 )] # movement [x[m],y[m],yaw[deg]]
136128
@@ -156,4 +148,4 @@ def main():
156148
157149
158150if __name__ == '__main__' :
159- main ()
151+ main ()
0 commit comments