@@ -161,6 +161,7 @@ def __init__(self, filename, laser=False, verbose=False):
161
161
lasermeta = tokens [2 :6 ]
162
162
firstlaser = False
163
163
164
+ v = self .graph .add_vertex ()
164
165
v .theta = np .arange (0 , nbeams ) * float (tokens [4 ]) + float (tokens [2 ])
165
166
v .range = np .array ([float (x ) for x in tokens [9 :nbeams + 9 ]])
166
167
v .time = float (tokens [21 + nbeams ])
@@ -189,7 +190,6 @@ def scan(self, i):
189
190
return v .range , v .theta
190
191
191
192
def scanxy (self , i ):
192
- v = self .vindex [i ]
193
193
194
194
range , theta = self .scan (i )
195
195
x = range * np .cos (theta )
@@ -328,10 +328,6 @@ def bresenham(p1, p2):
328
328
329
329
return x , y
330
330
331
-
332
-
333
-
334
-
335
331
336
332
# This source code is part of the graph optimization package
337
333
# deveoped for the lectures of robotics2 at the University of Freiburg.
@@ -367,43 +363,43 @@ def bresenham(p1, p2):
367
363
# PURPOSE.
368
364
369
365
370
- # %ls-slam.m
371
- # %this file is released under the creative common license
366
+ # %ls-slam.m
367
+ # %this file is released under the creative common license
368
+
369
+ # solves a graph-based slam problem via least squares
370
+ # vmeans: matrix containing the column vectors of the poses of the vertices
371
+ # the vertices are odrered such that vmeans[i] corresponds to the ith id
372
+ # eids: matrix containing the column vectors [idFrom, idTo]' of the ids of the vertices
373
+ # eids[k] corresponds to emeans[k] and einfs[k].
374
+ # emeans: matrix containing the column vectors of the poses of the edges
375
+ # einfs: 3d matrix containing the information matrices of the edges
376
+ # einfs(:,:,k) refers to the information matrix of the k-th edge.
377
+ # n: number of iterations
378
+ # newmeans: matrix containing the column vectors of the updated vertices positions
372
379
373
- # solves a graph-based slam problem via least squares
374
- # vmeans: matrix containing the column vectors of the poses of the vertices
375
- # the vertices are odrered such that vmeans[i] corresponds to the ith id
376
- # eids: matrix containing the column vectors [idFrom, idTo]' of the ids of the vertices
377
- # eids[k] corresponds to emeans[k] and einfs[k].
378
- # emeans: matrix containing the column vectors of the poses of the edges
379
- # einfs: 3d matrix containing the information matrices of the edges
380
- # einfs(:,:,k) refers to the information matrix of the k-th edge.
381
- # n: number of iterations
382
- # newmeans: matrix containing the column vectors of the updated vertices positions
380
+ def optimize (self , iterations = 10 , animate = False , retain = False ):
383
381
384
- def optimize (self , iterations = 10 , animate = False , retain = False ):
385
-
386
-
387
- g2 = PGraph (self .graph ) # deep copy
382
+
383
+ g2 = PGraph (self .graph ) # deep copy
384
+
385
+ eprev = math .inf
386
+ for i in range (iterations ):
387
+ if animate :
388
+ if not retain :
389
+ plt .clf ()
390
+ g2 .plot ()
391
+ plt .pause (0.5 )
388
392
389
- eprev = math .inf
390
- for i in range (iterations ):
391
- if animate :
392
- if not retain :
393
- plt .clf ()
394
- g2 .plot ()
395
- plt .pause (0.5 )
396
-
397
- vmeans , energy = linearize_and_solve (g2 )
398
- g2 .setcoord (vmeans )
399
-
400
- if energy >= eprev :
401
- break
402
- eprev = energy
393
+ vmeans , energy = linearize_and_solve (g2 )
394
+ g2 .setcoord (vmeans )
403
395
404
- self .graph = g2
396
+ if energy >= eprev :
397
+ break
398
+ eprev = energy
399
+
400
+ self .graph = g2
405
401
406
- return g2
402
+ return g2
407
403
408
404
409
405
#computes the taylor expansion of the error function of the k_th edge
@@ -460,7 +456,7 @@ def linear_factors(self, edge):
460
456
461
457
ztinv = base .trinv2 (zt_ij )
462
458
T = ztinv @ f_ij
463
- e = np . r_ [ base . transl2 (T ), base . angle ( T )]
459
+ e = tr2xyt (T )
464
460
ztinv [0 :2 ,2 ] = 0
465
461
A = ztinv @ A
466
462
B = ztinv @ B
0 commit comments