Exemplo n.º 1
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()))
Exemplo n.º 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)
Exemplo n.º 3
0
def uc_setbot(request, theform = RobotInfoForm):
    robj = None

    try:
        robj = Robot.objects.get(owner = request.user)
    except ObjectDoesNotExist:
        # make sure exsited one robot
        robj = Robot(rob_alias = 'default', owner = request.user)
        robj.save()
    except:
        info = "%s || %s" % (sys.exc_info()[0], sys.exc_info()[1])
        print info


    if request.method == 'POST':
        try:
            print 'POST, get data'
            form = theform(request.POST, request.FILES,
                    instance = robj, initial={})
            if form.is_valid():
                form.save()

        except:
            info = "%s || %s" % (sys.exc_info()[0], sys.exc_info()[1])
            print info # FIXME - currently I just log the exception

    else:
        print 'a GET'
        form = theform(instance=robj, initial={})

    return render_to_response('uc_set_bot.html', {
            "form": form,
            "user_name": request.user.username,
            }, context_instance=RequestContext(request))
Exemplo n.º 4
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()))
Exemplo n.º 5
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")
Exemplo n.º 6
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")
Exemplo n.º 7
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")
Exemplo n.º 8
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()))
Exemplo n.º 9
0
 def get(self, robot_id):
     robot = Robot.query(Robot.robot_id == robot_id).get()
     if None is robot:
         self.response.set_status(404, "robot not found")
         return
     # CALLING ALL ROBOTS!
     all_robot_keys = Robot.query().order(Robot.created).fetch(keys_only=True)
     all_robots = ndb.get_multi(all_robot_keys) # all gets seed memcache
     context = {"tracked_robot": robot, "robots": all_robots}
     render_template(self.response, 'index.html', context)
Exemplo n.º 10
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))
Exemplo n.º 11
0
def create_robot(post_form, user):
    print 'TODO code, will add in the future'

#r_obj = Robot(rob_sex = post_form['robotsettings.gender'],
#           rob_alias = post_form['robotsettings.nickname'],
#           owner = user)
#   TODO - just stub code
    r_obj = Robot(rob_sex = 1,
                rob_alias = 'debug',
                owner = user)
    r_obj.save()

    return 0
Exemplo n.º 12
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()
Exemplo n.º 13
0
    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)
Exemplo n.º 14
0
def _draw_scene(robot: Robot, ball: Ball, obstacles: List[MovingObstacle],
                ball_predicted_positions, barriers_predicted_positions):

    screen = numpy.full((constants.WINDOW_HEIGHT, constants.WINDOW_WIDTH, 3),
                        Color.BLACK,
                        dtype=numpy.uint8)

    robot.draw(screen)
    for obstacle in obstacles:
        obstacle.draw(screen)
    ball.draw(screen)

    screen_picture = copy.deepcopy(screen)
    _draw_edges(screen, ball_predicted_positions, Color.YELLOW)
    _draw_edges(screen, barriers_predicted_positions, Color.GREEN)
    return cv2.cvtColor(screen, cv2.COLOR_BGR2RGB), screen_picture
Exemplo n.º 15
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.)
Exemplo n.º 16
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)    
Exemplo n.º 17
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)
Exemplo n.º 18
0
def robot_update(id):
    json = bottle.request.json

    robot = Robot.get(Robot.id == id)
    robot.name = json['name']
    robot.code = json['code']
    robot.save()
    return {'robot': model_json(robot)}
Exemplo n.º 19
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
Exemplo n.º 20
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
Exemplo n.º 21
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
Exemplo n.º 22
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)
Exemplo n.º 23
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()
Exemplo n.º 24
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()
Exemplo n.º 25
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)
Exemplo n.º 26
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
Exemplo n.º 27
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
Exemplo n.º 28
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)
Exemplo n.º 29
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()
Exemplo n.º 30
0
    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)
Exemplo n.º 31
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.)
Exemplo n.º 32
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)
Exemplo n.º 33
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.)
Exemplo n.º 34
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)
Exemplo n.º 35
0
def CreateRobot(name):
	robot=Robot()
	robot.name,robot.table,robot.dirs,robot.x_cord,robot.y_cord=(name,None,None,None,None)
	robot.save()
	return
Exemplo n.º 36
0
def robot_list():
    bottle.response.content_type = 'application/json'
    return json.dumps(map(model_json, Robot.select()))
Exemplo n.º 37
0
def robot_create():
    json = bottle.request.json

    new_robot = Robot.create(**json)
    return {'robot': model_json(new_robot)}
Exemplo n.º 38
0
def robot_delete(id):
    return {'rows': Robot.get(Robot.id == id).delete_instance()}
Exemplo n.º 39
0
 def get(self):
     # CALLING ALL ROBOTS!
     all_robot_keys = Robot.query().order(Robot.created).fetch(keys_only=True)
     all_robots = ndb.get_multi(all_robot_keys) # all gets seed memcache
     render_template(self.response, 'index.html', {"robots": all_robots})