Esempio n. 1
0
 def deplacer(self, vecteur: Vecteur):
     """
     deplace le robot et sa tete
     :param vecteur: Vecteur
     """
     Robot.deplacer(self, vecteur)
     self.tete.deplacer(vecteur)
Esempio n. 2
0
 def tournerAutour(self, point: Point, angle: float):
     """
     tourne le robot et la tete
     :param point: Point
     :param angle: float en rad
     :return:
     """
     Robot.tournerAutour(self, point, angle)
     self.tete.tournerAutour(point, angle)
Esempio n. 3
0
class TestRobot(unittest.TestCase):

    def setUp(self):
        self.r = Robot(Pave(50, 50, 0), Objet3D(), Objet3D(), Vecteur(0, -1, 0))

    def test_initialisation(self):
        self.assertIsInstance(self.r, Robot, msg=None)
        self.assertIsInstance(self.r.rd, Objet3D, msg=None)
        self.assertIsInstance(self.r.rg, Objet3D, msg=None)
        self.assertIsInstance(self.r.forme, Pave, msg=None)
        self.assertIsInstance(self.r.direction, Vecteur, msg=None)

    def test_avancer(self):
        direction = self.r.direction
        vitesse = 1.0
        self.r.avancer(1)
        self.assertEqual(self.r.direction, direction*vitesse)
Esempio n. 4
0
 def setUp(self):
     self.r = Robot()
     random.seed()
Esempio n. 5
0
class TestRobot(unittest.TestCase):
    def setUp(self):
        self.r = Robot()
        random.seed()

    def test_init(self):
        self.assertIsInstance(self.r, Robot, msg=None)
        self.assertIsInstance(self.r.rd, Objet3D, msg=None)
        self.assertIsInstance(self.r.rg, Objet3D, msg=None)
        self.assertIsInstance(self.r.forme, Pave, msg=None)
        self.assertIsInstance(self.r.direction, Vecteur, msg=None)

        self.assertEqual(
            self.r.rd.centre, self.r.centre +
            (self.r.direction.rotate(-pi / 4) * self.r.forme.width / 2))
        self.assertEqual(
            self.r.rg.centre, self.r.centre +
            (self.r.direction.rotate(pi / 4) * self.r.forme.width / 2))
        self.assertEqual(self.r.dist_wheels, self.r.forme.width)

    def test_clone(self):
        r = self.r.clone()

        self.assertEqual(r.forme, self.r.forme)
        self.assertEqual(r.centre, self.r.centre)
        self.assertEqual(r.direction, self.r.direction)
        self.assertEqual(r.rd, self.r.rd)
        self.assertEqual(r.rg, self.r.rg)
        self.assertEqual(r.dist_wheels - self.r.dist_wheels, 0.0)

    def test_eq(self):
        r = self.r.clone()
        self.assertEqual(r, self.r)

        r = self.r.clone()
        r.centre = None
        self.assertNotEqual(r, self.r)

        r = self.r.clone()
        r.direction = None
        self.assertNotEqual(r, self.r)

        r = self.r.clone()
        r.rg = None
        self.assertNotEqual(r, self.r)

        r = self.r.clone()
        r.rd = None
        self.assertNotEqual(r, self.r)

        r = self.r.clone()
        r.dist_wheels = None
        self.assertNotEqual(r, self.r)

    def test_move(self):
        v = Vecteur(
            random.choice([1, -1]) * random.randint(0, 5),
            random.choice([1, -1]) * random.randint(0, 5),
            random.choice([1, -1]) * random.randint(0, 5))

        f = self.r.forme.clone()
        c = self.r.centre.clone()
        rg = self.r.rg.clone()
        rd = self.r.rd.clone()

        self.r.move(v)
        rd.move(v)
        rg.move(v)
        f.move(v)
        c.move(v)

        self.assertEqual(self.r.forme, f)
        self.assertEqual(self.r.centre, c)
        self.assertEqual(self.r.rd, rd)
        self.assertEqual(self.r.rg, rg)

    def test_rotate_around(self):
        p = Point(
            random.choice([1, -1]) * random.randint(0, 5),
            random.choice([1, -1]) * random.randint(0, 5),
            random.choice([1, -1]) * random.randint(0, 5)) + self.r.centre
        teta = random.random() * 2 * pi * random.choice([1, -1])

        f = self.r.forme.clone()
        c = self.r.centre.clone()
        rg = self.r.rg.clone()
        rd = self.r.rd.clone()

        self.r.rotate_around(p, teta)
        rd.centre.rotate_around(p, teta)
        rg.centre.rotate_around(p, teta)
        f.centre.rotate_around(p, teta)
        c.rotate_around(p, teta)

        self.assertEqual(self.r.forme.centre, f.centre)
        self.assertEqual(self.r.centre, c)
        self.assertEqual(self.r.rd.centre, rd.centre)
        self.assertEqual(self.r.rg.centre, rg.centre)

    def test_rotate_all_around(self):
        p = Point(
            random.choice([1, -1]) * random.randint(0, 5),
            random.choice([1, -1]) * random.randint(0, 5),
            random.choice([1, -1]) * random.randint(0, 5)) + self.r.centre
        teta = random.random() * 2 * pi * random.choice([1, -1])

        f = self.r.forme.clone()
        c = self.r.centre.clone()
        rg = self.r.rg.clone()
        rd = self.r.rd.clone()
        v = self.r.direction.clone()

        print(v)

        self.r.rotate_all_around(p, teta)
        rd.rotate_around(p, teta)
        rg.rotate_around(p, teta)
        f.rotate_all_around(p, teta)
        c.rotate_around(p, teta)
        v.rotate(teta)

        self.assertEqual(self.r.direction, v)
        self.assertEqual(self.r.forme, f)
        self.assertEqual(self.r.centre, c)
        self.assertEqual(self.r.direction, v)
        self.assertEqual(self.r.rd, rd)
        self.assertEqual(self.r.rg, rg)
Esempio n. 6
0
from gl_lib.sim.robot import Robot
from math import *
from gl_lib.sim.robot import Tete

# Creation d'une arene et ajout de n objets
a = Arene()
a.height = 50
a.width = 50
poly = Polygone3D()
p = Pave(10, 10, 10)
# p.tournerAutour(Point(0,4,5) , pi/3)
# poly.sommets = [Point(14, 15, 14), Point(5, 99, 120)]
# a.add(poly)
a.add(p)

robot = Robot(Pave(0, 0, 0), direction=Vecteur(1, 1, 0))
robot.deplacer(Vecteur(-20, -20, 0))
tete = Tete(robot)

capt = CapteurIR(tete)
#a.sauvegarder("./geometrie/BanqueArenes/arene1.txt")

v = Vecteur(1, -1, 0)
alpha = v.getAngle2D()
print(tan(alpha), tan(3 * pi / 4))
dist, mat = capt.mesure(a)
print(dist)
for i in range(int(a.height + a.height / 2)):
    for j in range(int(a.width + a.width / 2)):
        print(mat[j][i], end=' ')
    print("\n")
Esempio n. 7
0
 def setUp(self):
     self.r = Robot(Pave(50, 50, 0), Objet3D(), Objet3D(), Vecteur(0, -1, 0))