X-Git-Url: http://git.droids-corp.org/?p=aversive.git;a=blobdiff_plain;f=projects%2Fmicrob2010%2Ftests%2Ftourel_beacon%2Fgraph.py;fp=projects%2Fmicrob2010%2Ftests%2Ftourel_beacon%2Fgraph.py;h=f1e175eb8ff5157f38fcf0b28d68400fefa246f1;hp=23193b7a4e57f7347d4b2d6df4ca04df153307c5;hb=9b20b69a87c9d442cf4610351dc40b28b7f36e9c;hpb=aeae9ffbe911b68824da692179a990e8e358a994 diff --git a/projects/microb2010/tests/tourel_beacon/graph.py b/projects/microb2010/tests/tourel_beacon/graph.py index 23193b7..f1e175e 100644 --- a/projects/microb2010/tests/tourel_beacon/graph.py +++ b/projects/microb2010/tests/tourel_beacon/graph.py @@ -13,7 +13,8 @@ import popen2, random Path = mpath.Path FLOAT = "([-+]?[0-9]*\.?[0-9]+)" INT = "([-+]?[0-9][0-9]*)" -RANDOM_ERROR = 0.3 # deg +RANDOM_ERROR_A = 0.5 # deg +RANDOM_ERROR_D = 0.5 # percent beacons = [ (0.0, 1050.0), (3000.0, 0.0), (3000.0, 2100.0) ] def build_poly(ptlist): @@ -40,50 +41,149 @@ def build_path(ptlist): def get_angle(ref, b): """get angle from robot point of view (ref) of beacon 'b'""" a = math.atan2(b[1]-ref[1], b[0]-ref[0]) - ea = (math.pi/180.) * RANDOM_ERROR * random.random() + ea = (math.pi/180.) * RANDOM_ERROR_A * random.random() ea = random.choice([ea, -ea]) return a + ea, ea - alpha = math.atan2(a[1]-ref[1], a[0]-ref[0]) - beta = math.atan2(b[1]-ref[1], b[0]-ref[0]) - gamma = beta-alpha - if gamma < 0: - gamma = gamma + 2*math.pi - return gamma + error, error +def get_distance(ref, b): + """get distance between robot (ref) and beacon 'b'""" + d = math.sqrt((b[1]-ref[1])**2 + (b[0]-ref[0])**2) + ed = RANDOM_ERROR_D * random.random() + ed = random.choice([ed, -ed]) + return d + (d * ed / 100.), ed def dist(p1, p2): return math.sqrt((p1[0]-p2[0])**2+(p1[1]-p2[1])**2) -def graph(filename, real_x, real_y): +# graph position from distance + angle +def graph_da(filename, real_x, real_y, real_a): + pcol = [] + print "real_pt = %s"%(str((real_x, real_y, real_a))) real_pt = (real_x, real_y) # display beacons patches = [] for b in beacons: patches += [ Circle((b[0], b[1]), 40, alpha=0.4) ] + pcol.append(PatchCollection(patches, facecolor="yellow", alpha = 1)) - patches += [ Circle((real_x, real_y), 20, alpha=0.4, facecolor="red") ] + patches = [ Circle((real_x, real_y), 20, alpha=0.4, facecolor="red") ] + pcol.append(PatchCollection(patches, facecolor="red", alpha = 1)) + + # process angles from robot position + a0,ea0 = get_angle((real_x, real_y), beacons[0]) + a1,ea1 = get_angle((real_x, real_y), beacons[1]) + a0 -= real_a + a1 -= real_a + text = "a0 = %2.2f (%+2.2f deg)\n"%(a0, ea0*(180./math.pi)) + text += "a1 = %2.2f (%+2.2f deg)\n"%(a1, ea1*(180./math.pi)) + d0,ed0 = get_distance((real_x, real_y), beacons[0]) + d1,ed1 = get_distance((real_x, real_y), beacons[1]) + text += "d0 = %2.2f (%+2.2f %%)\n"%(d0, ed0) + text += "d1 = %2.2f (%+2.2f %%)\n"%(d1, ed1) + + cmd = "./main ad2pos %f %f %f %f"%(a0, a1, d0, d1) + print cmd + o,i = popen2.popen2(cmd) + i.close() + s = o.read(1000000) + o.close() + + open(filename + ".txt", "w").write(s) + + if len(s) == 1000000: + gloupix() + + fig = plt.figure() + ax = fig.add_subplot(111) + title = "Erreur de position en mm, qd l'erreur " + title += "d'angle aleatoire est comprise\n" + title += "erreur -%1.1f et %1.1f deg "%(RANDOM_ERROR_A, RANDOM_ERROR_A) + title += "et de distance de +/- %2.2f %%"%(RANDOM_ERROR_D) + ax.set_title(title) + + # area + x,y = build_poly([(0,0), (3000,0), (3000,2100), (0,2100)]) + ax.plot(x, y, 'g-') + + result_pt = (-1, -1) + patches = [] + for l in s.split("\n"): + m = re.match("circle: x=%s y=%s r=%s"%(FLOAT, FLOAT, FLOAT), l) + if m: + x,y,r = (float(m.groups()[0]), float(m.groups()[1]), float(m.groups()[2])) + print x,y,r + patches += [ Circle((x, y), r, facecolor="none") ] + m = re.match("p%s: x=%s y=%s a=%s"%(INT, FLOAT, FLOAT, FLOAT), l) + if m: + n,x,y,a = (float(m.groups()[0]), float(m.groups()[1]), + float(m.groups()[2]), float(m.groups()[3])) + if (n == 0): + patches += [ Circle((x, y), 20, alpha=0.4, facecolor="yellow") ] + result_pt = (x, y) + text += l + "\n" + + pcol.append(PatchCollection(patches, facecolor="none", alpha = 0.6)) + pcol.append(PatchCollection(patches, facecolor="blue", alpha = 0.2)) + + patches = [ Circle(result_pt, 20, alpha=0.4, facecolor="green") ] + pcol.append(PatchCollection(patches, cmap=matplotlib.cm.jet, alpha = 1)) + + # text area, far from the point + l = [(800., 1800.), (800., 500.), (1500., 1800.), (1500., 500.), + (2200., 1800.), (2200., 500.)] + l.sort(cmp=lambda p1,p2: (dist(p1,real_pt) 2cm (pour un deplacement\n" 'a %2.2f m/s vers %d deg et une periode tourelle = %d ms)'%(speed, angle_deg, period)) -#do_random_test() -#do_graph_2d_simple_error() +do_random_test() +do_graph_2d_simple_error() do_graph_2d_move_error() +do_graph_2d_ad_error()