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))
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))
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)
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))
def setUp(self): self.user = User.objects.create_user('testuser', '*****@*****.**', 'testpass') self.user.save() # Mission 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() self.mission = MissionConfig() self.mission.home_pos = pos self.mission.emergent_last_known_pos = pos self.mission.off_axis_odlc_pos = pos self.mission.air_drop_pos = pos self.mission.save() self.mission.mission_waypoints.add(wpt) self.mission.search_grid_points.add(wpt) self.mission.save() self.now = timezone.now()
def setUp(self): """Sets up the tests.""" super(TestOdlc, self).setUp() self.user = User.objects.create_user('user', '*****@*****.**', 'pass') # Mission 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() self.mission = MissionConfig() self.mission.home_pos = pos self.mission.emergent_last_known_pos = pos self.mission.off_axis_odlc_pos = pos self.mission.air_drop_pos = pos self.mission.save() self.mission.mission_waypoints.add(wpt) self.mission.search_grid_points.add(wpt) self.mission.save()
def setUp(self): # Mission 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() self.mission = MissionConfig() self.mission.home_pos = pos self.mission.emergent_last_known_pos = pos self.mission.off_axis_odlc_pos = pos self.mission.air_drop_pos = pos self.mission.save() self.mission.mission_waypoints.add(wpt) self.mission.search_grid_points.add(wpt) self.mission.save() # Mission 2 self.mission2 = MissionConfig() self.mission2.home_pos = pos self.mission2.emergent_last_known_pos = pos self.mission2.off_axis_odlc_pos = pos self.mission2.air_drop_pos = pos self.mission2.save() self.mission2.mission_waypoints.add(wpt) self.mission2.search_grid_points.add(wpt) self.mission2.save()
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)
def waypoints_from_data(self, waypoints_data): """Converts tuples of lat/lon/alt to a waypoint.""" waypoints = [] for i, waypoint in enumerate(waypoints_data): (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() waypoints.append(wpt) return waypoints
def setUp(self): 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_odlc_pos = pos config.air_drop_pos = pos config.save() config.mission_waypoints.add(wpt) config.search_grid_points.add(wpt) config.save() user = User.objects.create_user('user', '*****@*****.**', 'pass') self.feedback = MissionJudgeFeedback( mission=config, user=user, flight_time=datetime.timedelta(seconds=1), post_process_time=datetime.timedelta(seconds=2), used_timeout=True, min_auto_flight_time=True, safety_pilot_takeovers=3, waypoints_captured=5, out_of_bounds=6, unsafe_out_of_bounds=7, things_fell_off_uas=False, crashed=False, air_drop_accuracy=interop_admin_api_pb2.MissionJudgeFeedback. WITHIN_05_FT, ugv_drove_to_location=False, operational_excellence_percent=9) self.feedback.save()
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__())
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__())
def setUp(self): super(TestTakeoffOrLandingEventModel, self).setUp() # Mission 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() self.mission = MissionConfig() self.mission.home_pos = pos self.mission.emergent_last_known_pos = pos self.mission.off_axis_odlc_pos = pos self.mission.air_drop_pos = pos self.mission.save() self.mission.mission_waypoints.add(wpt) self.mission.search_grid_points.add(wpt) self.mission.save() # Mission 2 self.mission2 = MissionConfig() self.mission2.home_pos = pos self.mission2.emergent_last_known_pos = pos self.mission2.off_axis_odlc_pos = pos self.mission2.air_drop_pos = pos self.mission2.save() self.mission2.mission_waypoints.add(wpt) self.mission2.search_grid_points.add(wpt) self.mission2.save() self.ten_minutes = datetime.timedelta(minutes=10)
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.air_drop_pos = pos config.save() config.mission_waypoints.add(wpt) config.search_grid_points.add(wpt) config.save() self.assertTrue(config.__unicode__())
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_violations, exp_out_of_bounds_time, 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 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 num_violations, out_of_bounds_time = \ FlyZone.out_of_bounds(zones, uas_logs) self.assertEqual(num_violations, exp_violations) self.assertAlmostEqual(out_of_bounds_time, exp_out_of_bounds_time)
def setUp(self): """Setup the test case.""" super(TestOdlcEvaluator, self).setUp() self.maxDiff = None self.user = User.objects.create_user('user', '*****@*****.**', 'pass') l1 = GpsPosition(latitude=38, longitude=-76) l1.save() l2 = GpsPosition(latitude=38.0003, longitude=-76) l2.save() l3 = GpsPosition(latitude=-38, longitude=76) l3.save() l4 = GpsPosition(latitude=0, longitude=0) l4.save() # Mission 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() self.mission = MissionConfig() self.mission.home_pos = pos self.mission.emergent_last_known_pos = pos self.mission.off_axis_odlc_pos = pos self.mission.air_drop_pos = pos self.mission.save() self.mission.mission_waypoints.add(wpt) self.mission.search_grid_points.add(wpt) self.mission.save() event = TakeoffOrLandingEvent(user=self.user, mission=self.mission, uas_in_air=True) event.save() # A odlc worth full points. self.submit1 = Odlc(mission=self.mission, user=self.user, odlc_type=interop_api_pb2.Odlc.STANDARD, location=l1, orientation=interop_api_pb2.Odlc.S, shape=interop_api_pb2.Odlc.SQUARE, background_color=interop_api_pb2.Odlc.WHITE, alphanumeric='ABC', alphanumeric_color=interop_api_pb2.Odlc.BLACK, description='Submit test odlc 1', description_approved=True, autonomous=True, thumbnail_approved=True) self.submit1.save() self.real1 = Odlc(mission=self.mission, user=self.user, odlc_type=interop_api_pb2.Odlc.STANDARD, location=l1, orientation=interop_api_pb2.Odlc.S, shape=interop_api_pb2.Odlc.SQUARE, background_color=interop_api_pb2.Odlc.WHITE, alphanumeric='ABC', alphanumeric_color=interop_api_pb2.Odlc.BLACK, description='Real odlc 1') self.real1.save() # A odlc worth less than full points. self.submit2 = Odlc( mission=self.mission, user=self.user, odlc_type=interop_api_pb2.Odlc.STANDARD, location=l1, orientation=interop_api_pb2.Odlc.N, shape=interop_api_pb2.Odlc.CIRCLE, background_color=interop_api_pb2.Odlc.WHITE, # alphanumeric set below alphanumeric_color=interop_api_pb2.Odlc.BLACK, description='Submit test odlc 2', autonomous=False, thumbnail_approved=True) self.submit2.save() self.real2 = Odlc(mission=self.mission, user=self.user, odlc_type=interop_api_pb2.Odlc.STANDARD, location=l2, orientation=interop_api_pb2.Odlc.S, shape=interop_api_pb2.Odlc.TRIANGLE, background_color=interop_api_pb2.Odlc.WHITE, alphanumeric='ABC', alphanumeric_color=interop_api_pb2.Odlc.BLACK, description='Real test odlc 2') self.real2.save() # A odlc worth no points, so unmatched. self.submit3 = Odlc(mission=self.mission, user=self.user, odlc_type=interop_api_pb2.Odlc.STANDARD, location=l4, orientation=interop_api_pb2.Odlc.NW, shape=interop_api_pb2.Odlc.PENTAGON, background_color=interop_api_pb2.Odlc.GRAY, alphanumeric='XYZ', alphanumeric_color=interop_api_pb2.Odlc.ORANGE, description='Incorrect description', autonomous=False, thumbnail_approved=True) self.submit3.save() self.real3 = Odlc( mission=self.mission, user=self.user, odlc_type=interop_api_pb2.Odlc.STANDARD, orientation=interop_api_pb2.Odlc.E, shape=interop_api_pb2.Odlc.SEMICIRCLE, background_color=interop_api_pb2.Odlc.YELLOW, alphanumeric='LMN', # alphanumeric_color set below location=l3, description='Test odlc 3') self.real3.save() # Odlcs without approved image has no match value. self.submit4 = Odlc(mission=self.mission, user=self.user, odlc_type=interop_api_pb2.Odlc.EMERGENT, location=l1, description='Test odlc 4', autonomous=False, thumbnail_approved=False) self.submit4.save() self.real4 = Odlc(mission=self.mission, user=self.user, odlc_type=interop_api_pb2.Odlc.EMERGENT, location=l1, description='Test odlc 4') self.real4.save() # A odlc without location worth fewer points. self.submit5 = Odlc(mission=self.mission, user=self.user, odlc_type=interop_api_pb2.Odlc.STANDARD, orientation=interop_api_pb2.Odlc.N, shape=interop_api_pb2.Odlc.TRAPEZOID, background_color=interop_api_pb2.Odlc.PURPLE, alphanumeric='PQR', alphanumeric_color=interop_api_pb2.Odlc.BLUE, description='Test odlc 5', autonomous=False, thumbnail_approved=True) self.submit5.save() self.real5 = Odlc(mission=self.mission, user=self.user, odlc_type=interop_api_pb2.Odlc.STANDARD, location=l1, orientation=interop_api_pb2.Odlc.N, shape=interop_api_pb2.Odlc.TRAPEZOID, background_color=interop_api_pb2.Odlc.PURPLE, alphanumeric='PQR', alphanumeric_color=interop_api_pb2.Odlc.BLUE, description='Test odlc 5') self.real5.save() # Emergent odlc with correct description. self.submit6 = Odlc(mission=self.mission, user=self.user, odlc_type=interop_api_pb2.Odlc.EMERGENT, location=l1, description='Submit test odlc 6', description_approved=True, autonomous=True, thumbnail_approved=True) self.submit6.save() self.real6 = Odlc(mission=self.mission, user=self.user, odlc_type=interop_api_pb2.Odlc.EMERGENT, location=l1, description='Real odlc 1', description_approved=True) self.real6.save() event = TakeoffOrLandingEvent(user=self.user, mission=self.mission, uas_in_air=False) event.save() # submit2 updated after landing. self.submit2.alphanumeric = 'ABC' self.submit2.update_last_modified() self.submit2.save() self.submit2.update_last_modified() self.submit3.alphanumeric_color = interop_api_pb2.Odlc.YELLOW self.submit3.update_last_modified() self.submit3.save() # Unused but not unmatched odlc. self.submit7 = Odlc(mission=self.mission, user=self.user, odlc_type=interop_api_pb2.Odlc.STANDARD, location=l4, alphanumeric_color=interop_api_pb2.Odlc.BLACK, description='Submit unused test odlc 1', autonomous=False, thumbnail_approved=True) self.submit7.save() self.submitted_odlcs = [ self.submit7, self.submit6, self.submit5, self.submit4, self.submit3, self.submit2, self.submit1 ] self.real_odlcs = [ self.real1, self.real2, self.real3, self.real4, self.real5, self.real6 ] self.flights = TakeoffOrLandingEvent.flights(self.mission, self.user)
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)
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.air_drop_pos = gpos 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 create_data(self): """Create a basic sample dataset.""" self.user1 = User.objects.create_user('user1', '*****@*****.**', 'testpass') self.user1.save() self.user2 = User.objects.create_user('user2', '*****@*****.**', 'testpass') self.user2.save() # Mission 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() self.mission = MissionConfig() self.mission.home_pos = pos self.mission.emergent_last_known_pos = pos self.mission.off_axis_odlc_pos = pos self.mission.air_drop_pos = pos self.mission.save() self.mission.mission_waypoints.add(wpt) self.mission.search_grid_points.add(wpt) self.mission.save() # user1 is flying event = TakeoffOrLandingEvent(user=self.user1, mission=self.mission, uas_in_air=True) event.save() # user2 has landed event = TakeoffOrLandingEvent(user=self.user2, mission=self.mission, uas_in_air=True) event.save() event = TakeoffOrLandingEvent(user=self.user2, mission=self.mission, uas_in_air=False) event.save() # user2 is active self.timestamp = timezone.now() gps = GpsPosition(latitude=38.6462, longitude=-76.2452) gps.save() pos = AerialPosition(gps_position=gps, altitude_msl=0) pos.save() self.telem = UasTelemetry(user=self.user2, uas_position=pos, uas_heading=90) self.telem.save() self.telem.timestamp = dateutil.parser.parse( u'2016-10-01T00:00:00.0+00:00') self.telem.save()
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.air_drop_pos = gpos 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 = ({0: 40}, {0: 0.6, 1: 0.0, 2: 0.0}, {0: 40, 1: 460785.17}) logs = self.create_uas_logs(user, entries) self.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 = ({0: 40}, {0: 0.6, 1: 0.0, 2: 0.0}, {0: 40, 1: 460785.03}) logs = self.create_uas_logs(user, entries) self.assertSatisfiedWaypoints(expect, config.satisfied_waypoints(logs)) # Hit all. entries = [(38, -76, 140), (39, -77, 180), (40, -78, 40)] expect = ({0: 40, 1: 20, 2: 40}, {0: 0.6, 1: 0.8, 2: 0.6}, {0: 40, 1: 20, 2: 40}) # yapf: disable logs = self.create_uas_logs(user, entries) self.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 = ({0: 40, 1: 20, 2: 40}, {0: 0.6, 1: 0.8, 2: 0.6}, {0: 40, 1: 20, 2: 40}) # yapf: disable logs = self.create_uas_logs(user, entries) self.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 = ({0: 40, 1: 20, 2: 40}, {0: 0.6, 1: 0.8, 2: 0.6}, {0: 40, 1: 20, 2: 40}) # yapf: disable logs = self.create_uas_logs(user, entries) self.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 = ({0: 40, 1: 20, 2: 40}, {0: 0.6, 1: 0.8, 2: 0.6}, {0: 40, 1: 20, 2: 40}) # yapf: disable logs = self.create_uas_logs(user, entries) self.assertSatisfiedWaypoints(expect, config.satisfied_waypoints(logs)) # Hit all in first run, but second is higher scoring. entries = [ (38, -76, 140), (39, -77, 180), (40, -78, 60), # Run two: (38, -76, 100), (39, -77, 200), (40, -78, 110) ] expect = ({0: 0, 1: 0}, {0: 1, 1: 1, 2: 0}, {0: 0, 1: 0, 2: 60}) logs = self.create_uas_logs(user, entries) self.assertSatisfiedWaypoints(expect, config.satisfied_waypoints(logs)) # Restart waypoint path in the middle. waypoints = [(38, -76, 100), (39, -77, 200), (40, -78, 0)] entries = [ (38, -76, 140), (39, -77, 180), # Restart: (38, -76, 70), (39, -77, 150), (40, -78, 10) ] expect = ({0: 30, 1: 50, 2: 10}, {0: 0.7, 1: 0.5, 2: 0.9}, {0: 30, 1: 20, 2: 10}) # yapf: disable logs = self.create_uas_logs(user, entries) self.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.air_drop_pos = gpos 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 = ({0: 40}, {0: 0.6, 1: 0.0, 2: 0.0}, {0: 40, 1: 460785.17}) logs = self.create_uas_logs(user, entries) self.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 = ({0: 40}, {0: 0.6, 1: 0.0, 2: 0.0}, {0: 40, 1: 460785.03}) logs = self.create_uas_logs(user, entries) self.assertSatisfiedWaypoints(expect, config.satisfied_waypoints(logs)) # Hit all. entries = [(38, -76, 140), (39, -77, 180), (40, -78, 40)] expect = ({0: 40, 1: 20, 2: 40}, {0: 0.6, 1: 0.8, 2: 0.6}, {0: 40, 1: 20, 2: 40}) # yapf: disable logs = self.create_uas_logs(user, entries) self.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 = ({0: 40, 1: 20, 2: 40}, {0: 0.6, 1: 0.8, 2: 0.6}, {0: 40, 1: 20, 2: 40}) # yapf: disable logs = self.create_uas_logs(user, entries) self.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 = ({0: 40, 1: 20, 2: 40}, {0: 0.6, 1: 0.8, 2: 0.6}, {0: 40, 1: 20, 2: 40}) # yapf: disable logs = self.create_uas_logs(user, entries) self.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 = ({0: 40, 1: 20, 2: 40}, {0: 0.6, 1: 0.8, 2: 0.6}, {0: 40, 1: 20, 2: 40}) # yapf: disable logs = self.create_uas_logs(user, entries) self.assertSatisfiedWaypoints(expect, config.satisfied_waypoints(logs)) # Hit all in first run, but second is higher scoring. entries = [(38, -76, 140), (39, -77, 180), (40, -78, 60), # Run two: (38, -76, 100), (39, -77, 200), (40, -78, 110)] expect = ({0: 0, 1: 0}, {0: 1, 1: 1, 2: 0}, {0: 0, 1: 0, 2: 60}) logs = self.create_uas_logs(user, entries) self.assertSatisfiedWaypoints(expect, config.satisfied_waypoints(logs)) # Restart waypoint path in the middle. waypoints = [(38, -76, 100), (39, -77, 200), (40, -78, 0)] entries = [(38, -76, 140), (39, -77, 180), # Restart: (38, -76, 70), (39, -77, 150), (40, -78, 10)] expect = ({0: 30, 1: 50, 2: 10}, {0: 0.7, 1: 0.5, 2: 0.9}, {0: 30, 1: 20, 2: 10}) # yapf: disable logs = self.create_uas_logs(user, entries) self.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.air_drop_pos = gpos 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_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_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)
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_violations, exp_out_of_bounds_time, 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 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 num_violations, out_of_bounds_time = \ FlyZone.out_of_bounds(zones, uas_logs) self.assertEqual(num_violations, exp_violations) self.assertAlmostEqual(out_of_bounds_time.total_seconds(), exp_out_of_bounds_time)