static bool test_olc(int n_wind, Contest olc_type) { GlidePolar glide_polar(fixed_two); Waypoints waypoints; SetupWaypoints(waypoints); if (verbose) PrintDistanceCounts(); TaskBehaviour task_behaviour; task_behaviour.SetDefaults(); task_behaviour.DisableAll(); if (!verbose) task_behaviour.enable_trace = false; TaskManager task_manager(task_behaviour, waypoints); TaskEventsPrint default_events(verbose); task_manager.SetTaskEvents(default_events); task_manager.SetGlidePolar(glide_polar); test_task(task_manager, waypoints, 1); waypoints.Clear(); // clear waypoints so abort wont do anything autopilot_parms.goto_target = true; return run_flight(task_manager, autopilot_parms, n_wind); }
static bool test_goto(int n_wind, unsigned id, bool auto_mc) { GlidePolar glide_polar(fixed(2)); Waypoints waypoints; SetupWaypoints(waypoints); if (verbose) PrintDistanceCounts(); TaskBehaviour task_behaviour; task_behaviour.SetDefaults(); task_behaviour.DisableAll(); task_behaviour.auto_mc = auto_mc; task_behaviour.enable_trace = false; TaskManager task_manager(task_behaviour, waypoints); TaskEventsPrint default_events(verbose); task_manager.SetTaskEvents(default_events); task_manager.SetGlidePolar(glide_polar); test_task(task_manager, waypoints, 1); task_manager.DoGoto(*waypoints.LookupId(id)); task_report(task_manager, "goto"); waypoints.Clear(); // clear waypoints so abort wont do anything autopilot_parms.goto_target = true; return run_flight(task_manager, autopilot_parms, n_wind); }
static bool test_null() { GlidePolar glide_polar(fixed(2)); Waypoints waypoints; SetupWaypoints(waypoints); if (verbose) PrintDistanceCounts(); TaskBehaviour task_behaviour; task_behaviour.SetDefaults(); task_behaviour.DisableAll(); task_behaviour.enable_trace = false; TaskManager task_manager(task_behaviour, waypoints); TaskEventsPrint default_events(verbose); task_manager.SetTaskEvents(default_events); task_manager.SetGlidePolar(glide_polar); task_report(task_manager, "null"); waypoints.Clear(); // clear waypoints so abort wont do anything autopilot_parms.goto_target = true; return run_flight(task_manager, autopilot_parms, 0); }
static bool test_abort(int n_wind) { GlidePolar glide_polar(fixed(2)); Waypoints waypoints; SetupWaypoints(waypoints); if (verbose) PrintDistanceCounts(); TaskBehaviour task_behaviour; task_behaviour.SetDefaults(); task_behaviour.DisableAll(); task_behaviour.enable_trace = false; TaskManager task_manager(task_behaviour, waypoints); TaskEventsPrint default_events(verbose); task_manager.SetTaskEvents(default_events); task_manager.SetGlidePolar(glide_polar); test_task(task_manager, waypoints, 1); task_manager.Abort(); task_report(task_manager, "abort"); autopilot_parms.goto_target = true; return run_flight(task_manager, autopilot_parms, n_wind); }
TestFlightResult test_flight(TestFlightComponents components, int test_num, int n_wind, const double speed_factor, const bool auto_mc) { // multipurpose flight test GlidePolar glide_polar(fixed(2)); Waypoints waypoints; SetupWaypoints(waypoints); if (verbose) PrintDistanceCounts(); TaskBehaviour task_behaviour; task_behaviour.SetDefaults(); task_behaviour.enable_trace = false; task_behaviour.auto_mc = auto_mc; task_behaviour.calc_glide_required = false; if ((test_num == 0) || (test_num == 2)) task_behaviour.optimise_targets_bearing = false; TaskManager task_manager(task_behaviour, waypoints); TaskEventsPrint default_events(verbose); task_manager.SetTaskEvents(default_events); task_manager.SetGlidePolar(glide_polar); OrderedTaskSettings otb = task_manager.GetOrderedTask().GetOrderedTaskSettings(); otb.aat_min_time = aat_min_time(test_num); task_manager.SetOrderedTaskSettings(otb); bool goto_target = false; switch (test_num) { case 0: case 2: case 7: goto_target = true; break; }; autopilot_parms.goto_target = goto_target; test_task(task_manager, waypoints, test_num); waypoints.Clear(); // clear waypoints so abort wont do anything return run_flight(components, task_manager, autopilot_parms, n_wind, speed_factor); }
bool test_flight(int test_num, int n_wind, const double speed_factor, const bool auto_mc) { // multipurpose flight test GlidePolar glide_polar(fixed_two); Waypoints waypoints; setup_waypoints(waypoints); if (verbose) distance_counts(); TaskEventsPrint default_events(verbose); TaskManager task_manager(default_events, waypoints); task_manager.set_glide_polar(glide_polar); task_manager.get_ordered_task_behaviour().aat_min_time = aat_min_time(test_num); TaskBehaviour task_behaviour = task_manager.get_task_behaviour(); task_behaviour.enable_trace = false; task_behaviour.auto_mc = auto_mc; task_behaviour.calc_glide_required = false; if ((test_num == 0) || (test_num == 2)) task_behaviour.optimise_targets_bearing = false; task_manager.set_task_behaviour(task_behaviour); bool goto_target = false; switch (test_num) { case 0: case 2: case 7: goto_target = true; break; }; autopilot_parms.goto_target = goto_target; test_task(task_manager, waypoints, test_num); waypoints.clear(); // clear waypoints so abort wont do anything return run_flight(task_manager, autopilot_parms, n_wind, speed_factor); }
int main(int argc, char** argv) { // default arguments verbose=1; if (!parse_args(argc,argv)) { return 0; } TaskBehaviour task_behaviour; TaskEventsPrint default_events(verbose); GlidePolar glide_polar(fixed_two); Waypoints waypoints; setup_waypoints(waypoints); TaskManager task_manager(default_events, task_behaviour, waypoints); task_manager.set_glide_polar(glide_polar); test_task(task_manager, waypoints, 0); plan_tests(1); ok(test_edit(task_manager, task_behaviour), "edit task", 0); /* plan_tests(task_manager.task_size()); // here goes, example, edit all task points SafeTaskEdit ste(task_manager, waypoints); for (unsigned i=0; i<task_manager.task_size(); i++) { ok(ste.edit(i),"edit tp",0); task_report(task_manager, "edit tp\n"); } */ return exit_status(); }
static bool test_replay() { Directory::Create(Path(_T("output/results"))); std::ofstream f("output/results/res-sample.txt"); GlidePolar glide_polar(4.0); Waypoints waypoints; AircraftState state_last; TaskBehaviour task_behaviour; task_behaviour.SetDefaults(); task_behaviour.auto_mc = true; TaskManager task_manager(task_behaviour, waypoints); TaskEventsPrint default_events(verbose); task_manager.SetTaskEvents(default_events); glide_polar.SetBallast(1.0); task_manager.SetGlidePolar(glide_polar); OrderedTask* t = task_load(task_behaviour); if (t) { task_manager.Commit(*t); delete t; task_manager.Resume(); } else { return false; } // task_manager.get_task_advance().get_advance_state() = TaskAdvance::AUTO; Error error; FileLineReaderA *reader = new FileLineReaderA(replay_file, error); if (reader->error()) { delete reader; fprintf(stderr, "%s\n", error.GetMessage()); return false; } ReplayLoggerSim sim(reader); sim.state.netto_vario = 0; bool do_print = verbose; unsigned print_counter=0; NMEAInfo basic; basic.Reset(); while (sim.Update(basic) && !sim.started) { } state_last = sim.state; sim.state.wind.norm = 7; sim.state.wind.bearing = Angle::Degrees(330); auto time_last = sim.state.time; // uncomment this to manually go to first tp // task_manager.incrementActiveTaskPoint(1); FlyingComputer flying_computer; flying_computer.Reset(); FlyingState flying_state; flying_state.Reset(); while (sim.Update(basic)) { if (sim.state.time>time_last) { n_samples++; flying_computer.Compute(glide_polar.GetVTakeoff(), sim.state, sim.state.time - time_last, flying_state); sim.state.flying = flying_state.flying; task_manager.Update(sim.state, state_last); task_manager.UpdateIdle(sim.state); task_manager.UpdateAutoMC(sim.state, 0); task_manager.SetTaskAdvance().SetArmed(true); state_last = sim.state; if (verbose>1) { sim.print(f); f.flush(); } if (do_print) { PrintHelper::taskmanager_print(task_manager, sim.state); } do_print = (++print_counter % output_skip ==0) && verbose; } time_last = sim.state.time; }; if (verbose) { PrintDistanceCounts(); printf("# task elapsed %d (s)\n", (int)task_manager.GetStats().total.time_elapsed); printf("# task speed %3.1f (kph)\n", (int)task_manager.GetStats().total.travelled.GetSpeed()*3.6); printf("# travelled distance %4.1f (km)\n", (double)task_manager.GetStats().total.travelled.GetDistance()/1000.0); printf("# scored distance %4.1f (km)\n", (double)task_manager.GetStats().distance_scored/1000.0); if (task_manager.GetStats().total.time_elapsed > 0) { printf("# scored speed %3.1f (kph)\n", (double)task_manager.GetStats().distance_scored/(double)task_manager.GetStats().total.time_elapsed*3.6); } } return true; }
static bool test_replay(const OLCRules olc_type) { #ifdef DO_PRINT std::ofstream f("results/res-sample.txt"); #endif GlidePolar glide_polar(fixed_two); Waypoints waypoints; AIRCRAFT_STATE state_last; TaskBehaviour task_behaviour; TaskEventsPrint default_events(verbose); TaskManager task_manager(default_events, waypoints); task_manager.set_glide_polar(glide_polar); task_manager.get_task_behaviour().olc_rules = olc_type; task_manager.get_task_behaviour().enable_olc = true; ReplayLoggerSim sim; TCHAR szFilename[MAX_PATH]; ConvertCToT(szFilename, replay_file.c_str()); sim.SetFilename(szFilename); sim.Start(); bool do_print = verbose; unsigned print_counter=0; while (sim.Update() && !sim.started) { } state_last = sim.state; fixed time_last = sim.state.Time; while (sim.Update()) { if (sim.state.Time>time_last) { n_samples++; if (sim.state.Speed> glide_polar.get_Vtakeoff()) { sim.state.flying_state_moving(sim.state.Time); } else { sim.state.flying_state_stationary(sim.state.Time); } task_manager.update(sim.state, state_last); task_manager.update_idle(sim.state); task_manager.update_auto_mc(sim.state, fixed_zero); state_last = sim.state; #ifdef DO_PRINT if (verbose) { sim.print(f); f.flush(); } if (do_print) { task_manager.print(sim.state); } #endif do_print = (++print_counter % output_skip ==0) && verbose; } time_last = sim.state.Time; }; sim.Stop(); const CommonStats& stats = task_manager.get_common_stats(); printf("# OLC dist %g speed %g time %g\n", (double)stats.olc.distance, (double)(stats.olc.speed*fixed(3.6)), (double)stats.olc.time); if (verbose) { distance_counts(); } return true; }
static bool test_replay(const Contests olc_type, const ContestResult &official_score) { std::ofstream f("results/res-sample.txt"); GlidePolar glide_polar(fixed_two); Waypoints waypoints; AIRCRAFT_STATE state_last; TaskBehaviour task_behaviour; TaskEventsPrint default_events(verbose); TaskManager task_manager(default_events, waypoints); task_manager.set_glide_polar(glide_polar); task_manager.set_contest(olc_type); task_manager.get_task_behaviour().enable_olc = true; ReplayLoggerSim sim; TCHAR szFilename[MAX_PATH]; ConvertCToT(szFilename, replay_file.c_str()); sim.SetFilename(szFilename); load_scores(task_manager.get_task_behaviour().contest_handicap); if (verbose) { switch (olc_type) { case OLC_League: std::cout << "# OLC-League\n"; break; case OLC_Sprint: std::cout << "# OLC-Sprint\n"; break; case OLC_FAI: std::cout << "# OLC-FAI\n"; break; case OLC_Classic: std::cout << "# OLC-Classic\n"; break; case OLC_Plus: std::cout << "# OLC-Plus\n"; break; default: std::cout << "# Unknown!\n"; break; } } sim.Start(); bool do_print = verbose; unsigned print_counter=0; while (sim.Update() && !sim.started) { } state_last = sim.state; fixed time_last = sim.state.Time; while (sim.Update()) { if (sim.state.Time>time_last) { n_samples++; if (sim.state.Speed> glide_polar.get_Vtakeoff()) { sim.state.flying_state_moving(sim.state.Time); } else { sim.state.flying_state_stationary(sim.state.Time); } task_manager.update(sim.state, state_last); task_manager.update_idle(sim.state); state_last = sim.state; if (verbose>1) { sim.print(f); f.flush(); } if (do_print) { PrintHelper::taskmanager_print(task_manager, sim.state); } do_print = (++print_counter % output_skip ==0) && verbose; } time_last = sim.state.Time; }; sim.Stop(); task_manager.score_exhaustive(); if (verbose) { distance_counts(); } return compare_scores(official_score, task_manager.get_contest_stats().get_contest_result(0)); }
static bool test_replay() { std::ofstream f("results/res-sample.txt"); GlidePolar glide_polar(fixed(4.0)); Waypoints waypoints; AIRCRAFT_STATE state_last; TaskBehaviour task_behaviour; TaskEventsPrint default_events(verbose); TaskManager task_manager(default_events, waypoints); glide_polar.set_ballast(fixed(1.0)); task_manager.set_glide_polar(glide_polar); task_manager.get_task_behaviour().auto_mc = true; task_manager.get_task_behaviour().enable_trace = false; OrderedTask* blank = new OrderedTask(default_events, task_behaviour, glide_polar); OrderedTask* t = task_load(blank); if (t) { task_manager.commit(*t); task_manager.resume(); } else { return false; } // task_manager.get_task_advance().get_advance_state() = TaskAdvance::AUTO; ReplayLoggerSim sim; sim.state.NettoVario = fixed_zero; TCHAR szFilename[MAX_PATH]; ConvertCToT(szFilename, replay_file.c_str()); sim.SetFilename(szFilename); sim.Start(); bool do_print = verbose; unsigned print_counter=0; while (sim.Update() && !sim.started) { } state_last = sim.state; sim.state.wind.norm = fixed(7); sim.state.wind.bearing = Angle::degrees(fixed(330)); fixed time_last = sim.state.Time; // uncomment this to manually go to first tp // task_manager.incrementActiveTaskPoint(1); while (sim.Update()) { if (sim.state.Time>time_last) { n_samples++; if (sim.state.Speed> glide_polar.get_Vtakeoff()) { sim.state.flying_state_moving(sim.state.Time); } else { sim.state.flying_state_stationary(sim.state.Time); } task_manager.update(sim.state, state_last); task_manager.update_idle(sim.state); task_manager.update_auto_mc(sim.state, fixed_zero); task_manager.get_task_advance().set_armed(true); state_last = sim.state; if (verbose>1) { sim.print(f); f.flush(); } if (do_print) { PrintHelper::taskmanager_print(task_manager, sim.state); } do_print = (++print_counter % output_skip ==0) && verbose; } time_last = sim.state.Time; }; sim.Stop(); if (verbose) { distance_counts(); printf("# task elapsed %d (s)\n", (int)task_manager.get_stats().total.TimeElapsed); printf("# task speed %3.1f (kph)\n", (int)task_manager.get_stats().total.travelled.get_speed()*3.6); printf("# travelled distance %4.1f (km)\n", (double)task_manager.get_stats().total.travelled.get_distance()/1000.0); printf("# scored distance %4.1f (km)\n", (double)task_manager.get_stats().distance_scored/1000.0); if (task_manager.get_stats().total.TimeElapsed) { printf("# scored speed %3.1f (kph)\n", (double)task_manager.get_stats().distance_scored/(double)task_manager.get_stats().total.TimeElapsed*3.6); } } return true; }