示例#1
0
    def test_diametre(self):
        """
            Initialise une trajectoire circulaire, et calcule le diamètre de celle-ci
        """
        print("Testing diametre trajectory...")

        app = AppAreneThread(self.arene)
        sim = Simulation(strategies=[self.strat], acceleration_factor=5)

        min_x, min_y = sim.strategie.robot.centre.x, sim.strategie.robot.centre.y
        max_x, max_y = sim.strategie.robot.centre.x, sim.strategie.robot.centre.y

        sim.start()
        while not sim.stop:
            sleep(PAS_TEMPS/5)
            if sim.strategie.robot.centre.x < min_x:
                min_x = sim.strategie.robot.centre.x
            if sim.strategie.robot.centre.x > max_x:
                max_x = sim.strategie.robot.centre.x
            if sim.strategie.robot.centre.y < min_y:
                min_y = sim.strategie.robot.centre.y
            if sim.strategie.robot.centre.y > max_y:
                max_y = sim.strategie.robot.centre.y
            pass

        self.assertLess((max_y-min_y)-self.diametre_cercle, 0.0001)
        print("Done")
示例#2
0
    def test_sim(self):
        print("Initialising rotation of ", self.angle*180/pi, "degres")
        app = AppAreneThread(self.arene)
        s = Simulation(strategies=[self.strat])
        v = self.strat.robot.direction.clone()
        s.start()
        app.start()
        self.strat.robot.set_wheels_rotation(1, 40)
        self.strat.robot.set_wheels_rotation(2, 60)

        sens = self.strat.sens
        precision = max(self.strat.robot.get_wheels_rotations(1), self.strat.robot.get_wheels_rotations(2)) * (
                    pi / 180) * PAS_TEMPS * (max(self.strat.robot.rd.diametre,
                                                self.strat.robot.rg.diametre) / self.strat.robot.dist_wheels)
        while not s.stop:
            pass
        app.stop()
        if sens > 0:
            angle = abs((2 * pi) - v.diff_angle(self.strat.robot.direction, 1))
        else:
            angle = abs(v.diff_angle(self.strat.robot.direction, 1))

        print("Error: ", abs(abs(self.angle) - angle)*(180/pi), " degres")
        print("Maximal error expected: ", precision*180/pi, "degres")
        self.assertLess(abs(abs(self.angle) - angle), precision)
示例#3
0
    def test_vis(self):
        td = Thread(target=self.strat.start_3D)
        sim = Simulation(strategies=[self.strat])

        td.start()
        sim.start()

        sleep(15)

        self.strat.stop_3D()
示例#4
0
    def test_visualisation_2D(self):
        """
            Visualise le déplacement circulaire en 2D
        """
        print("Testing 2D...")

        app = AppAreneThread(self.arene)
        sim = Simulation(strategies=[self.strat], tic=2, tic_display=[self.strat.robot.tete.sensors["acc"]], final_actions=[app.stop])

        sim.start()
        app.start()
示例#5
0
 def test_target_circle_trajectectory(self):
     self.strat = DroitVersBaliseVision(RobotMotorise(forme=Pave(1,1,1,self.p0.clone()), direction=self.v2.clone()), AreneFermee(10,10,10))
     self.strat2 = DeplacementCercle(robot=self.target,vitesse=30, diametre=3, angle_max=360)
     td = Thread(target=self.strat.start_3D)
     sim = Simulation(strategies=[self.strat2, self.strat], tmax=15, tic=1,tic_display=[self.strat], final_actions=[self.strat.stop_3D])
     td.start()
     while not self.strat.robot.tete.sensors["cam"].is_set:
         pass
     sim.start()
     while not sim.stop:
         pass
     self.assertNotEqual(self.strat.last_detected, None)
示例#6
0
    def test_target_straith_trajectory(self):
        self.strat2 = DeplacementDroit(robot=self.target,vitesse= 30, distance_max=2)
        td = Thread(target=self.strat.start_3D)
        sim = Simulation(strategies=[self.strat2, self.strat], tmax=15, tic=3,
                         tic_display=[self.strat],
                         final_actions=[self.strat.stop_3D])

        td.start()
        while not self.strat.robot.tete.sensors["cam"].is_set:
            pass
        sim.start()
        while not sim.stop:
            pass
示例#7
0
    def test_vis(self):
        sim = Simulation(strategies=[self.strat],
                         tmax=10,
                         final_actions=[self.strat.stop_3D],
                         tic=2,
                         tic_display=[self.strat])

        thd = Thread(target=self.strat.start_3D)
        thd.start()
        while not self.strat.robot.tete.sensors["cam"].is_set:
            pass

        sim.start()
示例#8
0
    def test_sim_2D(self):
        """
            Teste la distance parcourue lors d'un déplacement droit
        """
        p = self.strat.robot.centre.clone()
        sim = Simulation(strategies=[self.strat],
                         tic=2,
                         tic_display=[self.strat.robot.tete.sensors["acc"]])
        app = AppAreneThread(self.arene)
        sim.start()
        app.start()
        dps_wheels = self.strat.robot.get_wheels_rotations(3)

        while not sim.stop:
            pass
        dist = (self.strat.robot.centre - p).to_vect().get_mag()
        # On s'assure qu'on a la précision souhaitée
        self.assertLess(
            abs(dist - self.distance),
            abs(dps_wheels[0]) * (pi / 180) * PAS_TEMPS *
            self.strat.robot.rd.diametre / 2)
示例#9
0
    def test_detection_2D(self):
        print("Testing direct detection with infrared ray...")
        td = Thread(target=self.strat.robot.tete.sensors["cam"].run)

        app = AppAreneThread(self.arene)
        sim = Simulation(strategies=[self.strat],
                         final_actions=[app.stop],
                         tic=2,
                         tic_display=[
                             (self.strat.robot.tete.sensors["ir"].arena_v,
                              "-v")
                         ])

        self.strat.init_movement(3, 60)

        sim.start()
        #self.strat.start()
        app.start()

        while not sim.stop:
            pass
        #self.strat.robot.tete.sensors["cam"].stop()

        # On s'assure que le pavé est bien entré dans le champ d'alerte
        dist = (self.p.centre - self.strat.robot.centre
                ).to_vect().get_mag() - self.p.length / 2
        self.assertLess(dist, self.strat.proximite_max,
                        "Object detected too close")

        # On s'assure qu'on a détecté la limite avec une assez bonne précision
        diff = abs(self.strat.last_detected - dist)
        # err_max n'est valide que si le pavé est droit par rapport à la direction du robot
        err_max = max(
            self.strat.robot.get_wheels_rotations(1) * (pi / 180) *
            self.strat.robot.rd.diametre * PAS_TEMPS, PAS_IR)

        self.assertLess(diff, err_max, "Maximal detection error exceeded")
        print("Done")
示例#10
0
 def test_simulation(self):
     sim = Simulation(strategies=[self.strat], acceleration_factor=5)
示例#11
0
    def __init__(self, arene):
        Thread.__init__(self)
        self.arene = arene
        self.window = None

    def run(self):
        self.window = AppArene(self.arene)
        self.window.mainloop()

    def stop(self):
        self.window.quit()


if __name__ == '__main__':
    from gl_lib.sim.robot.strategy.deplacement import DeplacementDroitAmeliore
    from gl_lib.sim.robot import RobotMotorise
    from gl_lib.sim import Simulation
    from gl_lib.sim.geometry import Vecteur
    a = Arene()
    strat = DeplacementDroitAmeliore(
        robot=RobotMotorise(direction=Vecteur(1, 1, 0).norm()),
        distance_max=1,
        arene=a)
    a.add(strat.robot)
    sim = Simulation(strategies=[strat])

    app = AppAreneThread(strat.arene)

    app.start()
    sim.start()
示例#12
0
文件: Model.py 项目: IlyesBB/gl_robot
                p.vertices[l_ln[l][3]].y,
                p.vertices[l_ln[l][3]].z,
            )
            lvertices.append(vertices)
        return lvertices


if __name__ == '__main__':
    from gl_lib.sim import Simulation
    from gl_lib.sim.robot.strategy.deplacement.balise import DroitVersBaliseVision
    from gl_lib.sim.robot.sensor.camera import Balise
    import os
    from math import pi

    a = AreneFermee(15, 15, 15)
    p1 = Pave(1, 1, 1)
    w, l, h = a.width, a.length, a.height
    p_w2, p_l2, p_h2 = p1.width / 2, p1.length / 2, p1.height / 2

    v = Vecteur(1, 1, 0).norm() * -1
    r = RobotTarget(direction=v.clone(), balise=Balise())
    r2 = RobotTarget(pave=Pave(1, 1, 1, (v * 5).to_point()),
                     direction=v.clone())
    r.set_wheels_rotation(3, 0)
    r2.set_wheels_rotation(0, 0)
    print(os.getcwd())
    #a.add(r2)
    s = Simulation(DroitVersBaliseVision(r, a))

    s.start()
示例#13
0
            return json.load(f, object_hook=DeplacementCercle.hook)


if __name__ == '__main__':
    from gl_lib.sim import Simulation
    from gl_lib.sim.display.d2.gui import AppAreneThread
    from gl_lib.sim.robot import *
    from gl_lib.sim.robot.sensor import Accelerometre
    from gl_lib.sim.geometry import *

    a = AreneRobot()
    r = RobotMotorise(
        forme=Pave(centre=Point(3.7, 6.7, 0), width=1, height=1, length=1))
    r.tete.sensors["cam"].arene = AreneFermee(3, 3, 3)
    td = Thread(target=r.tete.sensors["cam"].run)
    sim = Simulation(
        strategies=[DeplacementCercle(robot=r, angle_max=360, diametre=1)])
    a.add(r)
    app = AppAreneThread(a)
    app.start()
    min_x, min_y = sim.strategie.robot.centre.x, sim.strategie.robot.centre.y
    max_x, max_y = sim.strategie.robot.centre.x, sim.strategie.robot.centre.y
    dps_wheels = sim.strategie.robot.get_wheels_rotations(3)
    # td.start()
    sim.start()
    # print(sim.stop, sim.strategie.stop())
    while not sim.stop:
        sleep(1)
        print(sim.cpt, sim.strategie.robot.get_wheels_rotations(3))
        if sim.strategie.robot.centre.x < min_x:
            min_x = sim.strategie.robot.centre.x
        if sim.strategie.robot.centre.x > max_x:
示例#14
0
                DeplacementDroit.abort(self)
                Tourner.init_movement(self, 90)
        elif self.turning:
            Tourner.update(self)
        else:
            DeplacementDroit.init_movement(self, self.cote)
            self.cpt_turn += 1

    def stop(self):
        if self.cpt_turn > 4:
            return True
        else:
            return False


if __name__ == '__main__':
    from gl_lib.sim import Simulation
    from gl_lib.sim.display.d2.gui import AppAreneThread
    from gl_lib.sim.robot import *
    from gl_lib.sim.robot.sensor import Accelerometre
    from gl_lib.sim.geometry import *

    a = AreneFermee(10, 10, 10)
    r = RobotMotorise(Pave(centre=Point(3, 6, 0), width=1, height=1, length=1))
    sim = Simulation(DeplacementCarre(r, 1), 5)
    a.add(r)
    app = AppAreneThread(a)

    sim.start()
    app.start()