Exemplo n.º 1
0
    def create_moving_obstacle(self, waypoints):
        """Create a new MovingObstacle model.

        Args:
            waypoints: List of (lat, lon, alt) tuples

        Returns:
            Saved MovingObstacle
        """
        obstacle = MovingObstacle(speed_avg=40, sphere_radius=100)
        obstacle.save()

        for num, waypoint in enumerate(waypoints):
            (lat, lon, alt) = waypoint

            gps = GpsPosition(latitude=lat, longitude=lon)
            gps.save()

            pos = AerialPosition(gps_position=gps, altitude_msl=alt)
            pos.save()

            waypoint = Waypoint(order=num, position=pos)
            waypoint.save()

            obstacle.waypoints.add(waypoint)

        obstacle.save()
        return obstacle
Exemplo n.º 2
0
 def test_get_waypoint_travel_time(self):
     """Tests travel time calc."""
     test_spds = [1, 10, 100, 500]
     for (lon2, lat2, lon1, lat1, dist_km) in TESTDATA_COMPETITION_DIST:
         dist_ft = units.kilometers_to_feet(dist_km)
         for speed in test_spds:
             speed_fps = units.knots_to_feet_per_second(speed)
             time = dist_ft / speed_fps
             gpos1 = GpsPosition()
             gpos1.latitude = lat1
             gpos1.longitude = lon1
             gpos1.save()
             apos1 = AerialPosition()
             apos1.gps_position = gpos1
             apos1.altitude_msl = 0
             apos1.save()
             wpt1 = Waypoint()
             wpt1.position = apos1
             gpos2 = GpsPosition()
             gpos2.latitude = lat2
             gpos2.longitude = lon2
             gpos2.save()
             apos2 = AerialPosition()
             apos2.gps_position = gpos2
             apos2.altitude_msl = 0
             apos2.save()
             wpt2 = Waypoint()
             wpt2.position = apos2
             waypoints = [wpt1, wpt2]
             obstacle = MovingObstacle()
             obstacle.speed_avg = speed
             self.assertTrue(
                 self.eval_travel_time(
                     obstacle.get_waypoint_travel_time(waypoints, 0, 1),
                     time))
Exemplo n.º 3
0
 def test_get_waypoint_travel_time(self):
     """Tests travel time calc."""
     test_spds = [1, 10, 100, 500]
     for (lon2, lat2, lon1, lat1, dist_km) in TESTDATA_COMPETITION_DIST:
         dist_ft = units.kilometers_to_feet(dist_km)
         for speed in test_spds:
             speed_fps = units.knots_to_feet_per_second(speed)
             time = dist_ft / speed_fps
             gpos1 = GpsPosition()
             gpos1.latitude = lat1
             gpos1.longitude = lon1
             gpos1.save()
             apos1 = AerialPosition()
             apos1.gps_position = gpos1
             apos1.altitude_msl = 0
             apos1.save()
             wpt1 = Waypoint()
             wpt1.position = apos1
             gpos2 = GpsPosition()
             gpos2.latitude = lat2
             gpos2.longitude = lon2
             gpos2.save()
             apos2 = AerialPosition()
             apos2.gps_position = gpos2
             apos2.altitude_msl = 0
             apos2.save()
             wpt2 = Waypoint()
             wpt2.position = apos2
             waypoints = [wpt1, wpt2]
             obstacle = MovingObstacle()
             obstacle.speed_avg = speed
             self.assertTrue(self.eval_travel_time(
                 obstacle.get_waypoint_travel_time(waypoints, 0, 1), time))
Exemplo n.º 4
0
    def get(self, request):
        kml = Kml(name='LIVE Data')
        MovingObstacle.live_kml(kml, timedelta(seconds=5))
        UasTelemetry.live_kml(kml, timedelta(seconds=5))

        response = HttpResponse(kml.kml())
        response['Content-Type'] = 'application/vnd.google-earth.kml+xml'
        response['Content-Disposition'] = 'attachment; filename=update.kml'
        response['Content-Length'] = str(len(response.content))
        return response
Exemplo n.º 5
0
    def get(self, request):
        kml = Kml(name='LIVE Data')
        MovingObstacle.live_kml(kml, timedelta(seconds=5))
        UasTelemetry.live_kml(kml, timedelta(seconds=5))

        response = HttpResponse(kml.kml())
        response['Content-Type'] = 'application/vnd.google-earth.kml+xml'
        response['Content-Disposition'] = 'attachment; filename=update.kml'
        response['Content-Length'] = str(len(response.content))
        return response
Exemplo n.º 6
0
    def test_evaluate_collision_with_uas(self):
        """Tests the collision with UAS method."""
        # Get test data
        user = User.objects.create_user('testuser', '*****@*****.**',
                                        'testpass')
        user.save()
        testdata = TESTDATA_MOVOBST_EVALCOLLISION
        (obst_rad, obst_speed, obst_pos, log_details) = testdata
        # Create the obstacle
        obst = MovingObstacle()
        obst.speed_avg = obst_speed
        obst.sphere_radius = obst_rad
        obst.save()
        for pos_id in xrange(len(obst_pos)):
            (lat, lon, alt) = obst_pos[pos_id]
            gpos = GpsPosition()
            gpos.latitude = lat
            gpos.longitude = lon
            gpos.save()
            apos = AerialPosition()
            apos.gps_position = gpos
            apos.altitude_msl = alt
            apos.save()
            wpt = Waypoint()
            wpt.order = pos_id
            wpt.position = apos
            wpt.save()
            obst.waypoints.add(wpt)
        obst.save()
        # Create sets of logs
        epoch = timezone.now().replace(year=1970,
                                       month=1,
                                       day=1,
                                       hour=0,
                                       minute=0,
                                       second=0,
                                       microsecond=0)
        inside_logs = []
        outside_logs = []
        for (time_sec, inside_pos, outside_pos) in log_details:
            log_time = epoch + datetime.timedelta(seconds=time_sec)
            logs_pos = [(inside_pos, inside_logs), (outside_pos, outside_logs)]
            for (positions, log_list) in logs_pos:
                for (lat, lon, alt) in positions:
                    log = self.create_log(lat, lon, alt, user, log_time)
                    log_list.append(log)

        # Assert the obstacle correctly computes collisions
        log_collisions = [(True, inside_logs), (False, outside_logs)]
        for (inside, logs) in log_collisions:
            self.assertEqual(obst.evaluate_collision_with_uas(logs), inside)
            for log in logs:
                self.assertEqual(obst.evaluate_collision_with_uas([log]),
                                 inside)
Exemplo n.º 7
0
    def create_moving_obstacle(self, waypoints):
        """Create a new MovingObstacle model.

        Args:
            waypoints: List of (lat, lon, alt) tuples

        Returns:
            Saved MovingObstacle
        """
        obstacle = MovingObstacle(speed_avg=40, sphere_radius=100)
        obstacle.save()

        for num, waypoint in enumerate(waypoints):
            (lat, lon, alt) = waypoint

            gps = GpsPosition(latitude=lat, longitude=lon)
            gps.save()

            pos = AerialPosition(gps_position=gps, altitude_msl=alt)
            pos.save()

            waypoint = Waypoint(order=num, position=pos)
            waypoint.save()

            obstacle.waypoints.add(waypoint)

        obstacle.save()
        return obstacle
Exemplo n.º 8
0
 def test_contains_pos(self):
     """Tests the inside obstacle method."""
     # Form the test obstacle
     obst = MovingObstacle()
     obst.sphere_radius = TESTDATA_MOVOBST_CONTAINSPOS_OBJ[2]
     # Run test points against obstacle
     test_data = [(TESTDATA_MOVOBST_CONTAINSPOS_INSIDE, True),
                  (TESTDATA_MOVOBST_CONTAINSPOS_OUTSIDE, False)]
     for (cur_data, cur_contains) in test_data:
         for (lat, lon, alt) in cur_data:
             gpos = GpsPosition()
             gpos.latitude = lat
             gpos.longitude = lon
             gpos.save()
             apos = AerialPosition()
             apos.gps_position = gpos
             apos.altitude_msl = alt
             self.assertEqual(
                 obst.contains_pos(TESTDATA_MOVOBST_CONTAINSPOS_OBJ[0],
                                   TESTDATA_MOVOBST_CONTAINSPOS_OBJ[1],
                                   TESTDATA_MOVOBST_CONTAINSPOS_OBJ[3],
                                   apos), cur_contains)
Exemplo n.º 9
0
 def test_contains_pos(self):
     """Tests the inside obstacle method."""
     # Form the test obstacle
     obst = MovingObstacle()
     obst.sphere_radius = TESTDATA_MOVOBST_CONTAINSPOS_OBJ[2]
     # Run test points against obstacle
     test_data = [
         (TESTDATA_MOVOBST_CONTAINSPOS_INSIDE, True),
         (TESTDATA_MOVOBST_CONTAINSPOS_OUTSIDE, False)
     ]
     for (cur_data, cur_contains) in test_data:
         for (lat, lon, alt) in cur_data:
             gpos = GpsPosition()
             gpos.latitude = lat
             gpos.longitude = lon
             gpos.save()
             apos = AerialPosition()
             apos.gps_position = gpos
             apos.altitude_msl = alt
             self.assertEqual(
                 obst.contains_pos(TESTDATA_MOVOBST_CONTAINSPOS_OBJ[0],
                                   TESTDATA_MOVOBST_CONTAINSPOS_OBJ[1],
                                   TESTDATA_MOVOBST_CONTAINSPOS_OBJ[3],
                                   apos), cur_contains)
Exemplo n.º 10
0
 def test_unicode(self):
     """Tests the unicode method executes."""
     obst = MovingObstacle()
     obst.speed_avg = 10
     obst.sphere_radius = 100
     obst.save()
     for _ in range(3):
         pos = GpsPosition()
         pos.latitude = 10
         pos.longitude = 100
         pos.save()
         apos = AerialPosition()
         apos.altitude_msl = 1000
         apos.gps_position = pos
         apos.save()
         wpt = Waypoint()
         wpt.position = apos
         wpt.order = 10
         wpt.save()
         obst.waypoints.add(wpt)
     self.assertTrue(obst.__unicode__())
Exemplo n.º 11
0
 def test_unicode(self):
     """Tests the unicode method executes."""
     obst = MovingObstacle()
     obst.speed_avg = 10
     obst.sphere_radius = 100
     obst.save()
     for _ in range(3):
         pos = GpsPosition()
         pos.latitude = 10
         pos.longitude = 100
         pos.save()
         apos = AerialPosition()
         apos.altitude_msl = 1000
         apos.gps_position = pos
         apos.save()
         wpt = Waypoint()
         wpt.position = apos
         wpt.order = 10
         wpt.save()
         obst.waypoints.add(wpt)
     self.assertTrue(obst.__unicode__())
Exemplo n.º 12
0
    def setUp(self):
        """Create the obstacles for testing."""
        # Obstacle with no waypoints
        obst_no_wpt = MovingObstacle()
        obst_no_wpt.speed_avg = 1
        obst_no_wpt.sphere_radius = 1
        obst_no_wpt.save()
        self.obst_no_wpt = obst_no_wpt

        # Obstacle with single waypoint
        self.single_wpt_lat = 40
        self.single_wpt_lon = 76
        self.single_wpt_alt = 100
        obst_single_wpt = MovingObstacle()
        obst_single_wpt.speed_avg = 1
        obst_single_wpt.sphere_radius = 1
        obst_single_wpt.save()
        single_gpos = GpsPosition()
        single_gpos.latitude = self.single_wpt_lat
        single_gpos.longitude = self.single_wpt_lon
        single_gpos.save()
        single_apos = AerialPosition()
        single_apos.gps_position = single_gpos
        single_apos.altitude_msl = self.single_wpt_alt
        single_apos.save()
        single_wpt = Waypoint()
        single_wpt.position = single_apos
        single_wpt.order = 1
        single_wpt.save()
        obst_single_wpt.waypoints.add(single_wpt)
        self.obst_single_wpt = obst_single_wpt

        # Obstacles with predefined path
        self.obstacles = []
        for path in TESTDATA_MOVOBST_PATHS:
            cur_obst = MovingObstacle()
            cur_obst.speed_avg = 68
            cur_obst.sphere_radius = 10
            cur_obst.save()
            for pt_id in range(len(path)):
                (lat, lon, alt) = path[pt_id]
                cur_gpos = GpsPosition()
                cur_gpos.latitude = lat
                cur_gpos.longitude = lon
                cur_gpos.save()
                cur_apos = AerialPosition()
                cur_apos.gps_position = cur_gpos
                cur_apos.altitude_msl = alt
                cur_apos.save()
                cur_wpt = Waypoint()
                cur_wpt.position = cur_apos
                cur_wpt.order = pt_id
                cur_wpt.save()
                cur_obst.waypoints.add(cur_wpt)
            cur_obst.save()
            self.obstacles.append(cur_obst)
Exemplo n.º 13
0
    def test_get_waypoint_travel_time_invalid_inputs(self):
        """Tests proper invalid input handling."""
        obstacle = MovingObstacle()
        obstacle.speed_avg = 1

        self.assertIsNone(obstacle.get_waypoint_travel_time(None, 1, 1))
        self.assertIsNone(obstacle.get_waypoint_travel_time([], 1, 1))
        self.assertIsNone(obstacle.get_waypoint_travel_time([None], 1, 1))
        self.assertIsNone(
            obstacle.get_waypoint_travel_time([None, None], None, 1))
        self.assertIsNone(
            obstacle.get_waypoint_travel_time([None, None], 1, None))
        self.assertIsNone(
            obstacle.get_waypoint_travel_time([None, None], -1, 0))
        self.assertIsNone(
            obstacle.get_waypoint_travel_time([None, None], 0, -1))
        self.assertIsNone(obstacle.get_waypoint_travel_time([None, None], 2,
                                                            0))
        self.assertIsNone(obstacle.get_waypoint_travel_time([None, None], 0,
                                                            2))
        obstacle.speed_avg = 0
        self.assertIsNone(obstacle.get_waypoint_travel_time([None, None], 0,
                                                            1))
Exemplo n.º 14
0
    def test_evaluate_collision_with_uas(self):
        """Tests the collision with UAS method."""
        # Get test data
        user = User.objects.create_user('testuser', '*****@*****.**',
                                        'testpass')
        user.save()
        testdata = TESTDATA_MOVOBST_EVALCOLLISION
        (obst_rad, obst_speed, obst_pos, log_details) = testdata
        # Create the obstacle
        obst = MovingObstacle()
        obst.speed_avg = obst_speed
        obst.sphere_radius = obst_rad
        obst.save()
        for pos_id in xrange(len(obst_pos)):
            (lat, lon, alt) = obst_pos[pos_id]
            gpos = GpsPosition()
            gpos.latitude = lat
            gpos.longitude = lon
            gpos.save()
            apos = AerialPosition()
            apos.gps_position = gpos
            apos.altitude_msl = alt
            apos.save()
            wpt = Waypoint()
            wpt.order = pos_id
            wpt.position = apos
            wpt.save()
            obst.waypoints.add(wpt)
        obst.save()
        # Create sets of logs
        epoch = timezone.now().replace(year=1970,
                                       month=1,
                                       day=1,
                                       hour=0,
                                       minute=0,
                                       second=0,
                                       microsecond=0)
        inside_logs = []
        outside_logs = []
        for (time_sec, inside_pos, outside_pos) in log_details:
            log_time = epoch + datetime.timedelta(seconds=time_sec)
            logs_pos = [(inside_pos, inside_logs), (outside_pos, outside_logs)]
            for (positions, log_list) in logs_pos:
                for (lat, lon, alt) in positions:
                    gpos = GpsPosition()
                    gpos.latitude = lat
                    gpos.longitude = lon
                    gpos.save()
                    apos = AerialPosition()
                    apos.gps_position = gpos
                    apos.altitude_msl = alt
                    apos.save()
                    log = UasTelemetry()
                    log.user = user
                    log.uas_position = apos
                    log.uas_heading = 0
                    log.save()
                    log.timestamp = log_time
                    log.save()
                    log_list.append(log)

        # Assert the obstacle correctly computes collisions
        log_collisions = [(True, inside_logs), (False, outside_logs)]
        for (inside, logs) in log_collisions:
            self.assertEqual(obst.evaluate_collision_with_uas(logs), inside)
            for log in logs:
                self.assertEqual(
                    obst.evaluate_collision_with_uas([log]), inside)
Exemplo n.º 15
0
    def test_interpolated_collision(self):
        # Get test data
        user = User.objects.create_user('testuser', '*****@*****.**',
                                        'testpass')
        user.save()
        utm = distance.proj_utm(zone=18, north=True)
        (obst_rad, obst_speed, obst_pos, log_details) = TESTDATA_MOVOBST_INTERP
        # Create the obstacle
        obst = MovingObstacle()
        obst.speed_avg = obst_speed
        obst.sphere_radius = obst_rad
        obst.save()
        for pos_id in xrange(len(obst_pos)):
            (lat, lon, alt) = obst_pos[pos_id]
            gpos = GpsPosition()
            gpos.latitude = lat
            gpos.longitude = lon
            gpos.save()
            apos = AerialPosition()
            apos.gps_position = gpos
            apos.altitude_msl = alt
            apos.save()
            wpt = Waypoint()
            wpt.order = pos_id
            wpt.position = apos
            wpt.save()
            obst.waypoints.add(wpt)
        obst.save()

        for (inside, log_list) in log_details:
            logs = []
            for i in range(len(log_list)):
                lat, lon, alt = log_list[i]
                pos = GpsPosition()
                pos.latitude = lat
                pos.longitude = lon
                pos.save()
                apos = AerialPosition()
                apos.altitude_msl = alt
                apos.gps_position = pos
                apos.save()
                log = UasTelemetry()
                log.user = user
                log.uas_position = apos
                log.uas_heading = 0
                log.save()
                if i == 0:
                    log.timestamp = timezone.now().replace(year=1970,
                                                           month=1,
                                                           day=1,
                                                           hour=0,
                                                           minute=0,
                                                           second=0,
                                                           microsecond=0)
                if i > 0:
                    log.timestamp = (
                        logs[i - 1].timestamp + datetime.timedelta(seconds=1))
                logs.append(log)
            self.assertEqual(
                obst.determine_interpolated_collision(logs[0], logs[1], utm),
                inside)
Exemplo n.º 16
0
    def test_interpolated_collision(self):
        # Get test data
        user = User.objects.create_user('testuser', '*****@*****.**',
                                        'testpass')
        user.save()
        utm = distance.proj_utm(zone=18, north=True)
        (obst_rad, obst_speed, obst_pos, log_details) = TESTDATA_MOVOBST_INTERP
        # Create the obstacle
        obst = MovingObstacle()
        obst.speed_avg = obst_speed
        obst.sphere_radius = obst_rad
        obst.save()
        for pos_id in xrange(len(obst_pos)):
            (lat, lon, alt) = obst_pos[pos_id]
            gpos = GpsPosition()
            gpos.latitude = lat
            gpos.longitude = lon
            gpos.save()
            apos = AerialPosition()
            apos.gps_position = gpos
            apos.altitude_msl = alt
            apos.save()
            wpt = Waypoint()
            wpt.order = pos_id
            wpt.position = apos
            wpt.save()
            obst.waypoints.add(wpt)
        obst.save()

        for (inside, log_list) in log_details:
            logs = []
            for i in range(len(log_list)):
                lat, lon, alt = log_list[i]
                pos = GpsPosition()
                pos.latitude = lat
                pos.longitude = lon
                pos.save()
                apos = AerialPosition()
                apos.altitude_msl = alt
                apos.gps_position = pos
                apos.save()
                log = UasTelemetry()
                log.user = user
                log.uas_position = apos
                log.uas_heading = 0
                log.save()
                if i == 0:
                    log.timestamp = timezone.now().replace(year=1970,
                                                           month=1,
                                                           day=1,
                                                           hour=0,
                                                           minute=0,
                                                           second=0,
                                                           microsecond=0)
                if i > 0:
                    log.timestamp = (logs[i - 1].timestamp +
                                     datetime.timedelta(seconds=1))
                logs.append(log)
            self.assertEqual(
                obst.determine_interpolated_collision(logs[0], logs[1], utm),
                inside)
Exemplo n.º 17
0
    def test_get_waypoint_travel_time_invalid_inputs(self):
        """Tests proper invalid input handling."""
        obstacle = MovingObstacle()
        obstacle.speed_avg = 1

        self.assertIsNone(obstacle.get_waypoint_travel_time(None, 1, 1))
        self.assertIsNone(obstacle.get_waypoint_travel_time([], 1, 1))
        self.assertIsNone(obstacle.get_waypoint_travel_time([None], 1, 1))
        self.assertIsNone(obstacle.get_waypoint_travel_time(
            [None, None], None, 1))
        self.assertIsNone(obstacle.get_waypoint_travel_time(
            [None, None], 1, None))
        self.assertIsNone(obstacle.get_waypoint_travel_time(
            [None, None], -1, 0))
        self.assertIsNone(obstacle.get_waypoint_travel_time(
            [None, None], 0, -1))
        self.assertIsNone(obstacle.get_waypoint_travel_time(
            [None, None], 2, 0))
        self.assertIsNone(obstacle.get_waypoint_travel_time(
            [None, None], 0, 2))
        obstacle.speed_avg = 0
        self.assertIsNone(obstacle.get_waypoint_travel_time(
            [None, None], 0, 1))
Exemplo n.º 18
0
    def setUp(self):
        """Create the obstacles for testing."""
        # Obstacle with no waypoints
        obst_no_wpt = MovingObstacle()
        obst_no_wpt.speed_avg = 1
        obst_no_wpt.sphere_radius = 1
        obst_no_wpt.save()
        self.obst_no_wpt = obst_no_wpt

        # Obstacle with single waypoint
        self.single_wpt_lat = 40
        self.single_wpt_lon = 76
        self.single_wpt_alt = 100
        obst_single_wpt = MovingObstacle()
        obst_single_wpt.speed_avg = 1
        obst_single_wpt.sphere_radius = 1
        obst_single_wpt.save()
        single_gpos = GpsPosition()
        single_gpos.latitude = self.single_wpt_lat
        single_gpos.longitude = self.single_wpt_lon
        single_gpos.save()
        single_apos = AerialPosition()
        single_apos.gps_position = single_gpos
        single_apos.altitude_msl = self.single_wpt_alt
        single_apos.save()
        single_wpt = Waypoint()
        single_wpt.position = single_apos
        single_wpt.order = 1
        single_wpt.save()
        obst_single_wpt.waypoints.add(single_wpt)
        self.obst_single_wpt = obst_single_wpt

        # Obstacles with predefined path
        self.obstacles = []
        for path in TESTDATA_MOVOBST_PATHS:
            cur_obst = MovingObstacle()
            cur_obst.speed_avg = 68
            cur_obst.sphere_radius = 10
            cur_obst.save()
            for pt_id in range(len(path)):
                (lat, lon, alt) = path[pt_id]
                cur_gpos = GpsPosition()
                cur_gpos.latitude = lat
                cur_gpos.longitude = lon
                cur_gpos.save()
                cur_apos = AerialPosition()
                cur_apos.gps_position = cur_gpos
                cur_apos.altitude_msl = alt
                cur_apos.save()
                cur_wpt = Waypoint()
                cur_wpt.position = cur_apos
                cur_wpt.order = pt_id
                cur_wpt.save()
                cur_obst.waypoints.add(cur_wpt)
            cur_obst.save()
            self.obstacles.append(cur_obst)