@@ -161,6 +161,7 @@ def __init__(self, filename, laser=False, verbose=False):
161161 lasermeta = tokens [2 :6 ]
162162 firstlaser = False
163163
164+ v = self .graph .add_vertex ()
164165 v .theta = np .arange (0 , nbeams ) * float (tokens [4 ]) + float (tokens [2 ])
165166 v .range = np .array ([float (x ) for x in tokens [9 :nbeams + 9 ]])
166167 v .time = float (tokens [21 + nbeams ])
@@ -189,7 +190,6 @@ def scan(self, i):
189190 return v .range , v .theta
190191
191192 def scanxy (self , i ):
192- v = self .vindex [i ]
193193
194194 range , theta = self .scan (i )
195195 x = range * np .cos (theta )
@@ -328,10 +328,6 @@ def bresenham(p1, p2):
328328
329329 return x , y
330330
331-
332-
333-
334-
335331
336332# This source code is part of the graph optimization package
337333# deveoped for the lectures of robotics2 at the University of Freiburg.
@@ -367,43 +363,43 @@ def bresenham(p1, p2):
367363# PURPOSE.
368364
369365
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
372379
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 ):
383381
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 )
388392
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 )
403395
404- self .graph = g2
396+ if energy >= eprev :
397+ break
398+ eprev = energy
399+
400+ self .graph = g2
405401
406- return g2
402+ return g2
407403
408404
409405#computes the taylor expansion of the error function of the k_th edge
@@ -460,7 +456,7 @@ def linear_factors(self, edge):
460456
461457 ztinv = base .trinv2 (zt_ij )
462458 T = ztinv @ f_ij
463- e = np . r_ [ base . transl2 (T ), base . angle ( T )]
459+ e = tr2xyt (T )
464460 ztinv [0 :2 ,2 ] = 0
465461 A = ztinv @ A
466462 B = ztinv @ B
0 commit comments