Skip to content

Commit 53c6b19

Browse files
committed
fix bug with repeat optimization
due to unreset class variable also add exception handler just in case
1 parent afd7fae commit 53c6b19

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

roboticstoolbox/mobile/PoseGraph.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
class PGVertex(pgraph.UVertex):
1818

19-
nvertices = 0
19+
nvertices = 0 # reset this before each PGGraph build
2020

2121
def __init__(self, type, **kwargs):
2222
super().__init__(**kwargs)
@@ -160,6 +160,7 @@ def __init__(self, filename, lidar=False, verbose=False):
160160

161161
self.vindex = {}
162162
firstlidar = True
163+
PGVertex.nvertices = 0 # reset vertex counter in PGVertex class
163164
for line in f:
164165
# for zip file, we get data as bytes not str
165166
if isinstance(line, bytes):
@@ -479,13 +480,19 @@ def linearize_and_solve(self):
479480
jslice = slice(j * 3, (j + 1) * 3)
480481

481482
# accumulate the blocks in H and b
482-
H[islice, islice] += Hii
483-
H[jslice, jslice] += Hjj
484-
H[islice, jslice] += Hij
485-
H[jslice, islice] += Hij.T
486-
487-
b[islice, 0] += bi
488-
b[jslice, 0] += bj
483+
try:
484+
H[islice, islice] += Hii
485+
H[jslice, jslice] += Hjj
486+
H[islice, jslice] += Hij
487+
H[jslice, islice] += Hij.T
488+
489+
b[islice, 0] += bi
490+
b[jslice, 0] += bj
491+
except ValueError:
492+
print("linearize_and_solve failed")
493+
print(v)
494+
print(H.shape, b.shape, Hii.shape, Hjj.shape, Hij.shape)
495+
print(islice, jslice)
489496

490497
etotal += np.inner(e, e)
491498

0 commit comments

Comments
 (0)