Beispiel #1
0
bool AircraftSim::Update()  {

  update_state();
  
  integrate();
  
  update_mode();

  task_manager.update(state, state_last);
  task_manager.update_idle(state);
  task_manager.update_auto_mc(state, fixed_zero);
  
  state_last = state;

  state.flying_state_moving(state.Time);
  
  if (!far()) {
    wait_prompt(time());
    
    awp++;
    if (awp>= w.size()) {
      return false;
    } 
    task_manager.setActiveTaskPoint(awp);
  }

  if (goto_target) {
    if (task_manager.getActiveTaskPointIndex() < awp) {
      // manual advance
      task_manager.setActiveTaskPoint(awp);
      if (verbose>1) {
        printf("# manual advance to %d\n",awp);
      }
    }
  }
  if (task_manager.getActiveTaskPointIndex() > awp) {
    awp = task_manager.getActiveTaskPointIndex();
  }
  if (awp>= w.size()) {
    return false;
  } 
  if (short_flight && awp>=1) {
    return false;
  }
  if (task_manager.get_common_stats().task_finished) {
    return false;
  }

  return true;
}
Beispiel #2
0
int connect_wait(msyncdata *md)
{
  int r;
  r = wait_prompt(md->s, md->passwd, 0, NULL);
  if(r == 0){
    fprintf(stderr, "remote socket close\n");
    return(1);
  }
  if(r == -1){
    fprintf(stderr, "socket read error\n");
    return(1);
  }
  return(0);
}
Beispiel #3
0
void task_report(TaskManager& task_manager, const char* text)
{
  AIRCRAFT_STATE ac;
  if (verbose) {
    printf("%s",text);

    const AbstractTask *task = task_manager.get_active_task();
    if (task != NULL) {
      switch (task->type) {
      case TaskInterface::ORDERED:
        printf("# task is ordered\n");
        break;

      case TaskInterface::ABORT:
        printf("# task is abort\n");
        break;

      case TaskInterface::GOTO:
        printf("# task is goto\n");
        break;
      }

      TaskPointVisitorPrint tpv;
      task->tp_CAccept(tpv);
      printf("# - dist nominal %g\n",
             (double)task->get_stats().distance_nominal);

      if (task->type == TaskInterface::ORDERED &&
          task->get_stats().distance_max > task->get_stats().distance_min) {
        printf("# - dist max %g\n", (double)task->get_stats().distance_max);
        printf("# - dist min %g\n", (double)task->get_stats().distance_min);
      }
    }

    PrintHelper::taskmanager_print(task_manager, ac);
  }
  if (interactive>1) {
    wait_prompt(0);
  }
}
Beispiel #4
0
int makuo(int s, char *c, int view)
{
  int  r;
  int  line = 1;
  char buff[256];
  if(sizeof(buff) < strlen(c) + 2){
    fprintf(stderr, "error: command too long\n");
    return(-1);
  }
  sprintf(buff, "%s\r\n", c);
  if(writeline(s, buff) == -1){
    fprintf(stderr, "error: can't write socket\n");
    return(-1);
  }
  r = wait_prompt(s, NULL, view, &line);
  if(r == -1){
    fprintf(stderr, "error: can't read socket\n");
    return(-1);
  }
  if(r == 0){
    return(0);
  }
  return(line);
}
Beispiel #5
0
bool run_flight(TaskManager &task_manager,
                const AutopilotParameters &parms,
                const int n_wind,
                const double speed_factor) 
{
  DirectTaskAccessor ta(task_manager);
  PrintTaskAutoPilot autopilot(parms);
  AircraftSim aircraft;

  autopilot.set_default_location(GeoPoint(Angle::degrees(fixed(1.0)), Angle::degrees(fixed(0.0))));

  unsigned print_counter=0;
  if (n_wind)
    aircraft.set_wind(wind_to_mag(n_wind), wind_to_dir(n_wind));

  autopilot.set_speed_factor(fixed(speed_factor));

  std::ofstream f4("results/res-sample.txt");
  std::ofstream f5("results/res-sample-filtered.txt");

  bool do_print = verbose;
  bool first = true;

  time_elapsed = 0.0;
  time_planned = 1.0;
  time_remaining = 0;
  calc_cruise_efficiency = 1.0;
  calc_effective_mc = 1.0;

  static const fixed fixed_10(10);

  AirspaceAircraftPerformanceGlide perf(task_manager.get_glide_polar());

  if (aircraft_filter)
    aircraft_filter->Reset(aircraft.get_state());

  autopilot.Start(ta);
  aircraft.Start(autopilot.location_start, autopilot.location_previous,
                 parms.start_alt);

  if (airspaces) {
    airspace_warnings =
        new AirspaceWarningManager(*airspaces, task_manager);
    airspace_warnings->reset(aircraft.get_state());
  }

  do {

    if ((task_manager.getActiveTaskPointIndex() == 1) &&
        first && (task_manager.get_stats().total.time_elapsed > fixed_10)) {
      time_remaining = task_manager.get_stats().total.time_remaining;
      first = false;

      time_planned = task_manager.get_stats().total.time_planned;

      if (verbose > 1) {
        printf("# time remaining %g\n", time_remaining);
        printf("# time planned %g\n", time_planned);
      }
    }

    if (do_print) {
      PrintHelper::taskmanager_print(task_manager, aircraft.get_state());

      const AircraftState state = aircraft.get_state();
      f4 << state.time << " "
         <<  state.location.Longitude << " "
         <<  state.location.Latitude << " "
         <<  state.altitude << "\n";

      f4.flush();
      if (aircraft_filter) {
        f5 << aircraft_filter->GetSpeed() << " " 
           << aircraft_filter->GetBearing() << " " 
           << aircraft_filter->GetClimbRate() << "\n"; 
        f5.flush();
      }
    }

    if (airspaces) {
      scan_airspaces(aircraft.get_state(), *airspaces, perf,
                     do_print, 
                     autopilot.target(ta));
    }
    if (airspace_warnings) {
      if (verbose > 1) {
        bool warnings_updated = airspace_warnings->update(aircraft.get_state(),
                                                          false, 1);
        if (warnings_updated) {
          printf("# airspace warnings updated, size %d\n",
                 (int)airspace_warnings->size());
          print_warnings();
          wait_prompt();
        }
      }
    }

    n_samples++;

    do_print = (++print_counter % output_skip == 0) && verbose;

    if (aircraft_filter)
      aircraft_filter->Update(aircraft.get_state());

    autopilot.update_state(ta, aircraft.get_state());
    aircraft.Update(autopilot.heading);

    {
      const AircraftState state = aircraft.get_state();
      const AircraftState state_last = aircraft.get_state_last();
      task_manager.update(state, state_last);
      task_manager.update_idle(state);
      task_manager.update_auto_mc(state, fixed_zero);
    }

  } while (autopilot.update_autopilot(ta, aircraft.get_state(), aircraft.get_state_last()));

  aircraft.Stop();
  autopilot.Stop();

  if (verbose) {
    PrintHelper::taskmanager_print(task_manager, aircraft.get_state());

    const AircraftState state = aircraft.get_state();
    f4 << state.time << " "
       <<  state.location.Longitude << " "
       <<  state.location.Latitude << " "
       <<  state.altitude << "\n";
    f4 << "\n";
    f4.flush();
    task_report(task_manager, "end of task\n");
  }
  wait_prompt();

  time_elapsed = task_manager.get_stats().total.time_elapsed;
  time_planned = task_manager.get_stats().total.time_planned;
  calc_cruise_efficiency = task_manager.get_stats().cruise_efficiency;
  calc_effective_mc = task_manager.get_stats().effective_mc;

  if (verbose)
    distance_counts();

  if (airspace_warnings)
    delete airspace_warnings;

  return true;
}
Beispiel #6
0
 virtual void on_close() {
   wait_prompt();
 }