Skip to content

Commit ca7195f

Browse files
Fixed occasional math domain error
1 parent 3601bd1 commit ca7195f

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

Localization/particle_filter/particle_filter.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,15 @@ def plot_covariance_ellipse(xEst, PEst):
169169
smallind = 0
170170

171171
t = np.arange(0, 2 * math.pi + 0.1, 0.1)
172-
a = math.sqrt(eigval[bigind])
173-
b = math.sqrt(eigval[smallind])
172+
173+
#eigval[bigind] or eiqval[smallind] were occassionally negative numbers extremely
174+
#close to 0 (~10^-20), catch these cases and set the respective variable to 0
175+
try: a = math.sqrt(eigval[bigind])
176+
except ValueError: a = 0
177+
178+
try: b = math.sqrt(eigval[smallind])
179+
except ValueError: b = 0
180+
174181
x = [a * math.cos(it) for it in t]
175182
y = [b * math.sin(it) for it in t]
176183
angle = math.atan2(eigvec[bigind, 1], eigvec[bigind, 0])

0 commit comments

Comments
 (0)