示例#1
0
static int parameters_endfp(FORMPTR fmp)
{
    int         status;
    char        err_msg[80];
    char        variation_onoff;
    WINDOWPTR   wnp;


    if (error_flag)
        goto END;

    wnp = wn_def(vs_rowq()-1,0,1,vs_colq(),LWAIT,BDR_NULLP);
    wn_up(wnp);
    v_st(" Updating compass parameters, please wait...",wnp);

    status = 0;
    if ((fm_nextitem(fmp) == AC_QUIT) || !fm_isaltered(fmp))
        goto ERROR;             /* avoid writing if nothing changed */


    if (c100_in_superuser_mode()) {
        status = c100_set_who(parameters.serial_nbr,parameters.sftwr_rev,
                              parameters.hrdwr_rev,parameters.unit_type,
                              parameters.cal_date);
        if (status != 0) {
            strcpy(err_msg,"Unable to update serial number.");
            goto ERROR;
        } /* if */
    } /* if */

    variation_onoff = (parameters.true_mag == TRUE_HEADING) ? 't' : 'm';
    status = c100_set_variation_onoff(variation_onoff);
    if (status != 0) {
        strcpy(err_msg,"Unable to update variation flag.");
        goto ERROR;
    } /* if */

    status = c100_set_variation(parameters.variation);
    if (status != 0) {
        strcpy(err_msg,"Unable to update variation.");
        goto ERROR;
    } /* if */

    status = c100_set_a_offset(parameters.a_offset);
    if (status != 0) {
        strcpy(err_msg,"Unable to update A offset.");
        goto ERROR;
    } /* if */

//--------
// setting the message rate to 1 before setting the baud rate will prevent
// problems caused by trying to set conflicting values
//--------
    status = c100_set_msg_rate(1);
    if (status != 0) {
        strcpy(err_msg,"Unable to update message rate.");
        goto ERROR;
    } /* if */

    status = c100_set_baud(parameters.baud_rate);
    if (status != 0) {
        strcpy(err_msg,"Unable to update baud rate.");
        goto ERROR;
    } /* if */

    status = c100_set_msg_rate(parameters.msg_rate);
    if (status != 0) {
        strcpy(err_msg,"Unable to update message rate.");
        goto ERROR;
    } /* if */

    status = c100_set_msg_type(parameters.msg_type);
    if (status != 0) {
        strcpy(err_msg,"Unable to update message type.");
        goto ERROR;
    } /* if */

    status = c100_set_digital_type(parameters.digital_type);
    if (status != 0) {
        strcpy(err_msg,"Unable to update digital output type.");
        goto ERROR;
    } /* if */

    status = c100_set_digital_fmt(parameters.digital_fmt);
    if (status != 0) {
        strcpy(err_msg,"Unable to update digital output format.");
        goto ERROR;
    } /* if */

    status = c100_set_analog_fmt(parameters.analog_fmt);
    if (status != 0) {
        strcpy(err_msg,"Unable to update analog output format.");
        goto ERROR;
    } /* if */

    status = c100_set_damp_type(parameters.damping_type);
    if (status != 0) {
        strcpy(err_msg,"Unable to update damping type.");
        goto ERROR;
    } /* if */

    status = c100_set_damp_rate(parameters.damping_rate);
    if (status != 0) {
        strcpy(err_msg,"Unable to update damping rate.");
        goto ERROR;
    } /* if */

    status = c100_set_msg_units(parameters.msg_units);
    if (status != 0) {
        strcpy(err_msg,"Unable to update analog output format.");
        goto ERROR;
    } /* if */

    if (parameters.powerup_mode == SENDING) {
        status = c100_send_data();
        if (status != 0) {
            strcpy(err_msg,"Unable to turn data messages on.");
        } /* if */
    } /* if */

    c100_zap();                          /* reboot to effect changes */


ERROR:
    if (parameters.powerup_mode == SENDING)
        c100_send_data();

    wn_dn(wnp);
    wn_free(wnp);

    if (status != 0) {                   /* was there an error? */
        strcat(err_msg," ");
        strcat(err_msg,c100_error_name(status));
        msg_window(err_msg);
    } /* if */

END:
    c100_close_channel();
    return(TRUE);

} /* parameters_endfp() */
示例#2
0
int main(int argc, char **argv)
{
  try {

    const unsigned int d = 2;
    const unsigned int pmin = 1;
    const unsigned int pmax = 10;
    const unsigned int np = pmax-pmin+1;
    bool use_pce_quad_points = false;
    bool normalize = false;
    bool sparse_grid = true;
#ifndef HAVE_STOKHOS_DAKOTA
    sparse_grid = false;
#endif
    Teuchos::Array<double> mean(np), mean_st(np), std_dev(np), std_dev_st(np);
    Teuchos::Array<double> pt(np), pt_st(np);

    Teuchos::Array< Teuchos::RCP<const Stokhos::OneDOrthogPolyBasis<int,double> > > bases(d); 
    Teuchos::Array<double> eval_pt(d, 0.5);
    double pt_true;
    
    // Loop over orders
    unsigned int n = 0;
    for (unsigned int p=pmin; p<=pmax; p++) {

      std::cout << "p = " << p << std::endl;
      
      // Create product basis
      for (unsigned int i=0; i<d; i++)
	bases[i] = Teuchos::rcp(new basis_type(p));
      Teuchos::RCP<const Stokhos::CompletePolynomialBasis<int,double> > basis = 
	Teuchos::rcp(new Stokhos::CompletePolynomialBasis<int,double>(bases));
      
      // Create approximation
      Stokhos::OrthogPolyApprox<int,double> x(basis), u(basis), v(basis), 
	w(basis), w2(basis);
      for (unsigned int i=0; i<d; i++) {
	x.term(i, 1) = 1.0;
      }

      double x_pt = x.evaluate(eval_pt);
      pt_true = std::sin(x_pt)/(1.0 + exp(x_pt));
      
      // Quadrature
      Teuchos::RCP<const Stokhos::Quadrature<int,double> > quad;
#ifdef HAVE_STOKHOS_DAKOTA
      if (sparse_grid)
      	quad = 
	  Teuchos::rcp(new Stokhos::SparseGridQuadrature<int,double>(basis, p));
#endif
      if (!sparse_grid)
	quad = 
	  Teuchos::rcp(new Stokhos::TensorProductQuadrature<int,double>(basis));

      // Triple product tensor
      Teuchos::RCP<Stokhos::Sparse3Tensor<int,double> > Cijk =
	basis->computeTripleProductTensor();
      
      // Quadrature expansion
      Stokhos::QuadOrthogPolyExpansion<int,double> quad_exp(basis, Cijk, quad);
      
      // Compute PCE via quadrature expansion
      quad_exp.sin(u,x);
      quad_exp.exp(v,x);
      quad_exp.plusEqual(v, 1.0);
      quad_exp.divide(w,u,v);
	
      // Compute Stieltjes basis
      Teuchos::Array< Teuchos::RCP<const Stokhos::OneDOrthogPolyBasis<int,double> > > st_bases(2);
      Teuchos::RCP<sin_func> sf = Teuchos::rcp(new sin_func(x));
      Teuchos::RCP<exp_func> ef = Teuchos::rcp(new exp_func(x));
      st_bases[0] = 
	Teuchos::rcp(new Stokhos::StieltjesBasis<int,double,sin_func>(
		       p, sf, quad, use_pce_quad_points, normalize));
      st_bases[1] = 
	Teuchos::rcp(new Stokhos::StieltjesBasis<int,double,exp_func>(
		       p, ef, quad, use_pce_quad_points, normalize));
      Teuchos::RCP<const Stokhos::CompletePolynomialBasis<int,double> > 
	st_basis = 
	Teuchos::rcp(new Stokhos::CompletePolynomialBasis<int,double>(st_bases));
      //std::cout << *st_basis << std::endl;

      Stokhos::OrthogPolyApprox<int,double>  u_st(st_basis), v_st(st_basis),
	w_st(st_basis);
      u_st.term(0, 0) = u.mean();
      u_st.term(0, 1) = 1.0;
      v_st.term(0, 0) = v.mean();
      v_st.term(1, 1) = 1.0;
      
      // Triple product tensor
      Teuchos::RCP<Stokhos::Sparse3Tensor<int,double> > st_Cijk =
	st_basis->computeTripleProductTensor();
	
      // Tensor product quadrature
      Teuchos::RCP<const Stokhos::Quadrature<int,double> > st_quad;
      if (!use_pce_quad_points) {
#ifdef HAVE_STOKHOS_DAKOTA
	if (sparse_grid)
	  st_quad = Teuchos::rcp(new Stokhos::SparseGridQuadrature<int,double>(st_basis, p));
#endif
	if (!sparse_grid)
	  st_quad = Teuchos::rcp(new Stokhos::TensorProductQuadrature<int,double>(st_basis));
      }
      else {
	Teuchos::Array<double> st_points_0;
	Teuchos::Array<double> st_weights_0;
	Teuchos::Array< Teuchos::Array<double> > st_values_0;
	st_bases[0]->getQuadPoints(p+1, st_points_0, st_weights_0, st_values_0);
	Teuchos::Array<double> st_points_1;
	Teuchos::Array<double> st_weights_1;
	Teuchos::Array< Teuchos::Array<double> > st_values_1;
	st_bases[1]->getQuadPoints(p+1, st_points_1, st_weights_1, st_values_1);
	Teuchos::RCP< Teuchos::Array< Teuchos::Array<double> > > st_points =
	  Teuchos::rcp(new Teuchos::Array< Teuchos::Array<double> >(st_points_0.size()));
	for (int i=0; i<st_points_0.size(); i++) {
	  (*st_points)[i].resize(2);
	  (*st_points)[i][0] = st_points_0[i];
	  (*st_points)[i][1] = st_points_1[i];
	}
	Teuchos::RCP< Teuchos::Array<double> > st_weights = 
	  Teuchos::rcp(new Teuchos::Array<double>(st_weights_0));
	Teuchos::RCP< const Stokhos::OrthogPolyBasis<int,double> > st_b = 
	  st_basis;
	st_quad = 
	  Teuchos::rcp(new Stokhos::UserDefinedQuadrature<int,double>(st_b,
								      st_points,
								      st_weights));
      }
      
      // Quadrature expansion
      Stokhos::QuadOrthogPolyExpansion<int,double> st_quad_exp(st_basis, 
							       st_Cijk,
							       st_quad);
      
      // Compute w_st = u_st*v_st in Stieltjes basis
      st_quad_exp.divide(w_st, u_st, v_st);
      
      // Project w_st back to original basis
      pce_quad_func st_func(w_st, *st_basis);
      quad_exp.binary_op(st_func, w2, u, v);

      // std::cout.precision(12);
      // std::cout << w;
      // std::cout << w2;
      // std::cout << w_st;
      mean[n] = w.mean();
      mean_st[n] = w2.mean();
      std_dev[n] = w.standard_deviation();
      std_dev_st[n] = w2.standard_deviation();
      pt[n] = w.evaluate(eval_pt);
      pt_st[n] = w2.evaluate(eval_pt);
      n++;
    }

    n = 0;
    int wi=10;
    std::cout << "Statistical error:" << std::endl;
    std::cout << "p  " 
	      << std::setw(wi) << "mean" << "  " 
	      << std::setw(wi) << "mean_st" << "  "
	      << std::setw(wi) << "std_dev" << "  "
	      << std::setw(wi) << "std_dev_st" << "  "
	      << std::setw(wi) << "point" << "  "
	      << std::setw(wi) << "point_st" << std::endl;
    for (unsigned int p=pmin; p<pmax; p++) {
      std::cout.precision(3);
      std::cout.setf(std::ios::scientific);
      std::cout << p << "  " 
		<< std::setw(wi) << rel_err(mean[n], mean[np-1]) << "  "
		<< std::setw(wi) << rel_err(mean_st[n], mean[np-1]) << "  "
		<< std::setw(wi) << rel_err(std_dev[n], std_dev[np-1]) << "  "
		<< std::setw(wi) << rel_err(std_dev_st[n], std_dev[np-1]) 
		<< "  "
		<< std::setw(wi) << rel_err(pt[n], pt_true) << "  "
		<< std::setw(wi) << rel_err(pt_st[n], pt_true) 
		<< std::endl;
      n++;
    }
      
  }
  catch (std::exception& e) {
    std::cout << e.what() << std::endl;
  }
}
示例#3
0
static int parameters_beginfp(FORMPTR fmp)
{
    int         i,status,on_off;
    char        variation_onoff;
    char        err_msg[80];
    DFIELDPTR   fldp;
    WINDOWPTR   wnp;

    error_flag = TRUE;

    memset(&parameters,0,sizeof(parameters));
    for (i = 0; i <= i_maxnum(fmp); i++) {
        fldp = i_numptr(i,fmp);
        fld_blank(fldp,fmp);
    } /* for */

    wnp = wn_def(vs_rowq()-1,0,1,vs_colq(),LWAIT,BDR_NULLP);
    wn_up(wnp);
    v_st(" Reading parameters from compass, please wait...",wnp);

    status = c100_open_channel(dflt_port,dflt_baud);
    if (status != 0) {
        strcpy(err_msg,"Unable to talk to compass.");
        goto ERROR;
    } /* if */

    c100_zap();                  /* re-boot compass to force any changes
                                   made in terminal mode into effect */

    status = c100_halt_data();
    if (status != 0) {
        strcpy(err_msg,"Unable to halt data.");
        goto ERROR;
    } /* if */

    status = c100_get_who(parameters.serial_nbr,&parameters.sftwr_rev,
                          &parameters.hrdwr_rev,parameters.unit_type,
                          parameters.cal_date);
    if (status != 0) {
        strcpy(err_msg,"Unable to read serial number.");
        goto ERROR;
    } /* if */

    status = c100_get_variation_onoff(&variation_onoff);
    if (status != 0) {
        strcpy(err_msg,"Unable to read variation flag.");
        goto ERROR;
    } /* if */
    parameters.true_mag = (variation_onoff == 't') ? TRUE_HEADING : MAG_HEADING;

    status = c100_get_variation(&parameters.variation);
    if (status != 0) {
        strcpy(err_msg,"Unable to read variation.");
        goto ERROR;
    } /* if */

    status = c100_get_a_offset(&parameters.a_offset);
    if (status != 0) {
        strcpy(err_msg,"Unable to read A offset.");
        goto ERROR;
    } /* if */

    status = c100_get_powerup_mode(&parameters.powerup_mode);
    if (status != 0) {
        strcpy(err_msg,"Unable to read power-up mode.");
        goto ERROR;
    } /* if */

    status = c100_get_baud(&parameters.baud_rate);
    if (status != 0) {
        strcpy(err_msg,"Unable to read baud rate.");
        goto ERROR;
    } /* if */

    status = c100_get_msg_rate(&parameters.msg_rate);
    if (status != 0) {
        strcpy(err_msg,"Unable to read message rate.");
        goto ERROR;
    } /* if */

    status = c100_get_msg_type(&parameters.msg_type);
    if (status != 0) {
        strcpy(err_msg,"Unable to read message type.");
        goto ERROR;
    } /* if */

    status = c100_get_damp_type(&parameters.damping_type);
    if (status != 0) {
        strcpy(err_msg,"Unable to read damping type.");
        goto ERROR;
    } /* if */

    status = c100_get_damp_rate(&parameters.damping_rate);
    if (status != 0) {
        strcpy(err_msg,"Unable to read damping rate.");
        goto ERROR;
    } /* if */

    status = c100_get_digital_type(&parameters.digital_type);
    if (status != 0) {
        strcpy(err_msg,"Unable to read digital output type.");
        goto ERROR;
    } /* if */

    status = c100_get_digital_fmt(&parameters.digital_fmt);
    if (status != 0) {
        strcpy(err_msg,"Unable to read digital output format.");
        goto ERROR;
    } /* if */

    status = c100_get_analog_fmt(&parameters.analog_fmt);
    if (status != 0) {
        strcpy(err_msg,"Unable to read analog output format.");
        goto ERROR;
    } /* if */

    status = c100_get_msg_units(&parameters.msg_units);
    if (status != 0) {
        strcpy(err_msg,"Unable to read analog output format.");
        goto ERROR;
    } /* if */


    /*--- if in SUPERUSER mode, allow access to certain fields ---*/
    on_off = (c100_in_superuser_mode() ? OFF : ON);

    fldp = i_namptr("serial_nbr",fmp);
    sf_opt(SKIP,on_off,fldp);

    fldp = i_namptr("unit_type",fmp);
    sf_opt(SKIP,on_off,fldp);

    fldp = i_namptr("cal_date",fmp);
    sf_opt(SKIP,on_off,fldp);

    fldp = i_namptr("hardware_rev",fmp);
    sf_opt(SKIP,on_off,fldp);

    fldp = i_namptr("software_rev",fmp);
    sf_opt(SKIP,on_off,fldp);

    error_flag = FALSE;

ERROR:
    wn_dn(wnp);
    wn_free(wnp);

    if (status != 0) {      /* was there an error? */
        strcat(err_msg," ");
        strcat(err_msg,c100_error_name(status));
        msg_window(err_msg);
        sfm_nextitem(AC_EXIT,fmp);
    } else {
        fm_updflds(fmp);
    } /* if */

    return(TRUE);

} /* parameters_beginfp() */
示例#4
0
int eight_point_cal(FORMPTR fmp)
{
WINDOWPTR   wnp;
int         status,done;
int         score,count,environment;
int         space_pressed;
double      heading;
char        cal_msg[81];
char        serial_nbr[8],unit_type[5],cal_date[9];
char        hardware_rev,software_rev;


    latt_rpl(L_BLINK,NORMAL|BLINK,BLUE|BLINK,WHITE,LATT_SYS);
    latt_rpl(L_ERROR,REVERSE,     RED|BLINK, WHITE,LATT_SYS);

    wnp = wn_def(CENTER_WN,CENTER_WN,12,60,LREVERSE,BDR_DLNP);
    sw_shad(TRANSPARENT,LSHADOW,BOTTOMRIGHT,wnp);
    sw_updnfp(wn_expset,wn_expunset,wnp);

    wn_up(wnp);

    status = c100_open_channel(dflt_port,dflt_baud);
    if (status != 0) {
        v_printf(wnp,"Error: unable to open compass channel - %s",
                     c100_error_name(status));
        goto END;
    } /* if */

    status = c100_halt_data();
    if (status != 0) {
        v_printf(wnp,"Error: unable to halt data messages - %s",
                     c100_error_name(status));
        goto END;
    } /* if */

    status = c100_get_who(serial_nbr,&software_rev,&hardware_rev,
                                      unit_type,cal_date);
    if (status != 0) {
        v_printf(wnp,"Error: unable to read software revision level.  %s",
                 c100_error_name(status));
        goto END;
    } /* if */


    /*--- Start 8-point Calibration --*/
    sw_title("[Press SPACE when done...]",L_BLINK,BOTTOMCENTER,wnp);
    v_bdr(BDR_DLNP,wnp);
    v_st("Eight-Point Calibration started!\n",wnp);

   done = FALSE;
   do {

      status = c100_cal_mode(FORCED_EIGHT_POINT_CAL,&heading,cal_msg);
      switch (status) {
         case OK:
            v_printf(wnp,"\nPosition compass to ñ%.0fø...",heading);
            break;

         case DONE:
            v_st("\n\n8-point calibration complete!",wnp);

            if (dflt_baud <= 1200)
                delay(3000);

            if (software_rev >= 'C') {
               status = c100_get_cal_score(LONG_SCORE,&score,&count,
                                           &environment);
               if (status != 0) {
                  v_printf(wnp,"\nError: unable to read cal score - %s",
                           c100_error_name(status));
               } else {
                  v_printf(wnp,"\nCal score = %d, environment = %d, "
                           "count = %d.",score,environment,count);
                  if (environment < 5)
                     v_st("\nBad magnetic environment.  Consider re-"
                          "locating and re-calibrating the compass.",wnp);
               } /* if */
            } else {
               status = c100_get_cal_score(SHORT_SCORE,&score,&count,NULL);
               if (status != 0) {
                  v_printf(wnp,"\nError: unable to read cal score - %s",
                           c100_error_name(status));
               } else {
                  v_printf(wnp,"\nCal score = %d, count = %d.",
                           score,count);
               } /* if */
            } /* if */

            if (score < 7)
               v_statt("\nThis calibration may NOT be accurate.",
                       L_ERROR,wnp);
            done = TRUE;
            break;

         case MSG_NAKKED:
            v_printf(wnp,"\n\nError: %s",cal_msg);
            if (software_rev < 'C')
               c100_zap();
            else
               c100_cal_mode(ABORT_CAL,NULL,NULL);
            done = TRUE;
            break;

         default:
            v_printf(wnp,"\n\nError: unable to complete calibration - %s",
                     c100_error_name(status));
            if (software_rev < 'C')
               c100_zap();
            else
               c100_cal_mode(ABORT_CAL,NULL,NULL);
            done = TRUE;
            break;

      } /* switch */

      if (!done) {
         space_pressed = FALSE;
         do {
            switch (ki()) {
               case KEY_ESC:
                  if (continue_abort("ESC pressed!") == ABORT) {
                     if (software_rev < 'C')
                        c100_zap();
                     else
                        c100_cal_mode(ABORT_CAL,NULL,NULL);
                     v_st("\n8-point calibration aborted by user!",wnp);
                     goto END;
                  } /* if */
                  break;

               case KEY_SPACE:
                  space_pressed = TRUE;
                  break;

               default:
                  break;

            } /* switch */
         } while (!space_pressed);
      } /* if */

    } while (!done);


END:
//  if (c100_mode == SENDING) {
//     c100_send_data();
//  } /* if */

    sw_title("[Press any key...]",L_BLINK,BOTTOMCENTER,wnp);
    v_bdr(BDR_DLNP,wnp);
    beep_vv(BPMEDIUM,BPLOW);
    beep_vv(BPMEDIUM,BPMIDDLE);
    beep_vv(BPMEDIUM,BPHIGH);
    flush_keybuf();
    ki();

    c100_close_channel();
    wn_dn(wnp);
    wn_free(wnp);

    return(SAMELEVEL);

} /* eight_point_cal() */
示例#5
0
int circular_cal(FORMPTR fmp)
{
WINDOWPTR       wnp;
int             status,done;
int             score,count,environment;
int             row,col;
int             state;
char            cal_msg[81];
char            serial_nbr[8],unit_type[5],cal_date[9];
char            hardware_rev,software_rev;


   latt_rpl(L_BLINK,NORMAL|BLINK,BLUE|BLINK,WHITE,LATT_SYS);
   latt_rpl(L_ERROR,REVERSE,     RED|BLINK, WHITE,LATT_SYS);

   wnp = wn_def(CENTER_WN,CENTER_WN,12,60,LREVERSE,BDR_DLNP);
   sw_shad(TRANSPARENT,LSHADOW,BOTTOMRIGHT,wnp);
   sw_updnfp(wn_expset,wn_expunset,wnp);

   wn_up(wnp);

   status = c100_open_channel(dflt_port,dflt_baud);
   if (status != 0) {
      v_printf(wnp,"Error: unable to open compass channel - %s",
               c100_error_name(status));
      goto END;
   } /* if */

   status = c100_halt_data();
   if (status != 0) {
      v_printf(wnp,"Error: unable to halt data messages - %s",
               c100_error_name(status));
      goto END;
   } /* if */

   status = c100_get_who(serial_nbr,&software_rev,&hardware_rev,
                         unit_type,cal_date);
   if (status != 0) {
      v_printf(wnp,"Error: unable to read software revision level.  %s",
               c100_error_name(status));
      goto END;
   } /* if */
   if (software_rev < 'C') {
      v_st("\nCircular Cal requires software revision C or higher.",wnp);
      v_printf(wnp,"\nThis C100 has rev %c software.",software_rev);
      v_st("\n\nCalibration aborted.",wnp);
      goto END;
   } /* if */



//-----------
//   Start Circular Calibration
//-----------
   status = c100_cal_mode(CIRCULAR_CAL,NULL,cal_msg);
   if (status != 0) {
      v_printf(wnp,"Error: unable to start circular cal. %s.",
               c100_error_name(status));
      goto END;
   } /* if */

   v_st("Circular calibration started.\n\n",wnp);
   v_st("Turn compass SLOWLY in a circle...",wnp);
   row = wnp->r;
   col = wnp->c;
   v_statt("Collecting",L_BLINK,wnp);
   csr_mvwn(row,col,wnp);

   state = COLLECTING;
   done = FALSE;
   do {

      if (ki_chk()) {
         if (ki() == KEY_ESC) {
            if (continue_abort("ESC pressed!") == ABORT) {
               v_st("ABORTED    ",wnp);
               c100_cal_mode(ABORT_CAL,NULL,NULL);
               v_st("\nCircular calibration aborted by user!",wnp);
               goto END;
            } /* if */
         } /* if */
      } /* if */

      status = c100_check_for_ack(cal_msg);
      switch (status) {
         case ACK_RECEIVED:
            if (state == COLLECTING) {
               state = CALCULATING;
               v_statt("Calculating",L_BLINK,wnp);
               csr_mvwn(row,col,wnp);
            } else {
               v_st("Finished    ",wnp);
               v_st("\n\nCircular calibration complete!",wnp);
               if (software_rev >= 'C') {
                  if (dflt_baud <= 1200)
                     delay(3000);

                  status = c100_get_cal_score(LONG_SCORE,&score,&count,
                                              &environment);
                  if (status != 0) {
                     v_printf(wnp,"\nError: unable to read cal score - %s",
                              c100_error_name(status));
                  } else {
                     v_printf(wnp,"\nCal score = %d, environment = %d, "
                              "count = %d.",score,environment,count);
                     if (environment < 5)
                        v_st("\nBad magnetic environment.  Consider re-"
                             "locating and re-calibrating the compass.",wnp);
                  } /* if */

               } else {

                  status = c100_get_cal_score(SHORT_SCORE,&score,&count,NULL);
                  if (status != 0) {
                     v_printf(wnp,"\nError: unable to read cal score - %s",
                              c100_error_name(status));
                  } else {
                     v_printf(wnp,"\nCal score = %d, count = %d.",
                              score,count);
                  } /* if */
               } /* if */

               if (score < 7)
                  v_statt("\nThis calibration may NOT be accurate!",
                          L_ERROR,wnp);
               done = TRUE;
            } /* if */
            break;


         case NAK_RECEIVED:
            v_st("ABORTED    ",wnp);
            v_printf(wnp,"\nError: unable to complete calibration - %s",
                     cal_msg);
            c100_cal_mode(ABORT_CAL,NULL,NULL);
            done = TRUE;
            break;


         default:
            break;

      } /* switch */

   } while (!done);


END:
   if (c100_mode == SENDING) {
      c100_send_data();
   } /* if */

   sw_title("[Press any key...]",L_BLINK,BOTTOMCENTER,wnp);
   v_bdr(BDR_DLNP,wnp);
   beep_vv(BPMEDIUM,BPLOW);
   beep_vv(BPMEDIUM,BPMIDDLE);
   beep_vv(BPMEDIUM,BPHIGH);
   flush_keybuf();
   ki();

   c100_close_channel();
   wn_dn(wnp);
   wn_free(wnp);

   return(SAMELEVEL);

} /* circular_cal() */
示例#6
0
/*----------------------------------------------------------------------------*/
int three_point_cal(FORMPTR fmp)
{
WINDOWPTR       wnp;
DFORMPTR        dfmp;
DFIELDPTR       fldp;
int             status,done;
int             score,count;
double          heading;
char            cal_msg[81];
char            serial_nbr[8],unit_type[5],cal_date[9];
char            hardware_rev,software_rev;


   latt_rpl(L_BLINK,NORMAL|BLINK,BLUE|BLINK,WHITE,LATT_SYS);
   latt_rpl(L_ERROR,REVERSE,     RED|BLINK, WHITE,LATT_SYS);

   wnp = wn_def(CENTER_WN,CENTER_WN,12,60,LREVERSE,BDR_DLNP);
   sw_shad(TRANSPARENT,LSHADOW,BOTTOMRIGHT,wnp);
   sw_updnfp(wn_expset,wn_expunset,wnp);

   wn_up(wnp);

   dfmp = fm_def(12,CENTER_WN,3,25,LNORMAL,BDR_DLNP);
   sw_shad(TRANSPARENT,LSHADOW,BOTTOMRIGHT,dfmp->wnp);
   sw_updnfp(wn_expset,wn_expunset,dfmp->wnp);
   fldp = fld_def(0,1,"Actual Heading: ",FADJACENT,"###@#",
                  F_DOUBLE,&heading,dfmp);
   sf_msg("Enter actual compass heading and press ENTER.",fldp);

   status = c100_open_channel(dflt_port,dflt_baud);
   if (status != 0) {
      v_printf(wnp,"Error: unable to open compass channel - %s",
               c100_error_name(status));
      goto END;
   } /* if */

   status = c100_halt_data();
   if (status != 0) {
      v_printf(wnp,"Error: unable to halt data messages - %s",
               c100_error_name(status));
      goto END;
   } /* if */

   status = c100_get_who(serial_nbr,&software_rev,&hardware_rev,
                         unit_type,cal_date);
   if (status != 0) {
      v_printf(wnp,"Error: unable to read software revision level.  %s",
               c100_error_name(status));
      goto END;
   } /* if */
   if (software_rev < 'C') {
      v_st("\nThree Point Cal requires software revision C or higher.",wnp);
      v_printf(wnp,"\nThis C100 has rev %c software.",software_rev);
      v_st("\n\nCalibration aborted.",wnp);
      goto END;
   } /* if */

   v_st("Three-Point Calibration started.\n",wnp);

   done    = FALSE;
   heading = 0.0;

   while (!done) {
      status = c100_cal_mode(THREE_POINT_CAL,&heading,cal_msg);

      switch (status) {
         case OK:
            v_printf(wnp,"\nPosition compass to about %.0fø and enter actual"
                     " heading.",heading);
            if (fm_proc(0,dfmp) != AC_EXIT) {
               c100_cal_mode(ABORT_CAL,NULL,NULL);
               v_st("\n\nCalibration aborted by user.",wnp);
               done = TRUE;
            } /* if */
            break;


         case DONE:
            v_st("\n\nThree-Point calibration complete!",wnp);
            status = c100_get_cal_score(SHORT_SCORE,&score,&count,NULL);
            if (status != 0)
               v_printf(wnp,"\nError: unable to read cal score - %s",
                        c100_error_name(status));
            else
               v_printf(wnp,"\nCal score = %d, count = %d.",
                        score,count);
            done = TRUE;
            break;


         case MSG_NAKKED:
            v_printf(wnp,"\n\nError: %s",cal_msg);
            c100_cal_mode(ABORT_CAL,NULL,NULL);
            done = TRUE;
            break;


         default:
            v_printf(wnp,"\n\nError: unable to complete calibration - %s",
                     c100_error_name(status));
            c100_cal_mode(ABORT_CAL,NULL,NULL);
            done = TRUE;
            break;

      } /* switch */

   } /* while */


END:
   if (c100_mode == SENDING) {
      c100_send_data();
   } /* if */

   sw_title("[Press any key...]",L_BLINK,BOTTOMCENTER,wnp);
   v_bdr(BDR_DLNP,wnp);
   beep_vv(BPMEDIUM,BPLOW);
   beep_vv(BPMEDIUM,BPMIDDLE);
   beep_vv(BPMEDIUM,BPHIGH);
   flush_keybuf();
   ki();

   c100_close_channel();
   fm_free(dfmp);
   wn_dn(wnp);
   wn_free(wnp);

   return(SAMELEVEL);


} /* three_point_cal() */
示例#7
0
int main(int argc, char **argv)
{
  try {

    const unsigned int d = 2;
    const unsigned int p = 5;

    // Create product basis
    Teuchos::Array< Teuchos::RCP<const Stokhos::OneDOrthogPolyBasis<int,double> > > bases(d);
    for (unsigned int i=0; i<d; i++)
      bases[i] = Teuchos::rcp(new basis_type(p));
    Teuchos::RCP<const Stokhos::CompletePolynomialBasis<int,double> > basis = 
      Teuchos::rcp(new Stokhos::CompletePolynomialBasis<int,double>(bases));

    // Create approximation
    Stokhos::OrthogPolyApprox<int,double> x(basis), u(basis), v(basis), 
      w(basis), w2(basis), w3(basis);
    for (unsigned int i=0; i<d; i++) {
      x.term(i, 1) = 1.0;
    }

    // Tensor product quadrature
    Teuchos::RCP<const Stokhos::Quadrature<int,double> > quad = 
      Teuchos::rcp(new Stokhos::TensorProductQuadrature<int,double>(basis));

    // Triple product tensor
    Teuchos::RCP<Stokhos::Sparse3Tensor<int,double> > Cijk =
      basis->computeTripleProductTensor();
    
    // Quadrature expansion
    Stokhos::QuadOrthogPolyExpansion<int,double> quad_exp(basis, Cijk, quad);
    
    // Compute PCE via quadrature expansion
    quad_exp.sin(u,x);
    quad_exp.exp(v,x);
    quad_exp.times(w,v,u);
    
    // Compute tensor product Stieltjes basis for u and v
    Teuchos::Array< Teuchos::RCP<const Stokhos::OneDOrthogPolyBasis<int,double> > > st_bases(2);
    st_bases[0] = 
      Teuchos::rcp(new Stokhos::StieltjesPCEBasis<int,double>(
		     p, Teuchos::rcp(&u,false), quad, true));
    st_bases[1] = 
      Teuchos::rcp(new Stokhos::StieltjesPCEBasis<int,double>(
		     p, Teuchos::rcp(&v,false), quad, true));
    Teuchos::RCP<const Stokhos::CompletePolynomialBasis<int,double> > st_basis =
      Teuchos::rcp(new Stokhos::CompletePolynomialBasis<int,double>(st_bases));
    Stokhos::OrthogPolyApprox<int,double>  u_st(st_basis), v_st(st_basis), 
      w_st(st_basis);
    u_st.term(0, 0) = u.mean();
    u_st.term(0, 1) = 1.0;
    v_st.term(0, 0) = v.mean();
    v_st.term(1, 1) = 1.0;
    
    // Use Gram-Schmidt to orthogonalize Stieltjes basis of u and v
    Teuchos::Array<double> st_points_0;
    Teuchos::Array<double> st_weights_0;
    Teuchos::Array< Teuchos::Array<double> > st_values_0;
    st_bases[0]->getQuadPoints(p+1, st_points_0, st_weights_0, st_values_0);
    Teuchos::Array<double> st_points_1;
    Teuchos::Array<double> st_weights_1;
    Teuchos::Array< Teuchos::Array<double> > st_values_1;
    st_bases[1]->getQuadPoints(p+1, st_points_1, st_weights_1, st_values_1);
    Teuchos::Array< Teuchos::Array<double> > st_points(st_points_0.size());
    for (int i=0; i<st_points_0.size(); i++) {
      st_points[i].resize(2);
      st_points[i][0] = st_points_0[i];
      st_points[i][1] = st_points_1[i];
    }
    Teuchos::Array<double> st_weights = st_weights_0;
    
    Teuchos::RCP< Stokhos::GramSchmidtBasis<int,double> > gs_basis = 
      Teuchos::rcp(new Stokhos::GramSchmidtBasis<int,double>(st_basis,
							     st_points,
							     st_weights,
							     1e-15));
    
    // Create quadrature for Gram-Schmidt basis using quad points and 
    // and weights from original basis mapped to Stieljtes basis
    Teuchos::RCP< const Teuchos::Array< Teuchos::Array<double> > > points =
      Teuchos::rcp(&st_points,false);
    Teuchos::RCP< const Teuchos::Array<double> > weights =
      Teuchos::rcp(&st_weights,false);
    Teuchos::RCP<const Stokhos::Quadrature<int,double> > gs_quad = 
      Teuchos::rcp(new Stokhos::UserDefinedQuadrature<int,double>(gs_basis,
								  points,
								  weights));

    // Triple product tensor
    Teuchos::RCP<Stokhos::Sparse3Tensor<int,double> > gs_Cijk =
      gs_basis->computeTripleProductTensor();
    
    // Gram-Schmidt quadrature expansion
    Stokhos::QuadOrthogPolyExpansion<int,double> gs_quad_exp(gs_basis, 
							     gs_Cijk,
							     gs_quad);
    
    Stokhos::OrthogPolyApprox<int,double>  u_gs(gs_basis), v_gs(gs_basis), 
      w_gs(gs_basis);
    
    // Map expansion in Stieltjes basis to Gram-Schmidt basis
    gs_basis->transformCoeffs(u_st.coeff(), u_gs.coeff());
    gs_basis->transformCoeffs(v_st.coeff(), v_gs.coeff());
    
    // Compute w_gs = u_gs*v_gs in Gram-Schmidt basis
    gs_quad_exp.times(w_gs, u_gs, v_gs);
    
    // Project w_gs back to original basis
    pce_quad_func gs_func(w_gs, *gs_basis);
    quad_exp.binary_op(gs_func, w2, u, v);

    // Triple product tensor
    Teuchos::RCP<Stokhos::Sparse3Tensor<int,double> > st_Cijk =
      st_basis->computeTripleProductTensor();

    // Stieltjes quadrature expansion
    Teuchos::RCP<const Stokhos::Quadrature<int,double> > st_quad = 
      Teuchos::rcp(new Stokhos::UserDefinedQuadrature<int,double>(st_basis,
								  points,
								  weights));
    Stokhos::QuadOrthogPolyExpansion<int,double> st_quad_exp(st_basis,
							     st_Cijk,
							     st_quad);
    
    // Compute w_st = u_st*v_st in Stieltjes basis
    st_quad_exp.times(w_st, u_st, v_st);
    
    // Project w_st back to original basis
    pce_quad_func st_func(w_st, *st_basis);
    quad_exp.binary_op(st_func, w3, u, v);
    
    std::cout.precision(12);
    std::cout << "w = " << std::endl << w;
    std::cout << "w2 = " << std::endl << w2;
    std::cout << "w3 = " << std::endl << w3;
    std::cout << "w_gs = " << std::endl << w_gs;
    std::cout << "w_st = " << std::endl << w_st;
    
    std::cout.setf(std::ios::scientific);
    std::cout << "w.mean()       = " << w.mean() << std::endl
	      << "w2.mean()      = " << w2.mean() << std::endl
	      << "w3.mean()      = " << w3.mean() << std::endl
	      << "w_gs.mean()    = " << w_gs.mean() << std::endl
	      << "w_st.mean()    = " << w_st.mean() << std::endl
	      << "w.std_dev()    = " << w.standard_deviation() << std::endl
	      << "w2.std_dev()   = " << w2.standard_deviation() << std::endl
	      << "w3.std_dev()   = " << w3.standard_deviation() << std::endl
	      << "w_gs.std_dev() = " << w_gs.standard_deviation() << std::endl
	      << "w_st.std_dev() = " << w_st.standard_deviation() << std::endl;
  }
  catch (std::exception& e) {
    std::cout << e.what() << std::endl;
  }
}