Skip to content

Commit 99e94a9

Browse files
committed
fix a few LGTM alerts
1 parent 74f9d63 commit 99e94a9

File tree

4 files changed

+39
-43
lines changed

4 files changed

+39
-43
lines changed

roboticstoolbox/mobile/PoseGraph.py

Lines changed: 34 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -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

roboticstoolbox/mobile/bug2.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ def query(self, start=None, goal=None, animate=False, movie=None, current=False)
127127
% Options::
128128
% 'animate' show a simulation of the robot moving along the path
129129
% 'movie',M create a movie
130-
% 'current' show the current position position as a black circle
130+
% 'current' show the current position as a black circle
131131
%
132132
% Notes::
133133
% - START and GOAL are given as X,Y coordinates in the grid map, not as
@@ -172,7 +172,7 @@ def query(self, start=None, goal=None, animate=False, movie=None, current=False)
172172
plt.plot(robot[0], robot[1], 'y.')
173173
plt.pause(0.1)
174174
if current:
175-
h = self.plot(robot[0], robot[1])
175+
h = self.plot(robot)
176176
plt.draw()
177177
if movie is not None:
178178
anim.plot(h)

roboticstoolbox/robot/DHFactor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -449,8 +449,8 @@ def __str__(self, q=None):
449449
q = "q{0}"
450450
else:
451451
q = "q"
452-
q = "q{0}"
453-
# For et in the object, display it, data comes from properties
452+
453+
# For each ET in the object, display it, data comes from properties
454454
# which come from the named tuple
455455
for et in self:
456456

roboticstoolbox/robot/ikine_evaluate2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
err = np.linalg.norm(T - robot.fkine(sol.q))
7676
print(' error', err)
7777

78-
if N > 0:
78+
if N > 0: # noqa
7979
# evaluate the execution time
8080
t = timeit.timeit(stmt=f"robot.ikine_min(T, q0=q0, qlim=True, method='{solver}')", setup=setup, number=N)
8181
else:

0 commit comments

Comments
 (0)