test.py
Go to the documentation of this file.
00001 #Particle filter imports
00002 import pfilter as pf
00003 import robot_motion as rm
00004 import object_motion as om
00005 import detection_appearance as da
00006 
00007 #Others
00008 import nodes as nd
00009 import transforms2d as t2d
00010 import numpy as np
00011 import math as mt
00012 import opencv.cv as cv
00013 import types
00014 import functools as ft
00015 
00016 velocity     = np.matrix([0.01, 0.0]).T
00017 pose         = t2d.Pose2D(0.0, 0.0, 0.0)
00018 
00019 #Setup
00020 mvar         = rm.motion_var()
00021 particles    = rm.make_set(mvar, pose, 100)
00022 
00023 #Run
00024 motion_model = rm.RobotMotion(mvar)
00025 app_model    = da.DetectionAppearance(cov=np.matrix([[(.03*.03), 0], [0, (.03*.03)]]))
00026 filter       = pf.PFilter(motion_model, app_model)
00027 display      = nd.RobotDisp("particle filter", size = 2, draw_center=True, meters_radius=10)
00028 
00029 max_weight   = app_model.weight(np.matrix([1.0, 0.0]).T, t2d.Pose2D(1.0, 0.0, 0.0))
00030 draw_func    = ft.partial(rm.draw_weighted_Pose2D, display, max_weight)
00031 cur_pos      = pose.pos.copy()
00032 cur_set      = particles
00033 
00034 for i in xrange(100):
00035     display.clear()
00036     cur_set = filter.step(t2d.Pose2D(velocity[0,0], velocity[1,0], 0), 
00037                           cur_pos, cur_set, draw_func)
00038     scur_pos = display.to_screen(cur_pos)
00039     display.draw(wait=10)
00040 
00041     cur_pos = cur_pos + velocity
00042     #print "cur_pos", cur_pos.T
00043 
00044 
00045 
00046 
00047 
00048 
00049 
00050 
00051 
00052 
00053 
00054 
00055 
00056 
00057 
00058 
00059 
00060 
00061 
00062 
00063 
00064 
00065 
00066 
00067 
00068 
00069 
00070 
00071 
00072 
00073 
00074 
00075 
00076 
00077 
00078 
00079 
00080 
00081 
00082 
00083 
00084 
00085 
00086 
00087 
00088 
00089 
00090 
00091 #cur_set = filter.step(control_input=t2d.Pose2D(velocity[0,0], velocity[1,0], 0), 
00092 #            measurement=cur_pos, particle_set=cur_set)
00093 #cur_pos = cur_pos + velocity
00094 #cur_set = filter.step(control_input=t2d.Pose2D(velocity[0,0], velocity[1,0], 0), 
00095 #            measurement=cur_pos, particle_set=cur_set)
00096 #cur_pos = cur_pos + velocity
00097 
00098 
00099 #cur_set      = pf.predict(motion_model, t2d.Pose2D(1.0, 0.0, 0.0), cur_set)
00100 #weighted_set = pf.likelihood(app_model, np.matrix([1.0, 0.0]).T, cur_set)
00101 #normalized   = pf.normalize_likelihood(weighted_set)
00102 #for i in xrange(100):
00103 #    cur_set = filter.step(control_input=t2d.Pose2D(velocity[0,0], velocity[1,0], 0), 
00104 #                measurement=cur_pos, particle_set=cur_set)
00105 #    cur_pos = cur_pos + velocity
00106 #
00107 #    display.clear()
00108 #    draw_particles(cur_set)
00109 #    scur_pos = display.to_screen(cur_pos)
00110 #    cv.cvCircle(display.buffer, cv.cvPoint((int) (scur_pos[0,0]), (int) (scur_pos[1,0])), 
00111 #                4, cv.cvScalar(100,0,0), cv.CV_FILLED)
00112 #    display.draw(wait=10)
00113 
00114 
00115 #filter.step()
00116 #print "particles"
00117 #for s in particles:
00118 #    print s
00119 


pfilter
Author(s): Travis Deyle, Hai Nguyen, Advisor: Prof. Charlie Kemp, Lab: Healthcare Robotics Lab at Georgia Tech
autogenerated on Wed Nov 27 2013 11:42:09