Example #1
0
 def test_AffichageRobot(self):
     random_ligne = random.randint(5, 20)
     random_colonne = random.randint(5, 20)
     t = Terrain.Terrain(random_ligne, random_colonne)
     random_x = random.randint(1, t.nbLignes - 1)
     random_y = random.randint(1, t.nbColonnes - 1)
     robot = Robot.Robot(0, 10, 10, 0)
     self.assertTrue(t.ajout_objet(robot, random_x, random_y))
     robot = Robot.Robot(0, 10, 10, 0)
     # robot n'est pas affiché car coordonnees hors du terrain
     self.assertTrue(not t.ajout_objet(robot, -10, -10))
     self.assertTrue(not t.ajout_objet(robot, random_ligne, random_colonne))
Example #2
0
 def test_min_path_up_down_right_optimal_implementation(self):
     expected_route = [
         'D', 'D', 'R', 'R', 'U', 'U', 'R', 'R', 'D', 'D', 'D', 'D'
     ]
     robot = Robot(get_5x5_map_up_down_right(), (0, 0), (4, 4))
     answer = robot.get_min_path()
     self.assertEqual(answer, expected_route)
Example #3
0
    def test_continu_to_discret(self):
        tc = TerrainContinu.Carre(20)
        t = Terrain.construireTerrain(
            tc, Robot.Robot(random.uniform(0.2, 4.), random.uniform(0.2, 4.)))

        xMax = None
        yMax = None
        xMin = None
        yMin = None
        for sommetSurface in tc.polygoneSurface._liste_sommet:
            x, y = sommetSurface

            if xMax is None or x > xMax:
                xMax = x
            if yMax is None or y > yMax:
                yMax = y

            if xMin is None or x < xMin:
                xMin = x
            if yMin is None or y < yMin:
                yMin = y

        # x 1.1 pour les problèmes d'affichage lié aux approximations
        terrain = Terrain.Terrain(
            abs(yMin - yMax) + t.echelle,
            abs(xMax - xMin) + t.echelle, t.echelle, xMin, yMin)
        self.assertTrue(terrain.nbColonnes == t.nbColonnes)
        self.assertTrue(terrain.nbLignes == t.nbLignes)
Example #4
0
    def test_rotation(self):
        for i in range(3):
            random_x = random.randint(0, 50)
            random_y = random.randint(0, 50)
            random_vitesse = random.uniform(-50, 50)
            # --> On donne a la strategie seulement des angles positifs ?
            random_angle = random.uniform(0., 20.)
            # random_angle = random.uniform(0., 180.)
            # random_angle = random.uniform(0., 360.)
            # random_angle = random.uniform(-180., 180.)
            r = Robot.Robot(random_x, random_y, random_vitesse, random_angle)
            degrePS = random.randint(1, 20)
            stratT = StrategieTourner.StrategieTourner(r, random_angle,
                                                       degrePS)

            stratT.start()
            self.assertTrue(stratT.angleApplique == 0.)
            self.assertTrue(stratT.robot._degreParSeconde == 0.)
            self.assertIsNone(stratT.lastUpdate)

            while not stratT.stop():
                stratT.step()
                # 10*0.1 : pour approximation
                self.assertTrue(
                    stratT.angleApplique <= stratT.angleTarget + 10 * 0.1)
                # print(stratT.angleApplique , stratT.angleTarget + 10*0.1)
                self.assertTrue(stratT.robot._degreParSeconde == degrePS)

            self.assertTrue(stratT.angleApplique >= stratT.angleTarget)

            stratT.stop()
            self.assertTrue(stratT.robot._degreParSeconde == 0.)
Example #5
0
    def show_path_optimal(self):

        start = (0, 0)
        end = (5, 5)
        robot = Robot(self.map, start, end, "Optimal")
        print(robot.maps)
        print("Optimal path from file {}".format(robot.get_min_path()))
Example #6
0
 def test_instruction_list_exception(self):
     """tests instruction list exceptions"""
     mars_map = MarsMap(7,8)
     robot = Robot(2,2)
     instruction_list = "RFRFRFRFRFRFRFRFRFRFRFRFRFRFRFRFRFRFRFRFRFRFRFRFRFRFRFRFRFRFRFRFRFRFRFRFRFRFRFRFRFRFRFRFRFRFRFRFRFRFRFRFRFRFRF"
     with self.assertRaises(InstructionListException) as context:
         mars_map.process_robot_actions(robot, instruction_list)    
Example #7
0
    def test_Carre(self):
        for i in range(3):
            random_x = random.randint(0, 50)
            random_y = random.randint(0, 50)
            random_vitesse = random.uniform(-50, 50)
            random_angle = random.uniform(-180., 180.)
            r = Robot.Robot(random_x, random_y, random_vitesse, random_angle)
            degrePS = random.randint(0, 20)
            normeCote = random.randint(1, 10)
            stratAvancer = StrategieAvancerDroit.StrategieAvancerDroit(
                r, 7., 15.)
            stratTourner = StrategieTourner.StrategieTourner(r, 0., degrePS)
            stratC = StrategiePolygone.StrategiePolygone(
                stratAvancer, stratTourner, normeCote)

            stratC.start()

            self.assertTrue(stratTourner.angleApplique == 0.)
            self.assertTrue(stratTourner.robot._degreParSeconde == 0.)
            self.assertIsNone(stratTourner.lastUpdate)

            self.assertTrue(stratAvancer.parcouruSimu == 0)
            self.assertTrue(stratAvancer.robot.vitesse == 0.)
            self.assertIsNone(stratAvancer.lastUpdate)

            while not stratC.stop():
                stratC.step()
                self.assertTrue(stratC.i_liste_strategies <= normeCote * 2)

            stratC.stop()
    def test_Avancer(self):
        for i in range(3):
            random_x = random.randint(0, 50)
            random_y = random.randint(0, 50)
            random_vitesse = random.uniform(0, 50)
            random_angle = random.uniform(-180., 180.)
            r = Robot.Robot(random_x, random_y, random_vitesse, random_angle)
            random_distance = random.uniform(0, 20)
            stratAD = StrategieAvancerDroit.StrategieAvancerDroit(
                r, random_distance, random_vitesse)

            stratAD.start()
            self.assertTrue(stratAD.parcouruSimu == 0)
            self.assertTrue(stratAD.robot.vitesse == 0.)
            self.assertIsNone(stratAD.lastUpdate)

            while not stratAD.stop():
                stratAD.step()
                self.assertTrue(
                    stratAD.parcouruSimu <= stratAD.distance + 10 * 0.1)
                self.assertTrue(stratAD.robot.vitesse == stratAD.vitesse)

            self.assertTrue(stratAD.parcouruSimu >= stratAD.distance)

            stratAD.stop()
            self.assertTrue(stratAD.robot.vitesse == 0)
Example #9
0
 def test_output_3(self):
     """tests program output """
     mars_map = MarsMap(5,3)
     instruction_list = "LLFFFLFLFL"
     robot = Robot(0,3)
     robot.set_orientation("W")
     output = mars_map.process_robot_actions(robot,instruction_list)
     self.assertEqual(output,"23S")
Example #10
0
 def test_output_2(self):
     """tests program output """
     mars_map = MarsMap(5,3)
     instruction_list = "FRRFLLFFRRFLL"
     robot = Robot(3,2)
     robot.set_orientation("N")
     output = mars_map.process_robot_actions(robot,instruction_list)
     self.assertEqual(output,"33NLOST")
Example #11
0
    def show_path_naive(self):

        start = (0, 0)
        end = (5, 5)
        robot = Robot(self.map, start, end, "Naive")
        print(robot.maps)
        print("Naive (right down) path from file {}".format(
            robot.get_min_path()))
Example #12
0
 def test_output_1(self):
     """tests program output """
     mars_map = MarsMap(5,3)
     instruction_list = "RFRFRFRF"
     robot = Robot(1,1)
     robot.set_orientation("E")
     output = mars_map.process_robot_actions(robot,instruction_list)
     self.assertEqual(output,"11E")
Example #13
0
def _generate_robots(cnt=6):
    robots = []
    # for i in range(cnt):
    #     if constants.RANDOM_SEED is not None:
    #         random.seed(constants.RANDOM_SEED * (i + 1))
    for i in range(12):
        if i % 2 == 0:
            robot = Robot(constants.x_start_left + i - i / 3,
                          constants.y_start_left, constants.theta_start,
                          Color.WHITE)
            robots.append(robot)
        else:
            robot = Robot(constants.x_start_left + i - i / 3,
                          constants.y_start_left, constants.theta_start,
                          Color.YELLOW)
            robots.append(robot)

    return robots
Example #14
0
def test_no_obs():
    robot = Robot(1, -2, utils.to_radians(-60))
    ball = Ball(0, 0, 0, 0)
    result = main.run_simulation(robot,
                                 ball, [],
                                 simulation_delay=1000,
                                 enable_detection=False,
                                 drawable_obs_avoidance=True)
    assert result
Example #15
0
def test_no_obs2():
    robot = Robot(constants.x_start, constants.y_start, constants.theta_start)
    ball = Ball(constants.WINDOW_CORNERS[2] - 1,
                constants.WINDOW_CORNERS[3] - 1, 0, 0)
    result = main.run_simulation(robot,
                                 ball, [],
                                 simulation_delay=1000,
                                 enable_detection=False)
    assert result
Example #16
0
    def show_path_up_righ_down_left(self):

        maps = Map(
            "1 20 1 1 1 1 1 1 20 1 20 20 20 1 1 20 20 20 1 20 20 20 20 1 1")
        start = (0, 0)
        end = (4, 4)
        robot = Robot(maps, start, end, "Optimal")
        print("Map with up down right left")
        print(robot.maps)
        print("Optimal path from file {}".format(robot.get_min_path()))
Example #17
0
 def setUp(self):
     # premier robot : r et ses attributs
     self.x = random.uniform(-50, 50)
     self.random_x = random.randint(0, 50)
     self.random_y = random.randint(0, 50)
     self.random_vitesse = random.uniform(-50, 50)
     self.random_angle = random.uniform(-180, 180)
     self.r = Robot.Robot(self.random_x, self.random_y, self.random_vitesse,
                          self.random_angle)
     # deuxieme robot : Robot et ses attributs
     self.vitesse = random.uniform(-10, 10)
     self.angle = random.uniform(-180, 180)
     self.pos_x_init = random.uniform(-50, 50)
     self.pos_y_init = random.uniform(-50, 50)
     self.temps = random.randint(1, 100)
     self.Robot = Robot.Robot(self.pos_x_init, self.pos_y_init,
                              self.vitesse, self.angle)
     # troisieme robot : rimmob
     self.rimmob = Robot.Robot(self.pos_x_init, self.pos_y_init, 0.,
                               self.angle)
Example #18
0
def run():
    tc = TerrainContinu.Carre(20)
    robot = Robot.Robot(-3, -3, 0., 0.)
    stratmax = StrategieAvancerDroitMax.StrategieAvancerDroitMax(robot, 5., tc)
    fps = 60

    t1 = threading.Thread(target=affichage, args=(robot, tc, fps))
    t2 = threading.Thread(target=updateStrats, args=(stratmax, fps))
    t3 = threading.Thread(target=updateRobot, args=(robot, tc, fps))
    t1.start()
    t2.start()
    t3.start()
Example #19
0
def run():
    tc = TerrainContinu.Carre(20)
    robot = Robot.Robot(-3, -3, 0., 0.)
    stratIAS = StrategieIASimule.StrategieIASimule(robot, 4., tc)
    fps = 60

    t1 = threading.Thread(target=affichage, args=(robot, tc, fps))
    t2 = threading.Thread(target=updateStrats, args=(stratIAS, fps))
    t3 = threading.Thread(target=updateRobot, args=(robot, tc, fps))
    t1.start()
    t2.start()
    t3.start()
Example #20
0
    def test_rotation(self):
        r = Robot.Robot(0., 0., 1., 0.)
        oldAngle = r.angle
        oldVecteurD = r.vecteurDeplacement
        deltaT = random.uniform(0, 5)
        randomAngleRelative = r._degreParSeconde * deltaT
        r.rotation(deltaT)

        self.assertTrue(abs(oldAngle - r.angle) == randomAngleRelative)

        compare_vecteur = r.vecteurDeplacement + oldVecteurD.rotation(
            randomAngleRelative) * (-1)
        self.assertTrue(abs(compare_vecteur.norme()) < 0.00001)
Example #21
0
    def test_avance(self):
        # cas particuliers d'immobilité
        temps = random.randint(1, 100)
        pos_x_init = random.uniform(-50, 50)
        pos_y_init = random.uniform(-50, 50)
        vitesse = random.uniform(-10, 10)
        angle = random.uniform(-180, 180)
        # cas d'une vitesse nulle => immobile
        r = Robot.Robot(pos_x_init, pos_y_init, 0., angle)
        r.avance(temps)
        self.assertTrue(r.x == pos_x_init)
        self.assertTrue(r.y == pos_y_init)
        # cas d'un temps null => immobile
        r1 = Robot.Robot(pos_x_init, pos_y_init, vitesse, angle)
        r1.avance(0)
        self.assertTrue(r1.x == pos_x_init)
        self.assertTrue(r1.y == pos_y_init)

        # cas général, en prenant en compte l'incertitude de calcul --> float (arrondis au 1e-10 pres)
        for _ in range(1000):
            temps = random.randint(1, 100)
            pos_x_init = random.uniform(-50, 50)
            pos_y_init = random.uniform(-50, 50)
            vitesse = random.uniform(-10, 10)
            angle = random.uniform(-180, 180)
            r = Robot.Robot(pos_x_init, pos_y_init, vitesse, angle)
            r.avance(temps)
            pos_x_fin = pos_x_init + (
                (math.cos(math.radians(angle)) * vitesse) * temps)
            pos_y_fin = pos_y_init + (
                (math.sin(math.radians(angle)) * vitesse) * temps)
            # ordre de grandeur de l'incertitude = 0,0000000001 prés
            ordre_grandeur = 10**-10
            self.assertTrue(
                abs(r.x - pos_x_fin) <
                ordre_grandeur)  # test que valeurs identiques a 1e-10 prés
            self.assertTrue(
                abs(r.y - pos_y_fin) <
                ordre_grandeur)  # test que valeurs identiques a 1e-10 prés
Example #22
0
def test_vshyvost():
    for seed in seeds:
        print(seed)
        constants.RANDOM_SEED = seed
        ball = Ball.create_randomized()
        obstacles = main._generate_obstacles(cnt=constants.OBSTACLES_COUNT)
        robot = Robot(constants.x_start, constants.y_start,
                      constants.theta_start)
        result = main.run_simulation(robot,
                                     ball,
                                     obstacles,
                                     enable_detection=True)

        assert result
Example #23
0
    def test_contruct_Robot(self):
        random_x = random.randint(0, 50)
        random_y = random.randint(0, 50)
        random_vitesse = random.uniform(-50, 50)
        random_angle = random.uniform(-180., 180.)
        r = Robot.Robot(random_x, random_y, random_vitesse, random_angle)

        self.assertTrue(r.x == random_x)
        self.assertTrue(r.y == random_y)
        self.assertTrue(r.vitesse == random_vitesse)
        self.assertTrue(abs(r.angle - random_angle) < 0.0001)
        self.assertTrue(r._degreParSeconde == 0.)
        self.assertTrue(r._lastUpdate == None)
        self.assertTrue(r.lastCollision == False)
Example #24
0
def run(cote):
    tc = TerrainContinu.Carre(20)
    robot = Robot.Robot(-3, -3, 0., 0.)
    startAvancer = StrategieAvancerDroit.StrategieAvancerDroit(robot, 7., 15.)
    startTourner = StrategieTourner.StrategieTourner(robot, 0., 0.)
    stratPolygone = StrategiePolygone.StrategiePolygone(
        startAvancer, startTourner, int(cote))
    fps = 60

    t1 = threading.Thread(target=affichage, args=(robot, tc, fps))
    t2 = threading.Thread(target=updateStrats, args=(stratPolygone, fps))
    t3 = threading.Thread(target=updateRobot, args=(robot, tc, fps))
    t1.start()
    t2.start()
    t3.start()
Example #25
0
    def test_contruct_StratT(self):
        # pour creation robot
        random_x = random.randint(0, 50)
        random_y = random.randint(0, 50)
        random_vitesse = random.uniform(-50, 50)
        random_angle = random.uniform(-180., 180.)
        r = Robot.Robot(random_x, random_y, random_vitesse, random_angle)
        degrePS = random.randint(0, 20)
        stratT = StrategieTourner.StrategieTourner(r, random_angle, degrePS)

        self.assertTrue(stratT.robot == r)
        self.assertTrue(stratT.angleTarget == random_angle)
        self.assertTrue(stratT.degreParSeconde == degrePS)
        self.assertTrue(stratT.angleApplique == 0.)
        self.assertIsNone(stratT.lastUpdate)
    def test_contruct_StratAD(self):
        # pour creation robot
        random_x = random.randint(0, 50)
        random_y = random.randint(0, 50)
        random_vitesse = random.uniform(-50, 50)
        random_angle = random.uniform(-180., 180.)
        r = Robot.Robot(random_x, random_y, random_vitesse, random_angle)
        random_distance = random.uniform(-20, 20)
        stratAD = StrategieAvancerDroit.StrategieAvancerDroit(
            r, random_distance, random_vitesse)

        self.assertTrue(stratAD.robot == r)
        self.assertTrue(stratAD.distance == random_distance)
        self.assertTrue(stratAD.vitesse == random_vitesse)
        self.assertIsNone(stratAD.lastUpdate)
Example #27
0
    def test_contruct_StratCarre(self):
        # pour creation robot
        random_x = random.randint(0, 50)
        random_y = random.randint(0, 50)
        random_vitesse = random.uniform(-50, 50)
        random_angle = random.uniform(-180., 180.)
        r = Robot.Robot(random_x, random_y, random_vitesse, random_angle)
        degrePS = random.randint(0, 20)
        normeCote = random.randint(1, 10)
        stratAvancer = StrategieAvancerDroit.StrategieAvancerDroit(
            r, random_vitesse, normeCote)
        stratTourner = StrategieTourner.StrategieTourner(r, 0., degrePS)
        _ = StrategiePolygone.StrategiePolygone(stratAvancer, stratTourner, 4)

        self.assertTrue(stratTourner.angleTarget == 90.)
Example #28
0
    def test_setter_vitesse(self):
        random_x = random.randint(0, 50)
        random_y = random.randint(0, 50)
        random_vitesse = random.uniform(-50, 50)
        random_angle = random.uniform(0, 360)
        r = Robot.Robot(random_x, random_y, random_vitesse, random_angle)

        for _ in range(1000):
            x = random.uniform(-50, 50)
            r.vitesse = x
            self.assertTrue(
                r.vecteurDeplacement.x == math.cos(math.radians(r.angle)) *
                r.vitesse)
            self.assertTrue(
                r.vecteurDeplacement.y == math.sin(math.radians(r.angle)) *
                r.vitesse)
Example #29
0
    def testRotation(self):
        rr = Robot.Robot(0., 0., 1., 0.)
        oldAngle = rr.angle
        oldVecteurD = rr.vecteurDeplacement
        randomAngleRelative = random.uniform(-180, 180)
        rr.rotation(randomAngleRelative)

        oldAngle += randomAngleRelative
        oldAngle %= 360

        if oldAngle > 180.:
            oldAngle -= 360

        compare_vecteur = rr.vecteurDeplacement + oldVecteurD.rotation(
            randomAngleRelative) * (-1)
        self.assertLess(abs(compare_vecteur.norme()), 2.)
Example #30
0
    def deploy(self, table_params=[{}], robot_names=[]):
        if table_params and robot_names:
            for t in table_params:
                if set(Table.attributes) <= set(t):
                    self.tables[t['name']] = Table(t['name'], t['dx'], t['dy'],
                                                   t['rule'])
                else:
                    print('Table parameters "%s" not valid!' % t)

            for name in robot_names:
                self.robots[str(name)] = Robot(str(name))

            return True

        else:
            print("No valid data for creating tables and robots!")
            return False