File particle_filter.py changed (mode: 100644) (index 9b6d803..437bb0d) |
... |
... |
while True: |
210 |
210 |
|
|
211 |
211 |
weight_sum = 0 |
weight_sum = 0 |
212 |
212 |
|
|
213 |
|
new_particles = [] |
|
|
213 |
|
good_particles = [] |
|
214 |
|
bad_particles = [] |
214 |
215 |
|
|
215 |
216 |
# Loop over all particles |
# Loop over all particles |
216 |
217 |
for i in range(len(particles)): |
for i in range(len(particles)): |
|
... |
... |
while True: |
226 |
227 |
# Sample the new particle with some noise and increment the sum for the next particle |
# Sample the new particle with some noise and increment the sum for the next particle |
227 |
228 |
x, y = add_noise(0.02, *p.xy) |
x, y = add_noise(0.02, *p.xy) |
228 |
229 |
|
|
229 |
|
# Resample particle with increasing noise to avoid sampling points inside a wall or outside world |
|
230 |
|
c = 2 |
|
231 |
|
while not world.is_free(x, y): |
|
232 |
|
x, y = add_noise(c*0.02, *p.xy) |
|
233 |
|
c += 1 |
|
|
230 |
|
# Decide whether particle good or bad |
|
231 |
|
if world.is_free(x, y): |
|
232 |
|
good_particles.append(Particle(x, y, p.h, p.w, True)) |
|
233 |
|
else: |
|
234 |
|
bad_particles.append(p) |
234 |
235 |
|
|
235 |
|
new_particles.append(Particle(x, y, p.h, p.w, True)) |
|
236 |
236 |
new_part_weitgh_d += dp |
new_part_weitgh_d += dp |
237 |
237 |
|
|
238 |
|
weight_sum = 0 |
|
239 |
|
current_particle_index = 0 |
|
|
238 |
|
if len(good_particles) == 0: |
|
239 |
|
# Resample all particles random |
|
240 |
|
particles = Particle.create_random(PARTICLE_COUNT, world) |
|
241 |
|
elif len(bad_particles) > 0: |
|
242 |
|
# Put all particles near center of mass |
|
243 |
|
for bad in bad_particles: |
|
244 |
|
x, y, schmeiszweg = compute_mean_point(good_particles) |
|
245 |
|
new_particle = Particle(x, y, bad.h) |
|
246 |
|
new_particle.w = w_gauss(new_particle.read_sensor(world), r_d) |
240 |
247 |
|
|
241 |
|
particles = new_particles |
|
|
248 |
|
i = 1; |
|
249 |
|
|
|
250 |
|
# Check whether particle in wall or not |
|
251 |
|
while not world.is_free(x, y): |
|
252 |
|
x, y = add_noise(i * 0.02, *new_particle.xy) |
|
253 |
|
i += 1 |
|
254 |
|
|
|
255 |
|
# Add new good particle |
|
256 |
|
good_particles.append(Particle(x, y, new_particle.h, new_particle.w, True)) |
|
257 |
|
|
|
258 |
|
particles = good_particles |
242 |
259 |
|
|
243 |
260 |
# ---------- Move things ---------- |
# ---------- Move things ---------- |
244 |
261 |
old_heading = nao.h |
old_heading = nao.h |