Exemple #1
0
// *************************************************************************************************
// @fn          do_altitude_measurement
// @brief       Perform single altitude measurement
// @param       u8 filter       Filter option
// @return      none
// *************************************************************************************************
void do_altitude_measurement(u8 filter)
{
    volatile u32 pressure;

    // If sensor is not ready, skip data read
    if ((PS_INT_IN & PS_INT_PIN) == 0)
        return;

    // Get temperature (format is *10 K) from sensor
	if (bmp_used)
	{
        sAlt.temperature = bmp_ps_get_temp();
	}
	else
	{
        sAlt.temperature = cma_ps_get_temp();
	}

    // Get pressure (format is 1Pa) from sensor
	if (bmp_used)
	{
	    // Start sampling data in ultra low power mode
	    bmp_ps_write_register(BMP_085_CTRL_MEAS_REG, BMP_085_P_MEASURE);
	    // Get updated altitude
	    while ((PS_INT_IN & PS_INT_PIN) == 0) ;

	    pressure = bmp_ps_get_pa();
	}
	else
	{
        pressure = cma_ps_get_pa();
	}

    // Store measured pressure value
    if (filter == FILTER_OFF)   //sAlt.pressure == 0)
    {
        sAlt.pressure = pressure;
    }
    else
    {
        // Filter current pressure
        pressure = (u32) ((pressure * 0.2) + (sAlt.pressure * 0.8));

        // Store average pressure
        sAlt.pressure = pressure;
    }

    // Convert pressure (Pa) and temperature (K) to altitude (m)
    sAlt.altitude = conv_pa_to_meter(sAlt.pressure, sAlt.temperature);
}
Exemple #2
0
// *************************************************************************************************
// @fn          do_altitude_measurement
// @brief       Perform single altitude measurement
// @param       u8 filter       Filter option
// @return      none
// *************************************************************************************************
void do_altitude_measurement()
{
    volatile uint32_t pressure;

    // If sensor is not ready, skip data read
    if ((PS_INT_IN & PS_INT_PIN) == 0)
        return;

    // Get temperature (format is *10 K) from sensor
    if (bmp_used)
    {
        sAlt.temperature = bmp_ps_get_temp();
    }
    else
    {
        sAlt.temperature = cma_ps_get_temp();
    }

    // Get pressure (format is 1Pa) from sensor
    if (bmp_used)
    {
        // Start sampling data in configurable power mode
        bmp_ps_write_register(BMP_085_CTRL_MEAS_REG, BMP_085_P_MEASURE + (altPowerMode << 6));
        // Get updated altitude
        while ((PS_INT_IN & PS_INT_PIN) == 0) ;

        pressure = bmp_ps_get_pa();
    }
    else
    {
        pressure = cma_ps_get_pa();
    }

    // Store measured pressure value
    if(useFilter && sAlt.pressure){
            // Filter only if there was a previous value (to get a good first value)
            pressure = (u32) ((pressure * 0.7) + (sAlt.pressure * 0.3));
    }
    sAlt.pressure = pressure;
        
    
    // Convert pressure (Pa) and temperature (K) to altitude (m)
    sAlt.raw_altitude = conv_pa_to_meter(sAlt.pressure, sAlt.temperature);
    
    if(sAlt.raw_altitude > sAlt.raw_maxAltitude){
        sAlt.raw_maxAltitude = sAlt.raw_altitude;
    }
    
    if(sAlt.raw_altitude < sAlt.raw_minAltitude){
        sAlt.raw_minAltitude = sAlt.raw_altitude;
    }
    
    if((sAlt.raw_altitude > oldAccuAltitude) && (sAlt.raw_altitude - oldAccuAltitude > sAlt.accu_threshold)){
        sAlt.accuClimbUp += sAlt.raw_altitude - oldAccuAltitude;
        oldAccuAltitude = sAlt.raw_altitude;
    }
    
    if((sAlt.raw_altitude < oldAccuAltitude) && (oldAccuAltitude - sAlt.raw_altitude > sAlt.accu_threshold)){
        sAlt.accuClimbDown -= oldAccuAltitude - sAlt.raw_altitude;
        oldAccuAltitude = sAlt.raw_altitude;
    }

    
    sAlt.minAltitude = sAlt.raw_minAltitude - sAlt.altitude_offset;
    sAlt.maxAltitude = sAlt.raw_maxAltitude - sAlt.altitude_offset;
    sAlt.altitude = sAlt.raw_altitude - sAlt.altitude_offset;

    // Update climb value. Calibration is irrelevant, as it is just a constant sum. 
    // We subtract first_pressure from the reading to get the numbers down to something
    // that fits in 16 bits.
    sAlt.history_pos = (sAlt.history_pos + 1) % ALT_HISTORY_LEN;
    // Remove oldest value
    sAlt.climb += sAlt.history[sAlt.history_pos];
    // Add newest value
    sAlt.history[sAlt.history_pos] = (pressure - sAlt.first_pressure);
    sAlt.climb += sAlt.history[sAlt.history_pos];
    // The time half a history ago now affects the climb with a different sign,
    // so subtract twice
    sAlt.climb -= 2 * sAlt.history[(sAlt.history_pos + ALT_HISTORY_LEN/2) % ALT_HISTORY_LEN];
}