Exemple #1
0
/**
 *	@brief Calculate the angle and magnitude of a joystick.
 *
 *	@param js	[out] Pointer to a joystick_t structure.
 *	@param x	The raw x-axis value.
 *	@param y	The raw y-axis value.
 */
void calc_joystick_state(struct joystick_t* js, float x, float y) {
	float rx, ry, ang;

	/*
	 *	Since the joystick center may not be exactly:
	 *		(min + max) / 2
	 *	Then the range from the min to the center and the center to the max
	 *	may be different.
	 *	Because of this, depending on if the current x or y value is greater
	 *	or less than the assoicated axis center value, it needs to be interpolated
	 *	between the center and the minimum or maxmimum rather than between
	 *	the minimum and maximum.
	 *
	 *	So we have something like this:
	 *		(x min) [-1] ---------*------ [0] (x center) [0] -------- [1] (x max)
	 *	Where the * is the current x value.
	 *	The range is therefore -1 to 1, 0 being the exact center rather than
	 *	the middle of min and max.
	 */
   rx = applyCalibration(x, js->min.x, js->max.x, js->center.x);
   ry = applyCalibration(y, js->min.y, js->max.y, js->center.y);

	/* calculate the joystick angle and magnitude */
	ang = RAD_TO_DEGREE(atan2f(ry, rx));
	js->mag = sqrtf((rx * rx) + (ry * ry));
	js->ang = ang + 180.0f;
}
  void AbsoluteQuantitation::calculateBiasAndR(
    const std::vector<AbsoluteQuantitationStandards::featureConcentration> & component_concentrations,
    const String & feature_name,
    const String & transformation_model,
    const Param & transformation_model_params,
    std::vector<double> & biases,
    double & correlation_coefficient)
  {
    // reset biases
    biases.clear();

    // extract out the calibration points
    std::vector<double> concentration_ratios, feature_amounts_ratios;
    TransformationModel::DataPoints data;
    TransformationModel::DataPoint point;
    for (size_t i = 0; i < component_concentrations.size(); ++i)
    {

      // calculate the actual and calculated concentration ratios
      double calculated_concentration_ratio = applyCalibration(component_concentrations[i].feature,
        component_concentrations[i].IS_feature,
        feature_name,
        transformation_model,
        transformation_model_params);

      double actual_concentration_ratio = component_concentrations[i].actual_concentration/
        component_concentrations[i].IS_actual_concentration;
      concentration_ratios.push_back(component_concentrations[i].actual_concentration);

      // extract out the feature amount ratios
      double feature_amount_ratio = calculateRatio(component_concentrations[i].feature,
        component_concentrations[i].IS_feature,
        feature_name)/component_concentrations[i].dilution_factor;
      feature_amounts_ratios.push_back(feature_amount_ratio);

      // calculate the bias
      double bias = calculateBias(actual_concentration_ratio, calculated_concentration_ratio);
      biases.push_back(bias);

      point.first = actual_concentration_ratio;
      point.second = feature_amount_ratio;
      data.push_back(point);
    }

    // apply weighting to the feature amounts and actual concentration ratios
    TransformationModel tm(data, transformation_model_params);
    tm.weightData(data);
    std::vector<double> concentration_ratios_weighted, feature_amounts_ratios_weighted;
    for (size_t i = 0; i < data.size(); ++i)
    {
      concentration_ratios_weighted.push_back(data[i].first);
      feature_amounts_ratios_weighted.push_back(data[i].second);
    }

    // calculate the R2 (R2 = Pearson_R^2)
    correlation_coefficient = Math::pearsonCorrelationCoefficient(
      concentration_ratios_weighted.begin(), concentration_ratios_weighted.begin() + concentration_ratios_weighted.size(),
      feature_amounts_ratios_weighted.begin(), feature_amounts_ratios_weighted.begin() + feature_amounts_ratios_weighted.size()
    );
  }
/*
 * getOrientationVector method:
 * store calibrated and scaled accelerometer data(x,y,z) in '&data' parameter
 */
void HMC5883L::getMagVector(float (&data)[3])
{
	read();
	applyCalibration();
	scaleGain();

	memcpy(data, magVector, sizeof(data));
}
Exemple #4
0
CompassVec Compass::getMeasurements()
{
  byte buf[6];

  //writeReg(2, 1);
  //delay(10);

  readRegs(COMPASS_REG_DATA_OUT_X, 6, buf);

  float x, y, z;
  x = (float)makeI16(buf[0], buf[1]);
  z = (float)makeI16(buf[2], buf[3]);
  y = (float)makeI16(buf[4], buf[5]);

  CompassVec v(x, y, z);
  return applyCalibration(v);
}
Exemple #5
0
void main()
{
    byte writeIndex = 0;
    byte i;
    long l;
    TRISB = 0xFFFF;         /* All inputs */

    LAT_BATT1_CTL = BATT_ENABLE;
    LAT_BATT2_CTL = BATT_ENABLE;
    LAT_BATT3_CTL = BATT_ENABLE;
    LAT_BATT4_CTL = BATT_ENABLE;
#ifdef BBR2
    LAT_BATT5_CTL = ~BATT_ENABLE;
#else
    LAT_BATT5_CTL = BATT_ENABLE;
#endif
    LAT_BATT6_CTL = BATT_ENABLE;

    TRIS_BATT1_CTL = TRIS_OUT;
    TRIS_BATT2_CTL = TRIS_OUT;
    TRIS_BATT3_CTL = TRIS_OUT;
    TRIS_BATT4_CTL = TRIS_OUT;
#ifdef BBR2
    TRIS_BATT5_CTL = TRIS_IN;
#else
    TRIS_BATT5_CTL = TRIS_OUT;
#endif
    TRIS_BATT6_CTL = TRIS_OUT;

    TRIS_BATT1 = TRIS_IN;
    TRIS_BATT2 = TRIS_IN;
    TRIS_BATT3 = TRIS_IN;
    TRIS_BATT4 = TRIS_IN;
    TRIS_BATT5 = TRIS_IN;
    TRIS_BATT6 = TRIS_IN;

    TRIS_WTRSEN = TRIS_IN;

    LAT_PWRKILL = ~PWRKILL_ON;
    TRIS_PWRKILL = TRIS_OUT;

    TRIS_LED_STA = TRIS_OUT;
    TRIS_LED_BATTLOW = TRIS_OUT;

    LAT_LED_STA = LED_ON;
    LAT_LED_BATTLOW = LED_ON;


    initBus();
    LAT_LED_STA = LED_ON;
    LAT_LED_BATTLOW = ~LED_ON;

  //  while(1);

    initADC();
    initI2C();

    initBattlowLight();

#ifdef HAS_UART
    initInterruptUarts();
#endif

    for(l=0; l<50000; l++);

    LAT_LED_STA = LED_ON;
    LAT_LED_BATTLOW = ~LED_ON;

    for(l=0; l<50000; l++);

//     LAT_PWRKILL = PWRKILL_ON;

    LAT_LED_STA = ~LED_ON;

    for(i=0; i<16; i++)
        cfgRegs[i] = 65;


    byte i2cErrCount = 0;

    while(1)
    {
//         checkBus();
        /* Give it a second */
//        for(l=0; l<10000; l++);

        byte rx = readTemp(0x9E);

        /* Read error */
        if(rx == 255)
        {
            if(i2cErrCount < 10)
                i2cErrCount++;
            else
                myTemperature = 255;

            initI2C();
        } else
        {
            i2cErrCount = 0;
            myTemperature = rx;
        }

        static const byte vADCs[]={ADC_B1V, ADC_B2V, ADC_B3V, ADC_B4V, ADC_B5V, ADC_B6V, ADC_26V};

        /* Measure battery voltages */
        for(i=0; i < 7; i++) {
#ifdef BBR2
            /* There is no fifth battery in BBR2, so skip it */
            if(i == 4) { vBatt[4]= 0; continue; }
#endif
            setADC(vADCs[i]);
            vBatt[i] = applyCalibration(readADC(), CAL_V_A, CAL_V_B);
        }

        /* Maintain running averages of the I sensors */
        for(i=0; i < BATT_COUNT; i++) {
#ifdef BBR2
            /* There is no fifth battery in BBR2, so skip it */
            if(i == 4) { iADCVal[4][writeIndex] = 0; continue; }
#endif
            setADC(iADCs[i]);
            iADCVal[i][writeIndex] = readADC();
        }
        writeIndex++;

        if(writeIndex >= IHISTORY_SIZE)
            writeIndex = 0;

        /* Calculate running averages of the battery currents */
        for(i=0; i < BATT_COUNT; i++) {
#ifdef BBR2
            /* There is no fifth battery in BBR2, so skip it. */
            if(i == 4) { iBatt[4] = 0; continue; }
#endif
            iBatt[i] = applyCalibration(avgRow(i), CAL_I12V_A, CAL_I12V_B);
        }
    }
}
  void AbsoluteQuantitation::quantifyComponents(FeatureMap& unknowns)
  {
    //Potential Optimizations: create a map for each unknown FeatureMap
    // to reduce multiple loops

    // initialize all other variables
    Feature empty_feature;
    size_t IS_component_it, IS_component_group_it;

    // // iterate through the unknowns
    // for (size_t i = 0; i < unknowns.size(); i++)
    // {

    // iterate through each component_group/feature
    for (size_t feature_it = 0; feature_it < unknowns.size(); ++feature_it)
    {
      String component_group_name = (String)unknowns[feature_it].getMetaValue("PeptideRef");
      Feature unknowns_quant_feature;

      // iterate through each component/sub-feature
      for (size_t sub_it = 0; sub_it < unknowns[feature_it].getSubordinates().size(); ++sub_it)
      {
        String component_name = (String)unknowns[feature_it].getSubordinates()[sub_it].getMetaValue("native_id");

        // apply the calibration curve to components that are in the quant_method
        if (quant_methods_.count(component_name)>0)
        {
          double calculated_concentration = 0.0;
          std::map<String,AbsoluteQuantitationMethod>::iterator quant_methods_it = quant_methods_.find(component_name);
          String quant_component_name = quant_methods_it->second.getComponentName();
          String quant_IS_component_name = quant_methods_it->second.getISName();
          String quant_feature_name = quant_methods_it->second.getFeatureName();
          if (quant_IS_component_name != "")
          {
            // look up the internal standard for the component
            bool IS_found = false;
            // Optimization: 90% of the IS will be in the same component_group/feature
            for (size_t is_sub_it = 0; is_sub_it < unknowns[feature_it].getSubordinates().size(); ++is_sub_it)
            {
              String IS_component_name = (String)unknowns[feature_it].getSubordinates()[is_sub_it].getMetaValue("native_id");
              if (quant_IS_component_name == IS_component_name)
              {
                IS_found = true;
                IS_component_group_it = feature_it;
                IS_component_it = is_sub_it;
                break;
              }
            }
            if (!IS_found)
            {// expand IS search to all components
              // iterate through each component_group/feature
              for (size_t is_feature_it = 0; is_feature_it < unknowns.size(); ++is_feature_it)
              {
                //iterate through each component/sub-feature
                for (size_t is_sub_it = 0; is_sub_it < unknowns[is_feature_it].getSubordinates().size(); ++is_sub_it)
                {
                  String IS_component_name = (String)unknowns[is_feature_it].getSubordinates()[is_sub_it].getMetaValue("native_id");
                  if (quant_IS_component_name == IS_component_name)
                  {
                    IS_found = true;
                    IS_component_group_it = is_feature_it;
                    IS_component_it = is_sub_it;
                    break;
                  }
                }
                if (IS_found)
                {
                  break;
                }
              }
            }
            if (IS_found)
            {
              String transformation_model = quant_methods_it->second.getTransformationModel();
              Param transformation_model_params = quant_methods_it->second.getTransformationModelParams();
              calculated_concentration = applyCalibration(
                unknowns[feature_it].getSubordinates()[sub_it],
                unknowns[IS_component_group_it].getSubordinates()[IS_component_it],
                quant_feature_name,transformation_model,transformation_model_params);
            }
            else
            {
              LOG_INFO << "Component " << component_name << " IS " << quant_IS_component_name << " was not found.";
              LOG_INFO << "No concentration will be calculated.";
            }
          }
          else
          {
            String transformation_model = quant_methods_it->second.getTransformationModel();
            Param transformation_model_params = quant_methods_it->second.getTransformationModelParams();
            calculated_concentration = applyCalibration(
              unknowns[feature_it].getSubordinates()[sub_it],
              empty_feature,
              quant_feature_name,transformation_model,transformation_model_params);
          }

          // add new metadata (calculated_concentration, concentration_units) to the component
          unknowns[feature_it].getSubordinates()[sub_it].setMetaValue("calculated_concentration",calculated_concentration);
          String concentration_units = quant_methods_it->second.getConcentrationUnits();
          unknowns[feature_it].getSubordinates()[sub_it].setMetaValue("concentration_units",concentration_units);
          // calculate the bias?
        }
        else
        {
          LOG_INFO << "Component " << component_name << " does not have a quantitation method.";
          LOG_INFO << "No concentration will be calculated.";
          unknowns[feature_it].getSubordinates()[sub_it].setMetaValue("calculated_concentration","");
          unknowns[feature_it].getSubordinates()[sub_it].setMetaValue("concentration_units","");
        }
      }
    }
    // }
  }