Merge branch 'ets_start_delay'

* ets_start_delay:
  [modules] ets baro/airspeed: cleanup and default delay of 0.2s
  [modules] airspeed ets start delay
  [modules] baro ets start delay

closes #477
This commit is contained in:
Felix Ruess
2013-07-16 23:34:52 +02:00
9 changed files with 78 additions and 27 deletions
+3 -3
View File
@@ -9,7 +9,6 @@
<firmware name="fixedwing">
<target name="ap" board="lisa_m_1.0">
<define name="LISA_M_LONGITUDINAL_X"/>
<define name="SENSOR_SYNC_SEND"/>
<configure name="PERIODIC_FREQUENCY" value="120"/>
<configure name="AHRS_PROPAGATE_FREQUENCY" value="100"/>
@@ -27,7 +26,6 @@
<define name="STRONG_WIND"/>
<define name="WIND_INFO"/>
<define name="WIND_INFO_RET"/>
<define name="SENSOR_SYNC_SEND"/>
<!-- Sensors -->
<!--
<subsystem name="ahrs" type="int_cmpl_quat">
@@ -60,7 +58,9 @@
<modules>
<load name="gps_ubx_ucenter.xml"/>
<load name="airspeed_ets.xml"/>
<load name="airspeed_ets.xml">
<define name="AIRSPEED_ETS_SYNC_SEND"/>
</load>
<load name="adc_generic.xml">
<configure name="ADC_CHANNEL_GENERIC1" value="0"/>
<configure name="ADC_CHANNEL_GENERIC2" value="1"/>
@@ -44,14 +44,14 @@ twog_1.0 + aspirin + ETS baro + ETS speed
<modules>
<load name="airspeed_ets.xml">
<define name="SENSOR_SYNC_SEND"/>
<define name="AIRSPEED_ETS_SYNC_SEND"/>
<define name="AIRSPEED_ETS_SCALE" value="1.44"/> <!-- default 1.8-->
<!-- <define name="AIRSPEED_ETS_OFFSET" value="50"/> --> <!-- default 0 -->
<!-- <define name="AIRSPEED_ETS_I2C_DEV" value="i2c1"/> -->
</load>
<load name="baro_ets.xml">
<define name="BARO_ETS_SCALE" value="0.3"/>
<define name="BARO_ETS_TELEMETRY"/>
<define name="BARO_ETS_SYNC_SEND"/>
</load>
<load name="baro_board.xml">
<define name="BARO_ABS_EVENT" value="BaroEtsUpdate"/>
@@ -246,7 +246,7 @@ More information on the Quadshot can be found at transition-robotics.com -->
<!--Use an airspeed sensor and get the measured airspeed in the messages-->
<load name="airspeed_ets.xml">
<define name="SENSOR_SYNC_SEND"/>
<define name="AIRSPEED_ETS_SYNC_SEND"/>
</load>
<!-- Load this module to use multiple gain sets, which have to be specified in the gain sets section -->
+1 -1
View File
@@ -67,7 +67,7 @@
<configure name="ADC_CHANNEL_GENERIC1" value="ADC_4"/> <!-- voltage sensor -->
</load>
<!--load name="airspeed_ets.xml">
<define name="SENSOR_SYNC_SEND"/>
<define name="AIRSPEED_ETS_SYNC_SEND"/>
<define name="USE_AIRSPEED"/>
</load-->
</modules>
@@ -36,7 +36,7 @@
<modules>
<load name="airspeed_ets.xml">
<!--define name="USE_AIRSPEED" value="1"/-->
<define name="SENSOR_SYNC_SEND" value="1"/>
<define name="AIRSPEED_ETS_SYNC_SEND" value="1"/>
</load>
<load name="infrared_adc.xml"/>
</modules>
+5 -4
View File
@@ -17,11 +17,12 @@
- Yellow wire: SDA
- Brown wire: SCL
</description>
<define name="AIRSPEED_ETS_I2C_DEV" value="i2c0" description="change default i2c peripheral"/>
<define name="AIRSPEED_ETS_OFFSET" value="0" description="sensor offset (default: 0)"/>
<define name="AIRSPEED_ETS_SCALE" value="1.8" description="sensor scale factor (default: 1.8)"/>
<define name="AIRSPEED_ETS_I2C_DEV" value="i2cX" description="set i2c peripheral (default: i2c0)"/>
<define name="AIRSPEED_ETS_OFFSET" value="offset" description="sensor reading offset (default: 0)"/>
<define name="AIRSPEED_ETS_SCALE" value="scale" description="sensor scale factor (default: 1.8)"/>
<define name="AIRSPEED_ETS_START_DELAY" value="delay" description="set initial start delay in seconds"/>
<define name="USE_AIRSPEED" description="flag to use the data for airspeed control"/>
<define name="SENSOR_SYNC_SEND" description="flag to transmit the data as it is acquired"/>
<define name="AIRSPEED_ETS_SYNC_SEND" description="flag to transmit the data as it is acquired"/>
</doc>
<header>
+20 -4
View File
@@ -2,10 +2,26 @@
<module name="baro_ets" dir="sensors">
<doc>
<description>Baro ETS (I2C)</description>
<define name="BARO_ETS_I2C_DEV" value="i2cX" description="select i2c peripheral to use (default i2c0)"/>
<define name="BARO_ETS_SCALE" value="sensor scale factor"/>
<define name="BARO_ETS_TELEMETRY" description="flag to transmit the data as it is acquired"/>
<description>
Baro ETS (I2C).
Driver for the EagleTree Systems Baro Sensor.
Has only been tested with V3 of the sensor hardware.
Notes:
Connect directly to TWOG/Tiny I2C port. Multiple sensors can be chained together.
Sensor should be in the proprietary mode (default) and not in 3rd party mode.
Sensor module wire assignments:
- Red wire: 5V
- White wire: Ground
- Yellow wire: SDA
- Brown wire: SCL
</description>
<define name="BARO_ETS_I2C_DEV" value="i2cX" description="set i2c peripheral (default: i2c0)"/>
<define name="BARO_ETS_SCALE" value="scale" description="sensor scale factor (default: 1.8)"/>
<define name="BARO_ETS_START_DELAY" value="delay" description="set initial start delay in seconds"/>
<define name="BARO_ETS_SYNC_SEND" description="flag to transmit the data as it is acquired"/>
</doc>
<header>
+21 -4
View File
@@ -42,13 +42,14 @@
#include "state.h"
#include "mcu_periph/i2c.h"
#include "mcu_periph/uart.h"
#include "mcu_periph/sys_time.h"
#include "messages.h"
#include "subsystems/datalink/downlink.h"
#include <math.h>
#if !USE_AIRSPEED
#ifndef SENSOR_SYNC_SEND
#warning either set USE_AIRSPEED or SENSOR_SYNC_SEND to use ets_airspeed
#ifndef AIRSPEED_ETS_SYNC_SEND
#warning either set USE_AIRSPEED or AIRSPEED_ETS_SYNC_SEND to use ets_airspeed
#endif
#endif
@@ -68,6 +69,13 @@
#ifndef AIRSPEED_ETS_I2C_DEV
#define AIRSPEED_ETS_I2C_DEV i2c0
#endif
PRINT_CONFIG_VAR(AIRSPEED_ETS_I2C_DEV)
/** delay in seconds until sensor is read after startup */
#ifndef AIRSPEED_ETS_START_DELAY
#define AIRSPEED_ETS_START_DELAY 0.2
#endif
PRINT_CONFIG_VAR(AIRSPEED_ETS_START_DELAY)
#ifndef DOWNLINK_DEVICE
#define DOWNLINK_DEVICE DOWNLINK_AP_DEVICE
@@ -88,6 +96,8 @@ volatile bool_t airspeed_ets_i2c_done;
bool_t airspeed_ets_offset_init;
uint32_t airspeed_ets_offset_tmp;
uint16_t airspeed_ets_cnt;
uint32_t airspeed_ets_delay_time;
bool_t airspeed_ets_delay_done;
void airspeed_ets_init( void ) {
int n;
@@ -96,7 +106,7 @@ void airspeed_ets_init( void ) {
airspeed_ets_offset = 0;
airspeed_ets_offset_tmp = 0;
airspeed_ets_i2c_done = TRUE;
airspeed_ets_valid = TRUE;
airspeed_ets_valid = FALSE;
airspeed_ets_offset_init = FALSE;
airspeed_ets_cnt = AIRSPEED_ETS_OFFSET_NBSAMPLES_INIT + AIRSPEED_ETS_OFFSET_NBSAMPLES_AVRG;
@@ -105,10 +115,17 @@ void airspeed_ets_init( void ) {
airspeed_ets_buffer[n] = 0.0;
airspeed_ets_i2c_trans.status = I2CTransDone;
airspeed_ets_delay_done = FALSE;
SysTimeTimerStart(airspeed_ets_delay_time);
}
void airspeed_ets_read_periodic( void ) {
#ifndef SITL
if (!airspeed_ets_delay_done) {
if (SysTimeTimer(airspeed_ets_delay_time) < USEC_OF_SEC(AIRSPEED_ETS_START_DELAY)) return;
else airspeed_ets_delay_done = TRUE;
}
if (airspeed_ets_i2c_trans.status == I2CTransDone)
i2c_receive(&AIRSPEED_ETS_I2C_DEV, &airspeed_ets_i2c_trans, AIRSPEED_ETS_ADDR, 2);
#else // SITL
@@ -173,7 +190,7 @@ void airspeed_ets_read_event( void ) {
#if USE_AIRSPEED
stateSetAirspeed_f(&airspeed_ets);
#endif
#ifdef SENSOR_SYNC_SEND
#ifdef AIRSPEED_ETS_SYNC_SEND
DOWNLINK_SEND_AIRSPEED_ETS(DefaultChannel, DefaultDevice, &airspeed_ets_raw, &airspeed_ets_offset, &airspeed_ets);
#endif
} else {
+24 -7
View File
@@ -43,6 +43,7 @@
#include "mcu_periph/i2c.h"
#include "state.h"
#include <math.h>
#include "mcu_periph/sys_time.h"
#include "subsystems/nav.h"
@@ -50,7 +51,7 @@
#include "subsystems/gps.h"
#endif
#ifdef BARO_ETS_TELEMETRY
#ifdef BARO_ETS_SYNC_SEND
#ifndef DOWNLINK_DEVICE
#define DOWNLINK_DEVICE DOWNLINK_AP_DEVICE
#endif
@@ -58,7 +59,7 @@
#include "mcu_periph/uart.h"
#include "messages.h"
#include "subsystems/datalink/downlink.h"
#endif //BARO_ETS_TELEMETRY
#endif //BARO_ETS_SYNC_SEND
#define BARO_ETS_ADDR 0xE8
#define BARO_ETS_REG 0x07
@@ -75,6 +76,13 @@
#ifndef BARO_ETS_I2C_DEV
#define BARO_ETS_I2C_DEV i2c0
#endif
PRINT_CONFIG_VAR(BARO_ETS_I2C_DEV)
/** delay in seconds until sensor is read after startup */
#ifndef BARO_ETS_START_DELAY
#define BARO_ETS_START_DELAY 0.2
#endif
PRINT_CONFIG_VAR(BARO_ETS_START_DELAY)
// Global variables
uint16_t baro_ets_adc;
@@ -88,16 +96,18 @@ float baro_ets_sigma2;
struct i2c_transaction baro_ets_i2c_trans;
// Local variables
bool_t baro_ets_offset_init;
bool_t baro_ets_offset_init;
uint32_t baro_ets_offset_tmp;
uint16_t baro_ets_cnt;
uint32_t baro_ets_delay_time;
bool_t baro_ets_delay_done;
void baro_ets_init( void ) {
baro_ets_adc = 0;
baro_ets_altitude = 0.0;
baro_ets_offset = 0;
baro_ets_offset_tmp = 0;
baro_ets_valid = TRUE;
baro_ets_valid = FALSE;
baro_ets_offset_init = FALSE;
baro_ets_enabled = TRUE;
baro_ets_cnt = BARO_ETS_OFFSET_NBSAMPLES_INIT + BARO_ETS_OFFSET_NBSAMPLES_AVRG;
@@ -105,15 +115,22 @@ void baro_ets_init( void ) {
baro_ets_sigma2 = BARO_ETS_SIGMA2;
baro_ets_i2c_trans.status = I2CTransDone;
baro_ets_delay_done = FALSE;
SysTimeTimerStart(baro_ets_delay_time);
}
void baro_ets_read_periodic( void ) {
// Initiate next read
#ifndef SITL
if (!baro_ets_delay_done) {
if (SysTimeTimer(baro_ets_delay_time) < USEC_OF_SEC(BARO_ETS_START_DELAY)) return;
else baro_ets_delay_done = TRUE;
}
if (baro_ets_i2c_trans.status == I2CTransDone)
i2c_receive(&BARO_ETS_I2C_DEV, &baro_ets_i2c_trans, BARO_ETS_ADDR, 2);
#else // SITL
/* fake an offset so sim works for under hmsl as well */
/* fake an offset so sim works as well */
if (!baro_ets_offset_init) {
baro_ets_offset = 12400;
baro_ets_offset_init = TRUE;
@@ -123,7 +140,7 @@ void baro_ets_read_periodic( void ) {
baro_ets_valid = TRUE;
#endif
#ifdef BARO_ETS_TELEMETRY
#ifdef BARO_ETS_SYNC_SEND
DOWNLINK_SEND_BARO_ETS(DefaultChannel, DefaultDevice, &baro_ets_adc, &baro_ets_offset, &baro_ets_altitude);
#endif
}
@@ -161,7 +178,7 @@ void baro_ets_read_event( void ) {
if (baro_ets_offset_init) {
baro_ets_altitude = ground_alt + BARO_ETS_SCALE * (float)(baro_ets_offset-baro_ets_adc);
// New value available
#ifdef BARO_ETS_TELEMETRY
#ifdef BARO_ETS_SYNC_SEND
DOWNLINK_SEND_BARO_ETS(DefaultChannel, DefaultDevice, &baro_ets_adc, &baro_ets_offset, &baro_ets_altitude);
#endif
} else {