Browse Source

AP_Baro: make C_TO_KELVIN a function macro; create KELVIN_TO_C

These are in celsius
gps-1.3.1
Peter Barker 3 years ago committed by Peter Barker
parent
commit
e710969ebb
  1. 4
      libraries/AP_Baro/AP_Baro.cpp
  2. 2
      libraries/AP_Baro/AP_Baro_HIL.cpp
  3. 4
      libraries/AP_Baro/AP_Baro_SITL.cpp
  4. 2
      libraries/AP_Baro/AP_Baro_UAVCAN.cpp

4
libraries/AP_Baro/AP_Baro.cpp

@ -375,7 +375,7 @@ void AP_Baro::update_calibration() @@ -375,7 +375,7 @@ void AP_Baro::update_calibration()
float AP_Baro::get_altitude_difference(float base_pressure, float pressure) const
{
float ret;
float temp = get_ground_temperature() + C_TO_KELVIN;
float temp = C_TO_KELVIN(get_ground_temperature());
float scaling = pressure / base_pressure;
// This is an exact calculation that is within +-2.5m of the standard
@ -405,7 +405,7 @@ float AP_Baro::get_EAS2TAS(void) @@ -405,7 +405,7 @@ float AP_Baro::get_EAS2TAS(void)
// only estimate lapse rate for the difference from the ground location
// provides a more consistent reading then trying to estimate a complete
// ISA model atmosphere
float tempK = get_ground_temperature() + C_TO_KELVIN - ISA_LAPSE_RATE * altitude;
float tempK = C_TO_KELVIN(get_ground_temperature()) - ISA_LAPSE_RATE * altitude;
const float eas2tas_squared = SSL_AIR_DENSITY / (pressure / (ISA_GAS_CONSTANT * tempK));
if (!is_positive(eas2tas_squared)) {
return 1.0f;

2
libraries/AP_Baro/AP_Baro_HIL.cpp

@ -66,7 +66,7 @@ void AP_Baro::SimpleUnderWaterAtmosphere( @@ -66,7 +66,7 @@ void AP_Baro::SimpleUnderWaterAtmosphere(
// \f$T(D)\f$ Temperature underwater at given temperature
// \f$S\f$ Surface temperature at the surface
// \f$T(D)\approx\frac{S}{1.8 \cdot 10^{-4} \cdot S \cdot T + 1}\f$
const float seaTempSurface = SSL_AIR_TEMPERATURE - C_TO_KELVIN; // Celsius
const float seaTempSurface = KELVIN_TO_C(SSL_AIR_TEMPERATURE); // Celsius
const float S = seaTempSurface * 0.338f;
theta = 1.0f / ((1.8e-4f) * S * (alt * 1e3f) + 1.0f);
}

4
libraries/AP_Baro/AP_Baro_SITL.cpp

@ -118,14 +118,14 @@ void AP_Baro_SITL::_timer() @@ -118,14 +118,14 @@ void AP_Baro_SITL::_timer()
AP_Baro::SimpleAtmosphere(sim_alt * 0.001f, sigma, delta, theta);
float p = SSL_AIR_PRESSURE * delta;
float T = SSL_AIR_TEMPERATURE * theta - C_TO_KELVIN;
float T = KELVIN_TO_C(SSL_AIR_TEMPERATURE * theta);
temperature_adjustment(p, T);
#else
float rho, delta, theta;
AP_Baro::SimpleUnderWaterAtmosphere(-sim_alt * 0.001f, rho, delta, theta);
float p = SSL_AIR_PRESSURE * delta;
float T = SSL_AIR_TEMPERATURE * theta - C_TO_KELVIN;
float T = KELVIN_TO_C(SSL_AIR_TEMPERATURE * theta);
#endif
// add in correction for wind effects

2
libraries/AP_Baro/AP_Baro_UAVCAN.cpp

@ -168,7 +168,7 @@ void AP_Baro_UAVCAN::handle_temperature(AP_UAVCAN* ap_uavcan, uint8_t node_id, c @@ -168,7 +168,7 @@ void AP_Baro_UAVCAN::handle_temperature(AP_UAVCAN* ap_uavcan, uint8_t node_id, c
}
{
WITH_SEMAPHORE(driver->_sem_baro);
driver->_temperature = cb.msg->static_temperature - C_TO_KELVIN;
driver->_temperature = KELVIN_TO_C(cb.msg->static_temperature);
}
}

Loading…
Cancel
Save