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 setUp(self): """Populates an active mission to test a cached view.""" pos = GpsPosition() pos.latitude = 10 pos.longitude = 10 pos.save() self.pos = pos obst = StationaryObstacle() obst.gps_position = pos obst.cylinder_radius = 10 obst.cylinder_height = 10 obst.save() self.obst = obst config = MissionConfig() config.is_active = True 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.save() self.config = config config.stationary_obstacles.add(obst) config.save() self.login_url = reverse('auvsi_suas:login') self.obst_url = reverse('auvsi_suas:obstacles') self.clear_cache_url = reverse('auvsi_suas:clear_cache')
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__())
def setUp(self): """Setup a single active mission to test live kml with.""" super(TestGenerateLiveKMLNoFixture, self).setUp() pos = GpsPosition() pos.latitude = 10 pos.longitude = 10 pos.save() info = ServerInfo() info.timestamp = timezone.now() info.message = "Hello World" info.save() config = MissionConfig() config.is_active = True config.home_pos = pos config.emergent_last_known_pos = pos config.off_axis_target_pos = pos config.sric_pos = pos config.ir_primary_target_pos = pos config.ir_secondary_target_pos = pos config.air_drop_pos = pos config.server_info = info config.save() self.config = config
def setUp(self): self.user = User.objects.create_user('testuser', '*****@*****.**', 'testpass') self.user.save() # Create an active mission. pos = GpsPosition() pos.latitude = 10 pos.longitude = 10 pos.save() config = MissionConfig() config.is_active = True 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.save() # Add a couple of stationary obstacles obst = self.create_stationary_obstacle(lat=38.142233, lon=-76.434082, radius=300, height=500) config.stationary_obstacles.add(obst) obst = self.create_stationary_obstacle(lat=38.442233, lon=-76.834082, radius=100, height=750) config.stationary_obstacles.add(obst) # And a couple of moving obstacles obst = self.create_moving_obstacle([ # (lat, lon, alt) (38.142233, -76.434082, 300), (38.141878, -76.425198, 700), ]) config.moving_obstacles.add(obst) obst = self.create_moving_obstacle([ # (lat, lon, alt) (38.145405, -76.428310, 100), (38.146582, -76.424099, 200), (38.144662, -76.427634, 300), (38.147729, -76.419185, 200), (38.147573, -76.420832, 100), (38.148522, -76.419507, 750), ]) config.moving_obstacles.add(obst) config.save() # Login response = self.client.post(login_url, { 'username': '******', 'password': '******' }) self.assertEqual(200, response.status_code)
def setUp(self): self.user = User.objects.create_user("testuser", "*****@*****.**", "testpass") self.user.save() # Create an active mission. pos = GpsPosition() pos.latitude = 10 pos.longitude = 10 pos.save() info = ServerInfo() info.timestamp = datetime.datetime.now() info.message = "Hello World" info.save() config = MissionConfig() config.is_active = True 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 = info config.save() # Add a couple of stationary obstacles obst = self.create_stationary_obstacle(lat=38.142233, lon=-76.434082, radius=300, height=500) config.stationary_obstacles.add(obst) obst = self.create_stationary_obstacle(lat=38.442233, lon=-76.834082, radius=100, height=750) config.stationary_obstacles.add(obst) # And a couple of moving obstacles obst = self.create_moving_obstacle( [ # (lat, lon, alt) (38.142233, -76.434082, 300), (38.141878, -76.425198, 700), ] ) config.moving_obstacles.add(obst) obst = self.create_moving_obstacle( [ # (lat, lon, alt) (38.145405, -76.428310, 100), (38.146582, -76.424099, 200), (38.144662, -76.427634, 300), (38.147729, -76.419185, 200), (38.147573, -76.420832, 100), (38.148522, -76.419507, 750), ] ) config.moving_obstacles.add(obst) config.save() # Login response = self.client.post(login_url, {"username": "******", "password": "******"}) self.assertEqual(200, response.status_code)
def create_config(self): """Creates a dummy config for testing.""" pos = GpsPosition() pos.latitude = 10 pos.longitude = 10 pos.save() config = MissionConfig() config.is_active = False 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 return config
def setUp(self): """Setup a single active mission to test live kml with.""" super(TestGenerateLiveKMLNoFixture, self).setUp() pos = GpsPosition() pos.latitude = 10 pos.longitude = 10 pos.save() config = MissionConfig() config.is_active = True 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.save() self.config = config
def create_config(self): """Creates a dummy config for testing.""" pos = GpsPosition() pos.latitude = 10 pos.longitude = 10 pos.save() info = ServerInfo() info.timestamp = datetime.datetime.now() info.message = "Hello World" info.save() config = MissionConfig() config.is_active = False 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 = info return config
def setUp(self): """Populates an active mission to test a cached view.""" pos = GpsPosition() pos.latitude = 10 pos.longitude = 10 pos.save() self.pos = pos info = ServerInfo() info.timestamp = datetime.datetime.now() info.message = "Hello World" info.save() obst = StationaryObstacle() obst.gps_position = pos obst.cylinder_radius = 10 obst.cylinder_height = 10 obst.save() self.obst = obst config = MissionConfig() config.is_active = True config.home_pos = pos config.emergent_last_known_pos = pos config.off_axis_target_pos = pos config.sric_pos = pos config.ir_primary_target_pos = pos config.ir_secondary_target_pos = pos config.air_drop_pos = pos config.server_info = info config.save() self.config = config config.stationary_obstacles.add(obst) config.save() self.login_url = reverse('auvsi_suas:login') self.obst_url = reverse('auvsi_suas:obstacles') self.clear_cache_url = reverse('auvsi_suas:clear_cache')
def setUp(self): """Setup a single active mission to test live kml with.""" super(TestGenerateLiveKMLNoFixture, self).setUp() pos = GpsPosition() pos.latitude = 10 pos.longitude = 10 pos.save() info = ServerInfo() info.timestamp = timezone.now() info.message = "Hello World" info.save() config = MissionConfig() config.is_active = True 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 = info config.save() self.config = config
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))
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))
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))
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))