Example #1
0
void DoSched(void)
{
  time_t t;
  double dt;
  double d_lon;
  double d_lat;
  static int last_is = -1;
  static int last_s = -1;
  static int last_l = -1;
  static int last_slot = -1;
  static int last_up = -1;
  int i_sched, i_point;
  int i, index;
  struct ScheduleType *S = &_S[CommandData.sucks][CommandData.lat_range];
  struct ScheduleEvent event;

  
  i_point = GETREADINDEX(point_index);
  d_lat = PointingData[i_point].lat - NOMINAL_LATITUDE;
  
  if (last_up != CommandData.uplink_sched) {
    last_up = CommandData.uplink_sched;
    last_is = -1;
  }
  
  // Check for invalid uplinked schedule file
  if (CommandData.uplink_sched) {
    if (Uplink_S == 0) {
      CommandData.uplink_sched = 0;
    } else if (Uplink_S->n_sched<2) { 
      CommandData.uplink_sched = 0;
    }
  }
  
  if (CommandData.uplink_sched) {
    if (last_slot != CommandData.slot_sched) {
      last_slot = CommandData.slot_sched;
      last_is = -1;
    }    
    S = Uplink_S;
  } else {
    /* check our latitude band */
    if (CommandData.lat_range == 2) { /* southern band */
      if (d_lat > -(LATITUDE_BAND / 2) + LATITUDE_OVERLAP) {
        blast_info("Scheduler: Entering middle latitude band. (%g)\n", d_lat);
        CommandData.lat_range = 1;
      }
    } else if (CommandData.lat_range == 1) { /* middle band */
      if (d_lat < -(LATITUDE_BAND / 2)) {
        blast_info("Scheduler: Entering southern latitude band. (%g)\n", d_lat);
        CommandData.lat_range = 2;
      } else if (d_lat > (LATITUDE_BAND / 2)) {
        blast_info("Scheduler: Entering northern latitude band. (%g)\n", d_lat);
        CommandData.lat_range = 0;
      }
    } else if (CommandData.lat_range == 0) { /* norhtern band */
      if (d_lat < (LATITUDE_BAND / 2) - LATITUDE_OVERLAP) {
        blast_info("Scheduler: Entering middle latitude band. (%g)\n", d_lat);
        CommandData.lat_range = 1;
      }
    } else {
      blast_warn("Scheduler: Unexpected latitude band: %i\n",
              CommandData.lat_range);
      CommandData.lat_range = 1;
    }
    
    S = &_S[CommandData.sucks][CommandData.lat_range];
    
    /* check to see if we've changed schedule files */
    if (last_l != CommandData.lat_range) {
      last_is = -1;
      last_l = CommandData.lat_range;
    }
    
    if (last_s != CommandData.sucks) {
      last_is = -1;
      last_s = CommandData.sucks;
    }  
  }
  

  /* no schedule file case */
  if (S->n_sched < 1) {
    doing_schedule = 0;
    return;
  }

/*************************************************************/
  /** find local comoving siderial date (in siderial seconds) **/
  dt = (PointingData[i_point].t - S->t0) * 1.002737909; /*Ref Siderial Time */
  d_lon = PointingData[i_point].lon;

  while (d_lon < -170)
    d_lon += 360.0;
  while (d_lon >= 190.0)
    d_lon -= 360.0;

  dt -= ((d_lon) * 3600.00 * 24.00 / 360.0); /* add longitude correction */

  sched_lst = dt;
  
  t = PointingData[i_point].t;
  if (t < CommandData.pointing_mode.t) {
    doing_schedule = 0;
    last_is = -1;
    return;
  }

  if (PointingData[i_point].at_float && !CommandData.at_float) {
    bputs(info, "Scheduler: *** Executing initial float commands. ***\n");
    /* el on */
    event.command = el_on;
    event.is_multi = 0;
    ScheduledCommand(&event);
    /* unlock */
    event.command = unlock;
    ScheduledCommand(&event);
    /* az on */
    event.command = az_on;
    ScheduledCommand(&event);
    /* point antisolar */
    event.command = antisun;
    ScheduledCommand(&event);
    /* enable hwpr autostepping */
    event.command = hwpr_step_on;
    ScheduledCommand(&event);
    /* pot_valve_open */
    event.command = pot_valve_open;
    ScheduledCommand(&event);
    event.command = pot_valve_on;
    ScheduledCommand(&event);
    /* turn off lock motor hold current */
    event.command = lock_i;
    event.is_multi = 1;
    event.ivalues[0] = 50;
    event.ivalues[1] = 0;
    ScheduledCommand(&event);
    /* fridge autocylce system active */
    event.command = auto_cycle;
    event.is_multi = 0;
    ScheduledCommand(&event);

    // out of sched mode for a while
    CommandData.pointing_mode.t = t + 30;
    doing_schedule = 0;

    /* Remember we're at float */
    CommandData.at_float = 1;
    bputs(info, "Scheduler: *** Initial float commands complete. ***\n");
    return;
  }

  /******************/
  /** find i_sched **/
  i_sched = last_is;
  if (i_sched < 0)
    i_sched = 0;
  while ((i_sched < S->n_sched - 1) && (dt > S->event[i_sched].t))
    i_sched++;
  while ((i_sched > 0) && (dt < S->event[i_sched].t))
    i_sched--;

  /******************************/
  /** Execute initial controls **/
  if (!doing_schedule) {
    bputs(info, "Scheduler: *** Entering schedule file mode.  ***\n"
        "Scheduler: *** Running initial schedule controls.  ***\n");
    /* bias fixed */
    event.command = fixed;
    event.is_multi = 0;
    //ScheduledCommand(&event);
    /* cal repeat */
    event.command = cal_repeat;
    event.is_multi = 1;
    event.ivalues[0] = 130; /* ms */
    event.ivalues[1] = 600; /* s */
    //ScheduledCommand(&event);

    bputs(info, "Scheduler: *** Searching for current pointing mode. ***\n");

    /* find last pointing command */
    for (i = i_sched; i >= 0; --i)
      if (S->event[i].is_multi) {
        index = MIndex(S->event[i].command);
        if (mcommands[index].group & GR_POINT)
          break;
      } else {
        index = SIndex(S->event[i].command);
        if (scommands[index].group & GR_POINT)
          break;
      }

    if (i == -1) {
      bputs(warning,
          "Scheduler: *** No previous pointing mode, turning antisolar. ***\n");
      event.command = antisun;
      event.is_multi = 0;
      ScheduledCommand(&event);
    } else if (i == i_sched) {
      bputs(info, "Scheduler: *** Pointing mode change imminent. ***\n");
    } else {
      blast_info(          "Scheduler: *** Recovering scheduled pointing mode (event %i). ***\n",
          i);
      ScheduledCommand(&S->event[i]);
    }
  }
  doing_schedule = 1;

  /*******************************/
  /** Execute scheduled command **/
  dt /= 3600;
  if (i_sched != last_is) {
    blast_info("Scheduler: Submitting event %i from %s to command "
        "subsystem (LST = %i/%f)", i_sched,
        filename[CommandData.sucks][CommandData.lat_range], (int)(dt / 24),
        fmod(dt, 24));
    ScheduledCommand(&S->event[i_sched]);
  }
  last_is = i_sched;
}
Example #2
0
void entity::add_scheduled_command(int cycle, variant cmd)
{
	scheduled_commands_.push_back(ScheduledCommand(cycle, cmd));
}
Example #3
0
void entity::add_scheduled_command(int cycle, variant cmd)
{
	scheduled_commands_.push_back(ScheduledCommand(cycle, cmd));
	std::sort(scheduled_commands_.begin(), scheduled_commands_.end());
}