Example #1
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.name = 'Waypoint'
        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 = list()
        for path in TESTDATA_MOVOBST_PATHS:
            cur_obst = MovingObstacle()
            cur_obst.name = '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.name = 'Waypoint'
                cur_wpt.order = pt_id
                cur_wpt.save()
                cur_obst.waypoints.add(cur_wpt)
            cur_obst.save()
            self.obstacles.append(cur_obst)
Example #2
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.name = 'Waypoint'
        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 = list()
        for path in TESTDATA_MOVOBST_PATHS:
            cur_obst = MovingObstacle()
            cur_obst.name = '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.name = 'Waypoint'
                cur_wpt.order = pt_id
                cur_wpt.save()
                cur_obst.waypoints.add(cur_wpt)
            cur_obst.save()
            self.obstacles.append(cur_obst)
    def test_satisfied_waypoints(self):
        """Tests the evaluation of waypoints method."""
        data = TESTDATA_MISSIONCONFIG_EVALWAYPOINTS
        (waypoint_details, uas_log_details, exp_satisfied) = data

        # Create mission config
        gpos = GpsPosition()
        gpos.latitude = 10
        gpos.longitude = 10
        gpos.save()
        config = MissionConfig()
        config.home_pos = gpos
        config.emergent_last_known_pos = gpos
        config.off_axis_target_pos = gpos
        config.sric_pos = gpos
        config.air_drop_pos = gpos
        config.server_info = self.info
        config.save()

        # Create waypoints for config
        for wpt_id in xrange(len(waypoint_details)):
            (lat, lon, alt) = waypoint_details[wpt_id]
            pos = GpsPosition()
            pos.latitude = lat
            pos.longitude = lon
            pos.save()
            apos = AerialPosition()
            apos.altitude_msl = alt
            apos.gps_position = pos
            apos.save()
            wpt = Waypoint()
            wpt.position = apos
            wpt.order = wpt_id
            wpt.save()
            config.mission_waypoints.add(wpt)
        config.save()

        # Create UAS telemetry logs
        uas_logs = []
        user = User.objects.create_user('testuser', '*****@*****.**',
                                        'testpass')
        for (lat, lon, alt) in uas_log_details:
            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()
            uas_logs.append(log)

        # Assert correct satisfied waypoints
        wpts_satisfied = config.satisfied_waypoints(uas_logs)
        self.assertEqual(wpts_satisfied, exp_satisfied)
Example #4
0
 def setUp(self):
     """Creates test data."""
     # Form test set for contains position
     self.testdata_containspos = []
     for test_data in TESTDATA_FLYZONE_CONTAINSPOS:
         # Create the FlyZone
         zone = FlyZone()
         zone.altitude_msl_min = test_data['min_alt']
         zone.altitude_msl_max = test_data['max_alt']
         zone.save()
         for waypoint_id in range(len(test_data['waypoints'])):
             (lat, lon) = test_data['waypoints'][waypoint_id]
             gpos = GpsPosition()
             gpos.latitude = lat
             gpos.longitude = lon
             gpos.save()
             apos = AerialPosition()
             apos.gps_position = gpos
             apos.altitude_msl = 0
             apos.save()
             wpt = Waypoint()
             wpt.order = waypoint_id
             wpt.position = apos
             wpt.save()
             zone.boundary_pts.add(wpt)
         # Form test set
         test_pos = []
         for pos in test_data['inside_pos']:
             test_pos.append((pos, True))
         for pos in test_data['outside_pos']:
             test_pos.append((pos, False))
         # Store
         self.testdata_containspos.append((zone, test_pos))
Example #5
0
 def setUp(self):
     """Creates test data."""
     # Form test set for contains position
     self.testdata_containspos = []
     for test_data in TESTDATA_FLYZONE_CONTAINSPOS:
         # Create the FlyZone
         zone = FlyZone()
         zone.altitude_msl_min = test_data['min_alt']
         zone.altitude_msl_max = test_data['max_alt']
         zone.save()
         for waypoint_id in range(len(test_data['waypoints'])):
             (lat, lon) = test_data['waypoints'][waypoint_id]
             gpos = GpsPosition()
             gpos.latitude = lat
             gpos.longitude = lon
             gpos.save()
             apos = AerialPosition()
             apos.gps_position = gpos
             apos.altitude_msl = 0
             apos.save()
             wpt = Waypoint()
             wpt.order = waypoint_id
             wpt.position = apos
             wpt.save()
             zone.boundary_pts.add(wpt)
         # Form test set
         test_pos = []
         for pos in test_data['inside_pos']:
             test_pos.append((pos, True))
         for pos in test_data['outside_pos']:
             test_pos.append((pos, False))
         # Store
         self.testdata_containspos.append((zone, test_pos))
Example #6
0
 def test_unicode(self):
     """Tests the unicode method executes."""
     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()
     config = MissionConfig()
     config.home_pos = pos
     config.emergent_last_known_pos = pos
     config.off_axis_target_pos = pos
     config.sric_pos = pos
     config.air_drop_pos = pos
     config.server_info = self.info
     config.save()
     config.mission_waypoints.add(wpt)
     config.search_grid_points.add(wpt)
     config.save()
     self.assertTrue(config.__unicode__())
Example #7
0
    def test_satisfied_waypoints(self):
        """Tests the evaluation of waypoints method."""
        data = TESTDATA_MISSIONCONFIG_EVALWAYPOINTS
        (waypoint_details, uas_log_details, exp_satisfied) = data

        # Create mission config
        gpos = GpsPosition()
        gpos.latitude = 10
        gpos.longitude = 10
        gpos.save()
        config = MissionConfig()
        config.home_pos = gpos
        config.emergent_last_known_pos = gpos
        config.off_axis_target_pos = gpos
        config.sric_pos = gpos
        config.air_drop_pos = gpos
        config.server_info = self.info
        config.save()

        # Create waypoints for config
        for wpt_id in xrange(len(waypoint_details)):
            (lat, lon, alt) = waypoint_details[wpt_id]
            pos = GpsPosition()
            pos.latitude = lat
            pos.longitude = lon
            pos.save()
            apos = AerialPosition()
            apos.altitude_msl = alt
            apos.gps_position = pos
            apos.save()
            wpt = Waypoint()
            wpt.position = apos
            wpt.order = wpt_id
            wpt.save()
            config.mission_waypoints.add(wpt)
        config.save()

        # Create UAS telemetry logs
        uas_logs = []
        user = User.objects.create_user('testuser', '*****@*****.**',
                                        'testpass')
        for (lat, lon, alt) in uas_log_details:
            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()
            uas_logs.append(log)

        # Assert correct satisfied waypoints
        wpts_satisfied = config.satisfied_waypoints(uas_logs)
        self.assertEqual(wpts_satisfied, exp_satisfied)
 def test_unicode(self):
     """Tests the unicode method executes."""
     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()
     config = MissionConfig()
     config.home_pos = pos
     config.emergent_last_known_pos = pos
     config.off_axis_target_pos = pos
     config.sric_pos = pos
     config.air_drop_pos = pos
     config.server_info = self.info
     config.save()
     config.mission_waypoints.add(wpt)
     config.search_grid_points.add(wpt)
     config.save()
     self.assertTrue(config.__unicode__())
Example #9
0
 def setUp(self):
     """Sets up the client, obstacle URL, obstacles, and user."""
     # Setup user
     self.user = User.objects.create_user('testuser', '*****@*****.**',
                                          'testpass')
     self.user.save()
     # Setup the obstacles
     for path in TESTDATA_MOVOBST_PATHS:
         # Stationary obstacle
         (stat_lat, stat_lon, _) = path[0]
         stat_gps = GpsPosition()
         stat_gps.latitude = stat_lat
         stat_gps.longitude = stat_lon
         stat_gps.save()
         stat_obst = StationaryObstacle()
         stat_obst.gps_position = stat_gps
         stat_obst.cylinder_radius = 100
         stat_obst.cylinder_height = 200
         stat_obst.save()
         # Moving obstacle
         mov_obst = MovingObstacle()
         mov_obst.speed_avg = 40
         mov_obst.sphere_radius = 100
         mov_obst.save()
         for pt_id in range(len(path)):
             # Obstacle waypoints
             (wpt_lat, wpt_lon, wpt_alt) = path[pt_id]
             gpos = GpsPosition()
             gpos.latitude = wpt_lat
             gpos.longitude = wpt_lon
             gpos.save()
             apos = AerialPosition()
             apos.altitude_msl = wpt_alt
             apos.gps_position = gpos
             apos.save()
             wpt = Waypoint()
             wpt.name = 'test waypoint'
             wpt.order = pt_id
             wpt.position = apos
             wpt.save()
             mov_obst.waypoints.add(wpt)
         mov_obst.save()
     # Setup test objs
     self.client = Client()
     self.loginUrl = reverse('auvsi_suas:login')
     self.obstUrl = reverse('auvsi_suas:obstacles')
Example #10
0
 def setUp(self):
     """Sets up the client, obstacle URL, obstacles, and user."""
     # Setup user
     self.user = User.objects.create_user(
             'testuser', '*****@*****.**', 'testpass')
     self.user.save()
     # Setup the obstacles
     for path in TESTDATA_MOVOBST_PATHS:
         # Stationary obstacle
         (stat_lat, stat_lon, _) = path[0]
         stat_gps = GpsPosition()
         stat_gps.latitude = stat_lat
         stat_gps.longitude = stat_lon
         stat_gps.save()
         stat_obst = StationaryObstacle()
         stat_obst.gps_position = stat_gps
         stat_obst.cylinder_radius = 100
         stat_obst.cylinder_height = 200
         stat_obst.save()
         # Moving obstacle
         mov_obst = MovingObstacle()
         mov_obst.speed_avg = 40
         mov_obst.sphere_radius = 100
         mov_obst.save()
         for pt_id  in range(len(path)):
             # Obstacle waypoints
             (wpt_lat, wpt_lon, wpt_alt) = path[pt_id]
             gpos = GpsPosition()
             gpos.latitude = wpt_lat
             gpos.longitude = wpt_lon
             gpos.save()
             apos = AerialPosition()
             apos.altitude_msl = wpt_alt
             apos.gps_position = gpos
             apos.save()
             wpt = Waypoint()
             wpt.name = 'test waypoint'
             wpt.order = pt_id
             wpt.position = apos
             wpt.save()
             mov_obst.waypoints.add(wpt)
         mov_obst.save()
     # Setup test objs
     self.client = Client()
     self.loginUrl = reverse('auvsi_suas:login')
     self.obstUrl = reverse('auvsi_suas:obstacles')
Example #11
0
 def test_unicode(self):
     """Tests the unicode method executes."""
     zone = FlyZone()
     zone.altitude_msl_min = 1
     zone.altitude_msl_max = 2
     zone.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()
         zone.boundary_pts.add(wpt)
     self.assertTrue(zone.__unicode__())
Example #12
0
 def test_unicode(self):
     """Tests the unicode method executes."""
     zone = FlyZone()
     zone.altitude_msl_min = 1
     zone.altitude_msl_max = 2
     zone.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()
         zone.boundary_pts.add(wpt)
     self.assertTrue(zone.__unicode__())
Example #13
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__())
Example #14
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__())
Example #15
0
    def test_satisfied_waypoints(self):
        """Tests the evaluation of waypoints method."""
        # Create mission config
        gpos = GpsPosition()
        gpos.latitude = 10
        gpos.longitude = 10
        gpos.save()
        config = MissionConfig()
        config.home_pos = gpos
        config.emergent_last_known_pos = gpos
        config.off_axis_target_pos = gpos
        config.sric_pos = gpos
        config.air_drop_pos = gpos
        config.server_info = self.info
        config.save()

        # Create waypoints for config
        waypoints = [(38, -76, 100), (39, -77, 200), (40, -78, 0)]
        for i, waypoint in enumerate(waypoints):
            (lat, lon, alt) = waypoint
            pos = GpsPosition()
            pos.latitude = lat
            pos.longitude = lon
            pos.save()
            apos = AerialPosition()
            apos.altitude_msl = alt
            apos.gps_position = pos
            apos.save()
            wpt = Waypoint()
            wpt.position = apos
            wpt.order = i
            wpt.save()
            config.mission_waypoints.add(wpt)
        config.save()

        # Create UAS telemetry logs
        user = User.objects.create_user('testuser', '*****@*****.**',
                                        'testpass')

        # Only first is valid.
        entries = [(38, -76, 140), (40, -78, 600), (37, -75, 40)]
        expect = (1, 1)
        logs = self.create_uas_logs(user, entries)
        self.assertEqual(expect, config.satisfied_waypoints(logs))

        # First and last are valid, but missed second, so third doesn't count.
        entries = [(38, -76, 140), (40, -78, 600), (40, -78, 40)]
        expect = (1, 1)
        logs = self.create_uas_logs(user, entries)
        self.assertEqual(expect, config.satisfied_waypoints(logs))

        # Hit all.
        entries = [(38, -76, 140), (39, -77, 180), (40, -78, 40)]
        expect = (3, 3)
        logs = self.create_uas_logs(user, entries)
        self.assertEqual(expect, config.satisfied_waypoints(logs))

        # Hit all, but don't stay within waypoint track.
        entries = [(38, -76, 140), (39, -77, 180), (41, -78, 40),
                   (40, -78, 40)]
        expect = (3, 2)
        logs = self.create_uas_logs(user, entries)
        self.assertEqual(expect, config.satisfied_waypoints(logs))

        # Only hit the first waypoint on run one, hit all on run two.
        entries = [
            (38, -76, 140),
            (40, -78, 600),
            (37, -75, 40),
            # Run two:
            (38, -76, 140),
            (39, -77, 180),
            (40, -78, 40)
        ]
        expect = (3, 3)
        logs = self.create_uas_logs(user, entries)
        self.assertEqual(expect, config.satisfied_waypoints(logs))

        # Hit all on run one, only hit the first waypoint on run two.
        entries = [
            (38, -76, 140),
            (39, -77, 180),
            (40, -78, 40),
            # Run two:
            (38, -76, 140),
            (40, -78, 600),
            (37, -75, 40)
        ]
        expect = (3, 3)
        logs = self.create_uas_logs(user, entries)
        self.assertEqual(expect, config.satisfied_waypoints(logs))

        # Remain on the waypoint track only on the second run.
        entries = [
            (38, -76, 140),
            (39, -77, 180),
            (41, -78, 40),
            (40, -78, 40),
            # Run two:
            (38, -76, 140),
            (39, -77, 180),
            (40, -78, 40)
        ]
        expect = (3, 3)
        logs = self.create_uas_logs(user, entries)
        self.assertEqual(expect, config.satisfied_waypoints(logs))
Example #16
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)
Example #17
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)
    def test_satisfied_waypoints(self):
        """Tests the evaluation of waypoints method."""
        # Create mission config
        gpos = GpsPosition()
        gpos.latitude = 10
        gpos.longitude = 10
        gpos.save()
        config = MissionConfig()
        config.home_pos = gpos
        config.emergent_last_known_pos = gpos
        config.off_axis_target_pos = gpos
        config.sric_pos = gpos
        config.air_drop_pos = gpos
        config.server_info = self.info
        config.save()

        # Create waypoints for config
        waypoints = [(38, -76, 100), (39, -77, 200), (40, -78, 0)]
        for i, waypoint in enumerate(waypoints):
            (lat, lon, alt) = waypoint
            pos = GpsPosition()
            pos.latitude = lat
            pos.longitude = lon
            pos.save()
            apos = AerialPosition()
            apos.altitude_msl = alt
            apos.gps_position = pos
            apos.save()
            wpt = Waypoint()
            wpt.position = apos
            wpt.order = i
            wpt.save()
            config.mission_waypoints.add(wpt)
        config.save()

        # Create UAS telemetry logs
        user = User.objects.create_user('testuser', '*****@*****.**',
                                        'testpass')

        def assertSatisfiedWaypoints(expect, got):
            """Assert two satisfied_waypoints return values are equal."""
            self.assertEqual(expect[0], got[0])
            self.assertEqual(expect[1], got[1])
            for k in expect[2].keys():
                self.assertIn(k, got[2])
                self.assertAlmostEqual(expect[2][k], got[2][k], delta=0.1)
            for k in got[2].keys():
                self.assertIn(k, expect[2])

        # Only first is valid.
        entries = [(38, -76, 140), (40, -78, 600), (37, -75, 40)]
        expect = (1, 1, {0: 40, 1: 460785.17})
        logs = self.create_uas_logs(user, entries)
        assertSatisfiedWaypoints(expect, config.satisfied_waypoints(logs))

        # First and last are valid, but missed second, so third doesn't count.
        entries = [(38, -76, 140), (40, -78, 600), (40, -78, 40)]
        expect = (1, 1, {0: 40, 1: 460785.03})
        logs = self.create_uas_logs(user, entries)
        assertSatisfiedWaypoints(expect, config.satisfied_waypoints(logs))

        # Hit all.
        entries = [(38, -76, 140), (39, -77, 180), (40, -78, 40)]
        expect = (3, 3, {0: 40, 1: 20, 2: 40})
        logs = self.create_uas_logs(user, entries)
        assertSatisfiedWaypoints(expect, config.satisfied_waypoints(logs))

        # Hit all, but don't stay within waypoint track.
        entries = [(38, -76, 140), (39, -77, 180), (41, -78, 40),
                   (40, -78, 40)]
        expect = (3, 2, {0: 40, 1: 20, 2: 40})
        logs = self.create_uas_logs(user, entries)
        assertSatisfiedWaypoints(expect, config.satisfied_waypoints(logs))

        # Only hit the first waypoint on run one, hit all on run two.
        entries = [(38, -76, 140),
                   (40, -78, 600),
                   (37, -75, 40),
                   # Run two:
                   (38, -76, 140),
                   (39, -77, 180),
                   (40, -78, 40)]
        expect = (3, 3, {0: 40, 1: 20, 2: 40})
        logs = self.create_uas_logs(user, entries)
        assertSatisfiedWaypoints(expect, config.satisfied_waypoints(logs))

        # Hit all on run one, only hit the first waypoint on run two.
        entries = [(38, -76, 140),
                   (39, -77, 180),
                   (40, -78, 40),
                   # Run two:
                   (38, -76, 140),
                   (40, -78, 600),
                   (37, -75, 40)]
        expect = (3, 3, {0: 40, 1: 20, 2: 40})
        logs = self.create_uas_logs(user, entries)
        assertSatisfiedWaypoints(expect, config.satisfied_waypoints(logs))

        # Remain on the waypoint track only on the second run.
        entries = [(38, -76, 140),
                   (39, -77, 180),
                   (41, -78, 40),
                   (40, -78, 40),
                   # Run two:
                   (38, -76, 140),
                   (39, -77, 180),
                   (40, -78, 40)]
        expect = (3, 3, {0: 40, 1: 20, 2: 40})
        logs = self.create_uas_logs(user, entries)
        assertSatisfiedWaypoints(expect, config.satisfied_waypoints(logs))

        # Keep flying after hitting all waypoints.
        entries = [(38, -76, 140), (39, -77, 180), (40, -78, 40),
                   (30.1, -78.1, 100)]
        expect = (3, 3, {0: 40, 1: 20, 2: 40})
        logs = self.create_uas_logs(user, entries)
        assertSatisfiedWaypoints(expect, config.satisfied_waypoints(logs))

        # Miss last target by a sane distance.
        entries = [(38, -76, 140), (39, -77, 180), (40, -78, 60)]
        expect = (2, 2, {0: 40, 1: 20, 2: 60})
        logs = self.create_uas_logs(user, entries)
        assertSatisfiedWaypoints(expect, config.satisfied_waypoints(logs))
Example #19
0
    def test_out_of_bounds(self):
        """Tests the UAS out of bounds method."""
        (zone_details, uas_details) = TESTDATA_FLYZONE_EVALBOUNDS
        # Create FlyZone objects
        zones = []
        for (alt_min, alt_max, wpts) in zone_details:
            zone = FlyZone()
            zone.altitude_msl_min = alt_min
            zone.altitude_msl_max = alt_max
            zone.save()
            for wpt_id in xrange(len(wpts)):
                (lat, lon) = wpts[wpt_id]
                gpos = GpsPosition()
                gpos.latitude = lat
                gpos.longitude = lon
                gpos.save()
                apos = AerialPosition()
                apos.gps_position = gpos
                apos.altitude_msl = 0
                apos.save()
                wpt = Waypoint()
                wpt.order = wpt_id
                wpt.position = apos
                wpt.save()
                zone.boundary_pts.add(wpt)
            zone.save()
            zones.append(zone)

        # For each user, validate time out of bounds
        user_id = 0
        epoch = timezone.now().replace(year=1970,
                                       month=1,
                                       day=1,
                                       hour=0,
                                       minute=0,
                                       second=0,
                                       microsecond=0)
        for exp_out_of_bounds_time, uas_log_details in uas_details:
            # Create the logs
            user = User.objects.create_user('testuser%d' % user_id,
                                            '*****@*****.**', 'testpass')
            user_id += 1
            uas_logs = []
            for (lat, lon, alt, timestamp) in uas_log_details:
                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 = epoch + datetime.timedelta(seconds=timestamp)
                log.save()
                uas_logs.append(log)
            # Assert out of bounds time matches expected
            out_of_bounds_time = FlyZone.out_of_bounds(zones, uas_logs)
            self.assertAlmostEqual(out_of_bounds_time, exp_out_of_bounds_time)
Example #20
0
    def test_satisfied_waypoints(self):
        """Tests the evaluation of waypoints method."""
        # Create mission config
        gpos = GpsPosition()
        gpos.latitude = 10
        gpos.longitude = 10
        gpos.save()
        config = MissionConfig()
        config.home_pos = gpos
        config.emergent_last_known_pos = gpos
        config.off_axis_target_pos = gpos
        config.sric_pos = gpos
        config.air_drop_pos = gpos
        config.server_info = self.info
        config.save()

        # Create waypoints for config
        waypoints = [(38, -76, 100), (39, -77, 200), (40, -78, 0)]
        for i, waypoint in enumerate(waypoints):
            (lat, lon, alt) = waypoint
            pos = GpsPosition()
            pos.latitude = lat
            pos.longitude = lon
            pos.save()
            apos = AerialPosition()
            apos.altitude_msl = alt
            apos.gps_position = pos
            apos.save()
            wpt = Waypoint()
            wpt.position = apos
            wpt.order = i
            wpt.save()
            config.mission_waypoints.add(wpt)
        config.save()

        # Create UAS telemetry logs
        user = User.objects.create_user('testuser', '*****@*****.**',
                                        'testpass')

        # Only first is valid.
        entries = [(38, -76, 140), (40, -78, 600), (37, -75, 40)]
        expect = (1, 1)
        logs = self.create_uas_logs(user, entries)
        self.assertEqual(expect, config.satisfied_waypoints(logs))

        # First and last are valid, but missed second, so third doesn't count.
        entries = [(38, -76, 140), (40, -78, 600), (40, -78, 40)]
        expect = (1, 1)
        logs = self.create_uas_logs(user, entries)
        self.assertEqual(expect, config.satisfied_waypoints(logs))

        # Hit all.
        entries = [(38, -76, 140), (39, -77, 180), (40, -78, 40)]
        expect = (3, 3)
        logs = self.create_uas_logs(user, entries)
        self.assertEqual(expect, config.satisfied_waypoints(logs))

        # Hit all, but don't stay within waypoint track.
        entries = [(38, -76, 140), (39, -77, 180), (41, -78, 40),
                   (40, -78, 40)]
        expect = (3, 2)
        logs = self.create_uas_logs(user, entries)
        self.assertEqual(expect, config.satisfied_waypoints(logs))

        # Only hit the first waypoint on run one, hit all on run two.
        entries = [(38, -76, 140),
                   (40, -78, 600),
                   (37, -75, 40),
                   # Run two:
                   (38, -76, 140),
                   (39, -77, 180),
                   (40, -78, 40)]
        expect = (3, 3)
        logs = self.create_uas_logs(user, entries)
        self.assertEqual(expect, config.satisfied_waypoints(logs))

        # Hit all on run one, only hit the first waypoint on run two.
        entries = [(38, -76, 140),
                   (39, -77, 180),
                   (40, -78, 40),
                   # Run two:
                   (38, -76, 140),
                   (40, -78, 600),
                   (37, -75, 40)]
        expect = (3, 3)
        logs = self.create_uas_logs(user, entries)
        self.assertEqual(expect, config.satisfied_waypoints(logs))

        # Remain on the waypoint track only on the second run.
        entries = [(38, -76, 140),
                   (39, -77, 180),
                   (41, -78, 40),
                   (40, -78, 40),
                   # Run two:
                   (38, -76, 140),
                   (39, -77, 180),
                   (40, -78, 40)]
        expect = (3, 3)
        logs = self.create_uas_logs(user, entries)
        self.assertEqual(expect, config.satisfied_waypoints(logs))
Example #21
0
    def test_satisfied_waypoints(self):
        """Tests the evaluation of waypoints method."""
        # Create mission config
        gpos = GpsPosition()
        gpos.latitude = 10
        gpos.longitude = 10
        gpos.save()
        config = MissionConfig()
        config.home_pos = gpos
        config.emergent_last_known_pos = gpos
        config.off_axis_target_pos = gpos
        config.sric_pos = gpos
        config.air_drop_pos = gpos
        config.server_info = self.info
        config.save()

        # Create waypoints for config
        waypoints = [(38, -76, 100), (39, -77, 200), (40, -78, 0)]
        for i, waypoint in enumerate(waypoints):
            (lat, lon, alt) = waypoint
            pos = GpsPosition()
            pos.latitude = lat
            pos.longitude = lon
            pos.save()
            apos = AerialPosition()
            apos.altitude_msl = alt
            apos.gps_position = pos
            apos.save()
            wpt = Waypoint()
            wpt.position = apos
            wpt.order = i
            wpt.save()
            config.mission_waypoints.add(wpt)
        config.save()

        # Create UAS telemetry logs
        user = User.objects.create_user('testuser', '*****@*****.**',
                                        'testpass')

        def assertSatisfiedWaypoints(expect, got):
            """Assert two satisfied_waypoints return values are equal."""
            self.assertEqual(expect[0], got[0])
            self.assertEqual(expect[1], got[1])
            for k in expect[2].keys():
                self.assertIn(k, got[2])
                self.assertAlmostEqual(expect[2][k], got[2][k], delta=0.1)
            for k in got[2].keys():
                self.assertIn(k, expect[2])

        # Only first is valid.
        entries = [(38, -76, 140), (40, -78, 600), (37, -75, 40)]
        expect = (1, 1, {0: 40, 1: 460785.17})
        logs = self.create_uas_logs(user, entries)
        assertSatisfiedWaypoints(expect, config.satisfied_waypoints(logs))

        # First and last are valid, but missed second, so third doesn't count.
        entries = [(38, -76, 140), (40, -78, 600), (40, -78, 40)]
        expect = (1, 1, {0: 40, 1: 460785.03})
        logs = self.create_uas_logs(user, entries)
        assertSatisfiedWaypoints(expect, config.satisfied_waypoints(logs))

        # Hit all.
        entries = [(38, -76, 140), (39, -77, 180), (40, -78, 40)]
        expect = (3, 3, {0: 40, 1: 20, 2: 40})
        logs = self.create_uas_logs(user, entries)
        assertSatisfiedWaypoints(expect, config.satisfied_waypoints(logs))

        # Hit all, but don't stay within waypoint track.
        entries = [(38, -76, 140), (39, -77, 180), (41, -78, 40),
                   (40, -78, 40)]
        expect = (3, 2, {0: 40, 1: 20, 2: 40})
        logs = self.create_uas_logs(user, entries)
        assertSatisfiedWaypoints(expect, config.satisfied_waypoints(logs))

        # Only hit the first waypoint on run one, hit all on run two.
        entries = [
            (38, -76, 140),
            (40, -78, 600),
            (37, -75, 40),
            # Run two:
            (38, -76, 140),
            (39, -77, 180),
            (40, -78, 40)
        ]
        expect = (3, 3, {0: 40, 1: 20, 2: 40})
        logs = self.create_uas_logs(user, entries)
        assertSatisfiedWaypoints(expect, config.satisfied_waypoints(logs))

        # Hit all on run one, only hit the first waypoint on run two.
        entries = [
            (38, -76, 140),
            (39, -77, 180),
            (40, -78, 40),
            # Run two:
            (38, -76, 140),
            (40, -78, 600),
            (37, -75, 40)
        ]
        expect = (3, 3, {0: 40, 1: 20, 2: 40})
        logs = self.create_uas_logs(user, entries)
        assertSatisfiedWaypoints(expect, config.satisfied_waypoints(logs))

        # Remain on the waypoint track only on the second run.
        entries = [
            (38, -76, 140),
            (39, -77, 180),
            (41, -78, 40),
            (40, -78, 40),
            # Run two:
            (38, -76, 140),
            (39, -77, 180),
            (40, -78, 40)
        ]
        expect = (3, 3, {0: 40, 1: 20, 2: 40})
        logs = self.create_uas_logs(user, entries)
        assertSatisfiedWaypoints(expect, config.satisfied_waypoints(logs))

        # Keep flying after hitting all waypoints.
        entries = [(38, -76, 140), (39, -77, 180), (40, -78, 40),
                   (30.1, -78.1, 100)]
        expect = (3, 3, {0: 40, 1: 20, 2: 40})
        logs = self.create_uas_logs(user, entries)
        assertSatisfiedWaypoints(expect, config.satisfied_waypoints(logs))

        # Miss last target by a sane distance.
        entries = [(38, -76, 140), (39, -77, 180), (40, -78, 60)]
        expect = (2, 2, {0: 40, 1: 20, 2: 60})
        logs = self.create_uas_logs(user, entries)
        assertSatisfiedWaypoints(expect, config.satisfied_waypoints(logs))
Example #22
0
    def test_out_of_bounds(self):
        """Tests the UAS out of bounds method."""
        (zone_details, uas_details) = TESTDATA_FLYZONE_EVALBOUNDS
        # Create FlyZone objects
        zones = []
        for (alt_min, alt_max, wpts) in zone_details:
            zone = FlyZone()
            zone.altitude_msl_min = alt_min
            zone.altitude_msl_max = alt_max
            zone.save()
            for wpt_id in xrange(len(wpts)):
                (lat, lon) = wpts[wpt_id]
                gpos = GpsPosition()
                gpos.latitude = lat
                gpos.longitude = lon
                gpos.save()
                apos = AerialPosition()
                apos.gps_position = gpos
                apos.altitude_msl = 0
                apos.save()
                wpt = Waypoint()
                wpt.order = wpt_id
                wpt.position = apos
                wpt.save()
                zone.boundary_pts.add(wpt)
            zone.save()
            zones.append(zone)

        # For each user, validate time out of bounds
        user_id = 0
        epoch = timezone.now().replace(
            year=1970,
            month=1,
            day=1,
            hour=0,
            minute=0,
            second=0,
            microsecond=0)
        for exp_out_of_bounds_time, uas_log_details in uas_details:
            # Create the logs
            user = User.objects.create_user('testuser%d' % user_id,
                                            '*****@*****.**', 'testpass')
            user_id += 1
            uas_logs = []
            for (lat, lon, alt, timestamp) in uas_log_details:
                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 = epoch + datetime.timedelta(seconds=timestamp)
                log.save()
                uas_logs.append(log)
            # Assert out of bounds time matches expected
            out_of_bounds_time = FlyZone.out_of_bounds(zones, uas_logs)
            self.assertAlmostEqual(out_of_bounds_time, exp_out_of_bounds_time)