Exemplo n.º 1
0
robot = Robot([10, 10, 0])
poles = []
num_poles = 5
for i in range(num_poles):
    x = r.uniform(0, 100)
    y = r.uniform(0, 100)
    poles += [Pole([x, y, 0])]
particles = []
num_particles = 100
for i in range(num_particles):
    x = r.uniform(0, 100)
    y = r.uniform(0, 100)
    theta = r.uniform(0, math.pi * 2)
    particles += [Particle([x, y, theta])]

plot(robot, particles, poles)

moves = []
for i in range(60):
    if i < 10:
        moves += [[5, 0]]
        continue
    if i < 20:
        moves += [[5, math.pi / 10]]
        continue
    if i < 30:
        moves += [[-3, -math.pi / 20]]
        continue
    if i < 35:
        moves += [[10, 0]]
        continue
robot = Robot([10, 10, 0])
poles = []
num_poles = 5
for i in range(num_poles):
    x = r.uniform(0, 100)
    y = r.uniform(0, 100)
    poles += [Pole([x, y, 0])]
particles = []
num_particles = 100
for i in range(num_particles):
    x = r.uniform(0, 100)
    y = r.uniform(0, 100)
    theta = r.uniform(0, math.pi * 2)
    particles += [Particle([x, y, theta])]

plot(robot, particles, poles)


moves = []
for i in range(60):
    if i < 10:
        moves += [[5, 0]]
        continue
    if i < 20:
        moves += [[5, math.pi / 10]]
        continue
    if i < 30:
        moves += [[-3, -math.pi / 20]]
        continue
    if i < 35:
        moves += [[10, 0]]
from filter2d import Robot, Particle, Pole, resample_particles
import random as r
import math

r.seed(939)
robot = Robot([50, 50, 0])
poles = []
num_poles = 5
for i in range(num_poles):
    x = r.uniform(0, 100)
    y = r.uniform(0, 100)
    poles += [Pole([x, y, 0])]
particles = []
num_particles = 100
for i in range(num_particles):
    x = r.uniform(0, 100)
    y = r.uniform(0, 100)
    theta = r.uniform(0, math.pi * 2)
    particles += [Particle([x, y, theta])]

plot(robot, particles, poles)

robot.measure(poles)
for i in range(20):
    for particle in particles:
        particle.measure(poles)
        particle.update_weight(robot.measurements)
    print_particle_error(robot, particles)
    particles = resample_particles(particles)
    plot(robot, particles, poles, j=i, autorun=True)
Exemplo n.º 4
0
from sim.plot2d import plot
from filter2d import Robot, Particle, Pole
import random as r
import math

robot = Robot([50, 50, 0])
poles = [
    Pole([90, 90, 0]),
    Pole([80, 50, 0]),
    Pole([50, 70, 0]),
    Pole([25, 50, 0])
]

print("Robot Measurements:")
robot.measure(poles)
for measurement in robot.measurements:
    print("Distance: " + str(round(measurement.distance, 1)) + " Angle: " +
          str(round(measurement.angle, 2)))

print()
print("Measurement Answers:")
print("Distance: 56.6 Angle: 0.79")
print("Distance: 30.0 Angle: 0.0")
print("Distance: 20.0 Angle: 1.57")
print("Distance: 25.0 Angle: 3.14")
plot(robot, poles=poles)
Exemplo n.º 5
0
import random as r
import math

robot = Robot([50, 50, 0])
poles = [Pole([25, 25, 0])]
# Probably comment for real assignment.
poles += [Pole([25, 50, 0])]
particles = []
particles += [Particle([50, 50, 0])]
particles += [Particle([50, 50, math.pi / 8])]
particles += [Particle([75, 75, 0])]
particles += [Particle([55, 55, -math.pi / 4])]
particles += [Particle([45, 35, 0])]

robot.measure(poles)
for particle in particles:
    particle.measure(poles)
    particle.update_weight(robot.measurements)
    print("Weight: " + str(round(particle.weight, 2)))
    for measure in particle.measurements:
        print("Measurements: " + str(round(measure.distance, 2)))

print()
print("Answers:")
print("Weight: 1.0")
print("Weight: 0.54")
print("Weight: 0.0")
print("Weight: 0.12")
print("Weight: 0.25")
plot(robot, particles, poles)