mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2024-12-01 09:24:10 +01:00
OP-1273 Uncrustify
This commit is contained in:
parent
8e26338f24
commit
c5dc556a43
@ -118,7 +118,7 @@ int32_t AirspeedInitialize()
|
||||
airspeedADCPin = i;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
lastAirspeedSensorType = airspeedSettings.AirspeedSensorType;
|
||||
|
||||
AirspeedSensorInitialize();
|
||||
@ -155,21 +155,21 @@ static void airspeedTask(__attribute__((unused)) void *parameters)
|
||||
// Update the airspeed object
|
||||
AirspeedSensorGet(&airspeedData);
|
||||
|
||||
// if sensor type changed and the last sensor was
|
||||
// if sensor type changed and the last sensor was
|
||||
// either Eagletree or PixHawk, reset I2C alarms
|
||||
if(airspeedSettings.AirspeedSensorType != lastAirspeedSensorType){
|
||||
if (airspeedSettings.AirspeedSensorType != lastAirspeedSensorType) {
|
||||
switch (lastAirspeedSensorType) {
|
||||
// Eagletree or PixHawk => Reset I2C alams
|
||||
case AIRSPEEDSETTINGS_AIRSPEEDSENSORTYPE_EAGLETREEAIRSPEEDV3:
|
||||
case AIRSPEEDSETTINGS_AIRSPEEDSENSORTYPE_PIXHAWKAIRSPEEDMS4525DO:
|
||||
AlarmsDefault(SYSTEMALARMS_ALARM_I2C);
|
||||
break;
|
||||
// else do not reset I2C alarms
|
||||
default: break;
|
||||
// Eagletree or PixHawk => Reset I2C alams
|
||||
case AIRSPEEDSETTINGS_AIRSPEEDSENSORTYPE_EAGLETREEAIRSPEEDV3:
|
||||
case AIRSPEEDSETTINGS_AIRSPEEDSENSORTYPE_PIXHAWKAIRSPEEDMS4525DO:
|
||||
AlarmsDefault(SYSTEMALARMS_ALARM_I2C);
|
||||
break;
|
||||
// else do not reset I2C alarms
|
||||
default: break;
|
||||
}
|
||||
lastAirspeedSensorType = airspeedSettings.AirspeedSensorType;
|
||||
}
|
||||
|
||||
|
||||
switch (airspeedSettings.AirspeedSensorType) {
|
||||
#if defined(PIOS_INCLUDE_MPXV)
|
||||
case AIRSPEEDSETTINGS_AIRSPEEDSENSORTYPE_DIYDRONESMPXV7002:
|
||||
|
@ -45,15 +45,15 @@
|
||||
#if defined(PIOS_INCLUDE_MS4525DO)
|
||||
|
||||
#define CALIBRATION_IDLE_MS 0 // Time to wait before calibrating, in [ms]
|
||||
#define CALIBRATION_COUNT_MS 4000 // Time to spend calibrating, in [ms]
|
||||
#define FILTER_SHIFT 5 // Barry Dorr filter parameter k
|
||||
#define CALIBRATION_COUNT_MS 4000 // Time to spend calibrating, in [ms]
|
||||
#define FILTER_SHIFT 5 // Barry Dorr filter parameter k
|
||||
|
||||
#define P0 101325.0f // standard pressure
|
||||
#define CCEXPONENT 0.2857142857f // exponent of compressibility correction 2/7
|
||||
#define CASFACTOR 760.8802669f // sqrt(5) * speed of sound at standard
|
||||
#define TASFACTOR 0.05891022589f // 1/sqrt(T0)
|
||||
#define P0 101325.0f // standard pressure
|
||||
#define CCEXPONENT 0.2857142857f // exponent of compressibility correction 2/7
|
||||
#define CASFACTOR 760.8802669f // sqrt(5) * speed of sound at standard
|
||||
#define TASFACTOR 0.05891022589f // 1/sqrt(T0)
|
||||
|
||||
#define max(x,y) ((x)>=(y) ? (x) : (y))
|
||||
#define max(x, y) ((x) >= (y) ? (x) : (y))
|
||||
|
||||
// Private types
|
||||
|
||||
@ -62,38 +62,38 @@ static int8_t baro_airspeedReadMS4525DO(AirspeedSensorData *airspeedSensor, Airs
|
||||
|
||||
|
||||
// Private variables
|
||||
static uint16_t calibrationCount = 0;
|
||||
static uint32_t filter_reg = 0; // Barry Dorr filter register
|
||||
static uint16_t calibrationCount = 0;
|
||||
static uint32_t filter_reg = 0; // Barry Dorr filter register
|
||||
|
||||
void baro_airspeedGetMS4525DO(AirspeedSensorData *airspeedSensor, AirspeedSettingsData *airspeedSettings)
|
||||
{
|
||||
// request measurement first
|
||||
int8_t retVal = PIOS_MS4525DO_Request();
|
||||
|
||||
if( retVal !=0 ){
|
||||
|
||||
if (retVal != 0) {
|
||||
AlarmsSet(SYSTEMALARMS_ALARM_I2C, SYSTEMALARMS_ALARM_ERROR);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Datasheet of MS4525DO: conversion needs 0.5 ms + 20% more when status bit used
|
||||
// delay by one Tick or at least 2 ms
|
||||
const portTickType xDelay = max(2 / portTICK_RATE_MS, 1);
|
||||
vTaskDelay( xDelay );
|
||||
|
||||
vTaskDelay(xDelay);
|
||||
|
||||
// read the sensor
|
||||
retVal = baro_airspeedReadMS4525DO(airspeedSensor,airspeedSettings);
|
||||
|
||||
switch( retVal ){
|
||||
case 0 : AlarmsClear(SYSTEMALARMS_ALARM_I2C);
|
||||
break;
|
||||
case -4 :
|
||||
case -5 : AlarmsSet(SYSTEMALARMS_ALARM_I2C, SYSTEMALARMS_ALARM_WARNING);
|
||||
break;
|
||||
case -1 :
|
||||
case -2 :
|
||||
case -3 :
|
||||
case -6 :
|
||||
default : AlarmsSet(SYSTEMALARMS_ALARM_I2C, SYSTEMALARMS_ALARM_ERROR);
|
||||
retVal = baro_airspeedReadMS4525DO(airspeedSensor, airspeedSettings);
|
||||
|
||||
switch (retVal) {
|
||||
case 0: AlarmsClear(SYSTEMALARMS_ALARM_I2C);
|
||||
break;
|
||||
case -4:
|
||||
case -5: AlarmsSet(SYSTEMALARMS_ALARM_I2C, SYSTEMALARMS_ALARM_WARNING);
|
||||
break;
|
||||
case -1:
|
||||
case -2:
|
||||
case -3:
|
||||
case -6:
|
||||
default: AlarmsSet(SYSTEMALARMS_ALARM_I2C, SYSTEMALARMS_ALARM_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
@ -103,38 +103,38 @@ static int8_t baro_airspeedReadMS4525DO(AirspeedSensorData *airspeedSensor, Airs
|
||||
{
|
||||
// Check to see if airspeed sensor is returning airspeedSensor
|
||||
uint16_t values[2];
|
||||
int8_t retVal=PIOS_MS4525DO_Read(values);
|
||||
|
||||
if( retVal == 0 ){
|
||||
airspeedSensor->SensorValue = values[0];
|
||||
int8_t retVal = PIOS_MS4525DO_Read(values);
|
||||
|
||||
if (retVal == 0) {
|
||||
airspeedSensor->SensorValue = values[0];
|
||||
airspeedSensor->SensorValueTemperature = values[1];
|
||||
} else {
|
||||
airspeedSensor->SensorValue = -1;
|
||||
airspeedSensor->SensorValueTemperature = -1;
|
||||
airspeedSensor->SensorConnected = AIRSPEEDSENSOR_SENSORCONNECTED_FALSE;
|
||||
airspeedSensor->CalibratedAirspeed = 0;
|
||||
airspeedSensor->SensorConnected = AIRSPEEDSENSOR_SENSORCONNECTED_FALSE;
|
||||
airspeedSensor->CalibratedAirspeed = 0;
|
||||
return retVal;
|
||||
}
|
||||
|
||||
|
||||
// only calibrate if no stored calibration is available
|
||||
if ( !airspeedSettings->ZeroPoint ) {
|
||||
if (!airspeedSettings->ZeroPoint) {
|
||||
// Calibrate sensor by averaging zero point value
|
||||
if (calibrationCount <= CALIBRATION_IDLE_MS / airspeedSettings->SamplePeriod) {
|
||||
calibrationCount++;
|
||||
filter_reg = (airspeedSensor->SensorValue << FILTER_SHIFT );
|
||||
|
||||
filter_reg = (airspeedSensor->SensorValue << FILTER_SHIFT);
|
||||
|
||||
return retVal;
|
||||
} else if (calibrationCount <= (CALIBRATION_IDLE_MS + CALIBRATION_COUNT_MS) / airspeedSettings->SamplePeriod) {
|
||||
calibrationCount++;
|
||||
// update filter register
|
||||
filter_reg = filter_reg - ( filter_reg >> FILTER_SHIFT ) + airspeedSensor->SensorValue;
|
||||
filter_reg = filter_reg - (filter_reg >> FILTER_SHIFT) + airspeedSensor->SensorValue;
|
||||
|
||||
if (calibrationCount > (CALIBRATION_IDLE_MS + CALIBRATION_COUNT_MS) / airspeedSettings->SamplePeriod) {
|
||||
// Scale output for unity gain.
|
||||
airspeedSettings->ZeroPoint = (uint16_t)( filter_reg >> FILTER_SHIFT );
|
||||
|
||||
// Scale output for unity gain.
|
||||
airspeedSettings->ZeroPoint = (uint16_t)(filter_reg >> FILTER_SHIFT);
|
||||
|
||||
AirspeedSettingsZeroPointSet(&airspeedSettings->ZeroPoint);
|
||||
calibrationCount = 0;
|
||||
calibrationCount = 0;
|
||||
}
|
||||
return retVal;
|
||||
}
|
||||
@ -149,19 +149,19 @@ static int8_t baro_airspeedReadMS4525DO(AirspeedSensorData *airspeedSensor, Airs
|
||||
Datasheet temperature: output = (T+50)*2047 / 200
|
||||
Inversion: T = (200*out - 102350)/2047 in C
|
||||
T = (200*out - 102350)/2047 + 273.15 in K
|
||||
*/
|
||||
const float dP = ( 10*(int32_t)(airspeedSensor->SensorValue-airspeedSettings->ZeroPoint) ) * 0.1052120688f;
|
||||
const float T = (float)( 200*(int32_t)airspeedSensor->SensorValueTemperature - 102350) / 2047 + 273.15f;
|
||||
|
||||
*/
|
||||
const float dP = (10 * (int32_t)(airspeedSensor->SensorValue - airspeedSettings->ZeroPoint)) * 0.1052120688f;
|
||||
const float T = (float)(200 * (int32_t)airspeedSensor->SensorValueTemperature - 102350) / 2047 + 273.15f;
|
||||
|
||||
airspeedSensor->DifferentialPressure = dP;
|
||||
airspeedSensor->Temperature = T;
|
||||
airspeedSensor->Temperature = T;
|
||||
// CAS = Csound * sqrt( 5 *( (dP/P0 +1)^(2/7) - 1) )
|
||||
// TAS = Csound * sqrt( 5 T/T0 *( (dP/P0 +1)^(2/7) - 1) )
|
||||
// where Csound = 340.276 m/s at standard condition T0=288.15 K and P0 = 101315 Pa
|
||||
airspeedSensor->CalibratedAirspeed = airspeedSettings->Scale * CASFACTOR * sqrtf( powf( fabsf(dP) / P0 + 1.0f , CCEXPONENT ) - 1.0f );
|
||||
airspeedSensor->TrueAirspeed = airspeedSensor->CalibratedAirspeed * TASFACTOR * sqrtf( T );
|
||||
airspeedSensor->CalibratedAirspeed = airspeedSettings->Scale * CASFACTOR * sqrtf(powf(fabsf(dP) / P0 + 1.0f, CCEXPONENT) - 1.0f);
|
||||
airspeedSensor->TrueAirspeed = airspeedSensor->CalibratedAirspeed * TASFACTOR * sqrtf(T);
|
||||
airspeedSensor->SensorConnected = AIRSPEEDSENSOR_SENSORCONNECTED_TRUE;
|
||||
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
|
@ -650,7 +650,7 @@ static int32_t updateAttitudeComplementary(bool first_run)
|
||||
if (airspeedSensor.SensorConnected == AIRSPEEDSENSOR_SENSORCONNECTED_TRUE) {
|
||||
// we have airspeed available
|
||||
airspeed.CalibratedAirspeed = airspeedSensor.CalibratedAirspeed;
|
||||
airspeed.TrueAirspeed = (airspeedSensor.TrueAirspeed < 0.f) ? airspeed.CalibratedAirspeed * IAS2TAS(homeLocation.Altitude - positionState.Down) : airspeedSensor.TrueAirspeed;
|
||||
airspeed.TrueAirspeed = (airspeedSensor.TrueAirspeed < 0.f) ? airspeed.CalibratedAirspeed *IAS2TAS(homeLocation.Altitude - positionState.Down) : airspeedSensor.TrueAirspeed;
|
||||
AirspeedStateSet(&airspeed);
|
||||
}
|
||||
}
|
||||
@ -1078,8 +1078,8 @@ static int32_t updateAttitudeINSGPS(bool first_run, bool outdoor_mode)
|
||||
AirspeedStateGet(&airspeed);
|
||||
|
||||
airspeed.CalibratedAirspeed = airspeedData.CalibratedAirspeed;
|
||||
airspeed.TrueAirspeed = (airspeedSensor.TrueAirspeed < 0.f) ? airspeed.CalibratedAirspeed * IAS2TAS(homeLocation.Altitude - positionState.Down) : airspeedSensor.TrueAirspeed;
|
||||
|
||||
airspeed.TrueAirspeed = (airspeedSensor.TrueAirspeed < 0.f) ? airspeed.CalibratedAirspeed *IAS2TAS(homeLocation.Altitude - positionState.Down) : airspeedSensor.TrueAirspeed;
|
||||
|
||||
AirspeedStateSet(&airspeed);
|
||||
|
||||
if (!gps_vel_updated && !gps_updated) {
|
||||
|
@ -78,7 +78,7 @@ static int32_t filter(stateFilter *self, stateEstimation *state)
|
||||
this->altitude = state->baro[0];
|
||||
}
|
||||
// calculate true airspeed estimation
|
||||
if (IS_SET(state->updated, SENSORUPDATES_airspeed) && (state->airspeed[1]<0.f) ) {
|
||||
if (IS_SET(state->updated, SENSORUPDATES_airspeed) && (state->airspeed[1] < 0.f)) {
|
||||
state->airspeed[1] = state->airspeed[0] * IAS2TAS(this->altitude);
|
||||
}
|
||||
|
||||
|
@ -74,7 +74,7 @@
|
||||
UNSET_MASK(states.updated, SENSORUPDATES_##shortname); \
|
||||
} \
|
||||
}
|
||||
|
||||
|
||||
#define FETCH_SENSOR_FROM_UAVOBJECT_CHECK_AND_LOAD_TO_STATE_1_DIMENSION_WITH_CUSTOM_EXTRA_CHECK(sensorname, shortname, a1, EXTRACHECK) \
|
||||
if (IS_SET(states.updated, SENSORUPDATES_##shortname)) { \
|
||||
sensorname##Data s; \
|
||||
@ -86,7 +86,7 @@
|
||||
UNSET_MASK(states.updated, SENSORUPDATES_##shortname); \
|
||||
} \
|
||||
}
|
||||
|
||||
|
||||
#define FETCH_SENSOR_FROM_UAVOBJECT_CHECK_AND_LOAD_TO_STATE_2_DIMENSION_WITH_CUSTOM_EXTRA_CHECK(sensorname, shortname, a1, a2, EXTRACHECK) \
|
||||
if (IS_SET(states.updated, SENSORUPDATES_##shortname)) { \
|
||||
sensorname##Data s; \
|
||||
@ -110,7 +110,7 @@
|
||||
s.a3 = states.shortname[2]; \
|
||||
statename##Set(&s); \
|
||||
}
|
||||
|
||||
|
||||
#define EXPORT_STATE_TO_UAVOBJECT_IF_UPDATED_2_DIMENSIONS(statename, shortname, a1, a2) \
|
||||
if (IS_SET(states.updated, SENSORUPDATES_##shortname)) { \
|
||||
statename##Data s; \
|
||||
@ -395,7 +395,7 @@ static void StateEstimationCb(void)
|
||||
FETCH_SENSOR_FROM_UAVOBJECT_CHECK_AND_LOAD_TO_STATE_3_DIMENSIONS(GPSVelocitySensor, vel, North, East, Down);
|
||||
FETCH_SENSOR_FROM_UAVOBJECT_CHECK_AND_LOAD_TO_STATE_1_DIMENSION_WITH_CUSTOM_EXTRA_CHECK(BaroSensor, baro, Altitude, true);
|
||||
FETCH_SENSOR_FROM_UAVOBJECT_CHECK_AND_LOAD_TO_STATE_2_DIMENSION_WITH_CUSTOM_EXTRA_CHECK(AirspeedSensor, airspeed, CalibratedAirspeed, TrueAirspeed, s.SensorConnected == AIRSPEEDSENSOR_SENSORCONNECTED_TRUE);
|
||||
|
||||
|
||||
// GPS position data (LLA) is not fetched here since it does not contain floats. The filter must do all checks itself
|
||||
|
||||
// at this point sensor state is stored in "states" with some rudimentary filtering applied
|
||||
|
@ -40,7 +40,6 @@ static int8_t PIOS_MS4525DO_WriteI2C(uint8_t *buffer, uint8_t len);
|
||||
static bool pios_ms4525do_requested = false;
|
||||
|
||||
|
||||
|
||||
static int8_t PIOS_MS4525DO_ReadI2C(uint8_t *buffer, uint8_t len)
|
||||
{
|
||||
const struct pios_i2c_txn txn_list[] = {
|
||||
@ -73,15 +72,15 @@ static int8_t PIOS_MS4525DO_WriteI2C(uint8_t *buffer, uint8_t len)
|
||||
}
|
||||
|
||||
|
||||
|
||||
int8_t PIOS_MS4525DO_Request(void)
|
||||
{
|
||||
// MS4525DO expects a zero length write.
|
||||
// MS4525DO expects a zero length write.
|
||||
// Sending one byte is a workaround that works for the moment
|
||||
uint8_t data=0;
|
||||
int8_t retVal=PIOS_MS4525DO_WriteI2C(&data,sizeof(data));
|
||||
/* requested only when transfer worked */
|
||||
pios_ms4525do_requested = ( retVal == 0 );
|
||||
uint8_t data = 0;
|
||||
int8_t retVal = PIOS_MS4525DO_WriteI2C(&data, sizeof(data));
|
||||
|
||||
/* requested only when transfer worked */
|
||||
pios_ms4525do_requested = (retVal == 0);
|
||||
|
||||
return retVal;
|
||||
}
|
||||
@ -98,28 +97,28 @@ int8_t PIOS_MS4525DO_Read(uint16_t *values)
|
||||
}
|
||||
|
||||
uint8_t data[4];
|
||||
int8_t retVal=PIOS_MS4525DO_ReadI2C(data, sizeof(data));
|
||||
int8_t retVal = PIOS_MS4525DO_ReadI2C(data, sizeof(data));
|
||||
|
||||
uint8_t status = data[0] & 0xC0;
|
||||
if (status == 0x80) {
|
||||
/* stale data */
|
||||
/* stale data */
|
||||
return -5;
|
||||
} else if (status == 0xC0) {
|
||||
/* device probably broken */
|
||||
return -6;
|
||||
}
|
||||
|
||||
/* differential pressure */
|
||||
/* differential pressure */
|
||||
values[0] = (data[0] << 8);
|
||||
values[0] += data[1];
|
||||
|
||||
values[0] += data[1];
|
||||
|
||||
/* temperature */
|
||||
values[1] = (data[2] << 8);
|
||||
values[1] += data[3];
|
||||
values[1] += data[3];
|
||||
values[1] = (values[1] >> 5);
|
||||
|
||||
/* not requested anymore, only when transfer worked */
|
||||
pios_ms4525do_requested = !( retVal == 0 );
|
||||
|
||||
/* not requested anymore, only when transfer worked */
|
||||
pios_ms4525do_requested = !(retVal == 0);
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
@ -414,8 +414,8 @@ static void go_starting(struct pios_i2c_adapter *i2c_adapter)
|
||||
i2c_adapter->last_byte = NULL;
|
||||
i2c_adapter->active_byte = i2c_adapter->last_byte + 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
I2C_GenerateSTART(i2c_adapter->cfg->regs, ENABLE);
|
||||
if (i2c_adapter->active_txn->rw == PIOS_I2C_TXN_READ) {
|
||||
I2C_ITConfig(i2c_adapter->cfg->regs, I2C_IT_EVT | I2C_IT_BUF | I2C_IT_ERR, ENABLE);
|
||||
|
@ -417,7 +417,7 @@ static void go_starting(struct pios_i2c_adapter *i2c_adapter)
|
||||
i2c_adapter->last_byte = NULL;
|
||||
i2c_adapter->active_byte = i2c_adapter->last_byte + 1;
|
||||
}
|
||||
|
||||
|
||||
I2C_GenerateSTART(i2c_adapter->cfg->regs, ENABLE);
|
||||
if (i2c_adapter->active_txn->rw == PIOS_I2C_TXN_READ) {
|
||||
I2C_ITConfig(i2c_adapter->cfg->regs, I2C_IT_EVT | I2C_IT_BUF | I2C_IT_ERR, ENABLE);
|
||||
|
@ -119,12 +119,12 @@
|
||||
// PIOS_I2C
|
||||
// See also pios_board.c
|
||||
// ------------------------
|
||||
#define PIOS_I2C_MAX_DEVS 3
|
||||
#define PIOS_I2C_MAX_DEVS 3
|
||||
extern uint32_t pios_i2c_mag_pressure_adapter_id;
|
||||
#define PIOS_I2C_MAIN_ADAPTER (pios_i2c_mag_pressure_adapter_id)
|
||||
#define PIOS_I2C_MAIN_ADAPTER (pios_i2c_mag_pressure_adapter_id)
|
||||
extern uint32_t pios_i2c_flexiport_adapter_id;
|
||||
#define PIOS_I2C_FLEXI_ADAPTER (pios_i2c_flexiport_adapter_id)
|
||||
#define PIOS_I2C_ETASV3_ADAPTER (PIOS_I2C_FLEXI_ADAPTER)
|
||||
#define PIOS_I2C_FLEXI_ADAPTER (pios_i2c_flexiport_adapter_id)
|
||||
#define PIOS_I2C_ETASV3_ADAPTER (PIOS_I2C_FLEXI_ADAPTER)
|
||||
#define PIOS_I2C_MS4525DO_ADAPTER (PIOS_I2C_FLEXI_ADAPTER)
|
||||
|
||||
// -------------------------
|
||||
|
Loading…
Reference in New Issue
Block a user