Example #1
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 #2
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()
Example #3
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)
Example #4
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 #5
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 #6
0
def run(cote):
    tc = TerrainContinu.Carre(20)
    #on ajoute deux obstacles d'origine (2,2) et (6,1) sur le terrain
    ObsC = Polygone.Carre((8, 6), 3)
    tc.ajoutPolygone(ObsC)
    ObsC = Polygone.Carre((9, 5), 3)
    tc.ajoutPolygone(ObsC)
    tc_s = Serializer.serialize(tc).encode()

    HOST = '127.0.0.1'  # Standard loopback interface address (localhost)
    PORT = 65432
    fps = 60

    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.bind((HOST, PORT))
    s.listen()
    conn, addr = s.accept()

    while True:
        data = conn.recv(1024)
        if not data:
            time.sleep(1. / fps)
            continue
        break

    conn.send(tc_s)

    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))
    t1 = threading.Thread(target=unity, args=(robot, s, conn, 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 #7
0
 def __init__(self, Robot, vitessemax, TerrainContinu):
     self.robot = Robot
     self.tc = TerrainContinu
     self.vitessemax = vitessemax
     self.stopstrat = False
     self.stratTourner = StrategieTourner.StrategieTourner(Robot, 20., 20.)