mirror of
https://github.com/paparazzi/paparazzi.git
synced 2026-05-09 22:49:53 +08:00
remove baro ets event makro and move transaction status check into event function
This commit is contained in:
@@ -11,11 +11,10 @@
|
||||
</header>
|
||||
<init fun="baro_ets_init()"/>
|
||||
<periodic fun="baro_ets_read_periodic()" freq="10."/>
|
||||
<event fun="BaroEtsEvent()"/>
|
||||
<event fun="baro_ets_event()"/>
|
||||
|
||||
<makefile>
|
||||
<file name="baro_ets.c"/>
|
||||
<file name="baro_ets.c"/>
|
||||
</makefile>
|
||||
|
||||
</module>
|
||||
|
||||
|
||||
@@ -81,62 +81,65 @@ void baro_ets_init( void ) {
|
||||
baro_ets_cnt = BARO_ETS_OFFSET_NBSAMPLES_INIT + BARO_ETS_OFFSET_NBSAMPLES_AVRG;
|
||||
baro_ets_r = BARO_ETS_R;
|
||||
baro_ets_sigma2 = BARO_ETS_SIGMA2;
|
||||
|
||||
baro_ets_i2c_trans.status = I2CTransDone;
|
||||
}
|
||||
|
||||
void baro_ets_read_periodic( void ) {
|
||||
// Initiate next read
|
||||
#ifndef SITL
|
||||
I2CReceive(i2c0, baro_ets_i2c_trans, BARO_ETS_ADDR, 2);
|
||||
if (baro_ets_i2c_trans.status == I2CTransDone)
|
||||
I2CReceive(i2c0, baro_ets_i2c_trans, BARO_ETS_ADDR, 2);
|
||||
#else // SITL
|
||||
baro_ets_adc = 0;
|
||||
baro_ets_altitude = gps_alt / 100.0;
|
||||
baro_ets_valid = TRUE;
|
||||
EstimatorSetAlt(baro_ets_altitude);
|
||||
#endif
|
||||
}
|
||||
|
||||
void baro_ets_read_event( void ) {
|
||||
// Get raw altimeter from buffer
|
||||
baro_ets_adc = ((uint16_t)(baro_ets_i2c_trans.buf[1]) << 8) | (uint16_t)(baro_ets_i2c_trans.buf[0]);
|
||||
// Check if this is valid altimeter
|
||||
if (baro_ets_adc == 0)
|
||||
baro_ets_valid = FALSE;
|
||||
else
|
||||
baro_ets_valid = TRUE;
|
||||
|
||||
// Continue only if a new altimeter value was received
|
||||
if (baro_ets_valid) {
|
||||
// Calculate offset average if not done already
|
||||
if (!baro_ets_offset_init) {
|
||||
--baro_ets_cnt;
|
||||
// Check if averaging completed
|
||||
if (baro_ets_cnt == 0) {
|
||||
// Calculate average
|
||||
baro_ets_offset = (uint16_t)(baro_ets_offset_tmp / BARO_ETS_OFFSET_NBSAMPLES_AVRG);
|
||||
// Limit offset
|
||||
if (baro_ets_offset < BARO_ETS_OFFSET_MIN)
|
||||
baro_ets_offset = BARO_ETS_OFFSET_MIN;
|
||||
if (baro_ets_offset > BARO_ETS_OFFSET_MAX)
|
||||
baro_ets_offset = BARO_ETS_OFFSET_MAX;
|
||||
baro_ets_offset_init = TRUE;
|
||||
}
|
||||
// Check if averaging needs to continue
|
||||
else if (baro_ets_cnt <= BARO_ETS_OFFSET_NBSAMPLES_AVRG)
|
||||
baro_ets_offset_tmp += baro_ets_adc;
|
||||
}
|
||||
// Convert raw to m/s
|
||||
if (baro_ets_offset_init)
|
||||
baro_ets_altitude = BARO_ETS_SCALE * (float)(baro_ets_offset-baro_ets_adc);
|
||||
else
|
||||
baro_ets_altitude = 0.0;
|
||||
// New value available
|
||||
EstimatorSetAlt(baro_ets_altitude);
|
||||
} else {
|
||||
baro_ets_altitude = 0.0;
|
||||
}
|
||||
|
||||
// Transaction has been read
|
||||
baro_ets_i2c_trans.status = I2CTransDone;
|
||||
|
||||
}
|
||||
|
||||
void baro_ets_event( void ) {
|
||||
if (baro_ets_i2c_trans.status == I2CTransSuccess) {
|
||||
// Get raw altimeter from buffer
|
||||
baro_ets_adc = ((uint16_t)(baro_ets_i2c_trans.buf[1]) << 8) | (uint16_t)(baro_ets_i2c_trans.buf[0]);
|
||||
// Check if this is valid altimeter
|
||||
if (baro_ets_adc == 0)
|
||||
baro_ets_valid = FALSE;
|
||||
else
|
||||
baro_ets_valid = TRUE;
|
||||
|
||||
// Continue only if a new altimeter value was received
|
||||
if (baro_ets_valid) {
|
||||
// Calculate offset average if not done already
|
||||
if (!baro_ets_offset_init) {
|
||||
--baro_ets_cnt;
|
||||
// Check if averaging completed
|
||||
if (baro_ets_cnt == 0) {
|
||||
// Calculate average
|
||||
baro_ets_offset = (uint16_t)(baro_ets_offset_tmp / BARO_ETS_OFFSET_NBSAMPLES_AVRG);
|
||||
// Limit offset
|
||||
if (baro_ets_offset < BARO_ETS_OFFSET_MIN)
|
||||
baro_ets_offset = BARO_ETS_OFFSET_MIN;
|
||||
if (baro_ets_offset > BARO_ETS_OFFSET_MAX)
|
||||
baro_ets_offset = BARO_ETS_OFFSET_MAX;
|
||||
baro_ets_offset_init = TRUE;
|
||||
}
|
||||
// Check if averaging needs to continue
|
||||
else if (baro_ets_cnt <= BARO_ETS_OFFSET_NBSAMPLES_AVRG)
|
||||
baro_ets_offset_tmp += baro_ets_adc;
|
||||
}
|
||||
// Convert raw to m/s
|
||||
if (baro_ets_offset_init)
|
||||
baro_ets_altitude = BARO_ETS_SCALE * (float)(baro_ets_offset-baro_ets_adc);
|
||||
else
|
||||
baro_ets_altitude = 0.0;
|
||||
// New value available
|
||||
EstimatorSetAlt(baro_ets_altitude);
|
||||
} else {
|
||||
baro_ets_altitude = 0.0;
|
||||
}
|
||||
|
||||
// Transaction has been read
|
||||
baro_ets_i2c_trans.status = I2CTransDone;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,8 +56,6 @@ extern struct i2c_transaction baro_ets_i2c_trans;
|
||||
|
||||
extern void baro_ets_init( void );
|
||||
extern void baro_ets_read_periodic( void );
|
||||
extern void baro_ets_read_event( void );
|
||||
|
||||
#define BaroEtsEvent() { if (baro_ets_i2c_trans.status == I2CTransSuccess) baro_ets_read_event(); }
|
||||
extern void baro_ets_event( void );
|
||||
|
||||
#endif // BARO_ETS_H
|
||||
|
||||
Reference in New Issue
Block a user