def particle_filter(motions,
                    measurements,
                    final_robot,
                    N=500):  # I know it's tempting, but don't change N!
    # --------
    #
    # Make particles
    #

    v = Euv.Viewer(
        size=(600, 600),
        view_port_center=(50, 50),
        view_port_width=300,
    )

    p = []
    for i in range(N):
        r = robot()
        r.set_noise(bearing_noise, steering_noise, distance_noise)
        p.append(r)

    # --------
    #
    # Update particles
    #

    for t in range(len(motions)):
        show_frame(v, p, final_robot[t])

        # motion update (prediction)
        p2 = []
        for i in range(N):
            p2.append(p[i].move(motions[t]))
        p = p2

        # measurement update
        w = []
        for i in range(N):
            w.append(p[i].measurement_prob(measurements[t]))

        # resampling
        p3 = []
        index = int(random.random() * N)
        beta = 0.0
        mw = max(w)
        for i in range(N):
            beta += random.random() * 2.0 * mw
            while beta > w[index]:
                beta -= w[index]
                index = (index + 1) % N
            p3.append(p[index])
        p = p3
        show_frame(v, p, final_robot[t])

    # Wait for GUI to finish
    v.wait()

    return get_position(p)
Example #2
0
rod.setPosition((0, 0.5, 0))

# Connect the rod with the world through a Hinge joint.
world_joint = ode.HingeJoint(world)
world_joint.attach(rod, ode.environment)
world_joint.setAnchor((0, 0, 0))
world_joint.setAxis((0, 0, 1))

# Connect rod with ball with a fixed joint
rod_ball_joint = ode.FixedJoint(world)
rod_ball_joint.attach(rod, ball)
rod_ball_joint.setFixed()

# Create the viewer window
viewer = Euv.Viewer(size=(600, 600),
                    view_port_center=(0, 0),
                    view_port_width=2.5,
                    flip_y=True)

# Do the simulation

total_time = 0.0
dt = 0.02
Kf = 0.5  # Friction force
while total_time < 30:

    # push the ball after half a second!
    if total_time >= 0.5 and total_time < 0.5 + dt:
        ball.addRelForce((-20, 0, 0))
    elif total_time >= 0.5 + dt and total_time < 0.5 * 2 * dt:
        ball.addRelForce((20, 0, 0))
#!/usr/bin/python

import Euv.Frame as Frame
import Euv.EuvGtk as Euv
import Euv.Color as Color
import time

v = Euv.Viewer(size=(800, 600), view_port_center=(0, 0), view_port_width=800)

N = 1000
for i in range(N):
    f = Frame.Frame()
    x = 600. * (i - N / 2) / N
    f.add_circle(pos=(x, x), color="red", alpha=0.5, radius=15)
    f.add_circle(pos=(-x, x), color="blue", alpha=0.5, radius=15)
    f.add_text(pos=(250, 200),
               face="Sans",
               size=20,
               text="Frame %d" % i,
               color=Color.Color("darkgreen"))
    if v.user_break():
        break
    v.add_frame(f)
v.wait()
import Euv.Frame as Frame
import Euv.EuvGtk as Euv
import Euv.Color as Color
import Euv.Shapes as Shapes
import time
import math

N=200
v = Euv.Viewer(size=(800,600),
               view_port_center = (0,0),
               view_port_width = 800,
               max_num_frames=N,
               recording=True,
               flip_y = True)
for i in range(N):
    f = Frame.Frame()
    x = 400 * 1.0*(i-N/2)/N
    n = 40
    for j in range(n):
      f.add_circle(pos=(x+j*5,20*math.sin(2*math.pi*(i+j)/n)),
                   color=Color.Color("red"),
                   radius=3)
    f.add_lines(color=Color.Color("midnightblue"),
                lines=[[(x+5,105),(x+35,105)]])
    f.add_polygons(color=Color.Color("magenta3"),
                   polygons = [[(x,100),
                                (x+10,100),
                                (x+5,110)],
                               [(x+30,100),
                                (x+40,100),
                                (x+35,110)],