|
|
@ -77,10 +77,10 @@ |
|
|
|
#define PX4_I2C_BUS_DEFAULT PX4_I2C_BUS_EXPANSION |
|
|
|
#define PX4_I2C_BUS_DEFAULT PX4_I2C_BUS_EXPANSION |
|
|
|
|
|
|
|
|
|
|
|
/* I2C bus address */ |
|
|
|
/* I2C bus address */ |
|
|
|
#define I2C_ADDRESS 0x75 /* 7-bit address. 8-bit address is 0xEA */ |
|
|
|
#define I2C_ADDRESS 0x75 /* 7-bit address. 8-bit address is 0xEA */ |
|
|
|
|
|
|
|
|
|
|
|
/* Register address */ |
|
|
|
/* Register address */ |
|
|
|
#define READ_CMD 0x07 /* Read the data */ |
|
|
|
#define READ_CMD 0x07 /* Read the data */ |
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* The Eagle Tree Airspeed V3 cannot provide accurate reading below speeds of 15km/h. |
|
|
|
* The Eagle Tree Airspeed V3 cannot provide accurate reading below speeds of 15km/h. |
|
|
@ -106,35 +106,35 @@ public: |
|
|
|
ETSAirspeed(int bus, int address = I2C_ADDRESS); |
|
|
|
ETSAirspeed(int bus, int address = I2C_ADDRESS); |
|
|
|
virtual ~ETSAirspeed(); |
|
|
|
virtual ~ETSAirspeed(); |
|
|
|
|
|
|
|
|
|
|
|
virtual int init(); |
|
|
|
virtual int init(); |
|
|
|
|
|
|
|
|
|
|
|
virtual ssize_t read(struct file *filp, char *buffer, size_t buflen); |
|
|
|
virtual ssize_t read(struct file *filp, char *buffer, size_t buflen); |
|
|
|
virtual int ioctl(struct file *filp, int cmd, unsigned long arg); |
|
|
|
virtual int ioctl(struct file *filp, int cmd, unsigned long arg); |
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Diagnostics - print some basic information about the driver. |
|
|
|
* Diagnostics - print some basic information about the driver. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
void print_info(); |
|
|
|
void print_info(); |
|
|
|
|
|
|
|
|
|
|
|
protected: |
|
|
|
protected: |
|
|
|
virtual int probe(); |
|
|
|
virtual int probe(); |
|
|
|
|
|
|
|
|
|
|
|
private: |
|
|
|
private: |
|
|
|
work_s _work; |
|
|
|
work_s _work; |
|
|
|
unsigned _num_reports; |
|
|
|
unsigned _num_reports; |
|
|
|
volatile unsigned _next_report; |
|
|
|
volatile unsigned _next_report; |
|
|
|
volatile unsigned _oldest_report; |
|
|
|
volatile unsigned _oldest_report; |
|
|
|
differential_pressure_s *_reports; |
|
|
|
differential_pressure_s *_reports; |
|
|
|
bool _sensor_ok; |
|
|
|
bool _sensor_ok; |
|
|
|
int _measure_ticks; |
|
|
|
int _measure_ticks; |
|
|
|
bool _collect_phase; |
|
|
|
bool _collect_phase; |
|
|
|
int _diff_pres_offset; |
|
|
|
int _diff_pres_offset; |
|
|
|
|
|
|
|
|
|
|
|
orb_advert_t _airspeed_pub; |
|
|
|
orb_advert_t _airspeed_pub; |
|
|
|
|
|
|
|
|
|
|
|
perf_counter_t _sample_perf; |
|
|
|
perf_counter_t _sample_perf; |
|
|
|
perf_counter_t _comms_errors; |
|
|
|
perf_counter_t _comms_errors; |
|
|
|
perf_counter_t _buffer_overflows; |
|
|
|
perf_counter_t _buffer_overflows; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -144,7 +144,7 @@ private: |
|
|
|
* @param address The I2C bus address to probe. |
|
|
|
* @param address The I2C bus address to probe. |
|
|
|
* @return True if the device is present. |
|
|
|
* @return True if the device is present. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
int probe_address(uint8_t address); |
|
|
|
int probe_address(uint8_t address); |
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Initialise the automatic measurement state machine and start it. |
|
|
|
* Initialise the automatic measurement state machine and start it. |
|
|
@ -152,20 +152,20 @@ private: |
|
|
|
* @note This function is called at open and error time. It might make sense |
|
|
|
* @note This function is called at open and error time. It might make sense |
|
|
|
* to make it more aggressive about resetting the bus in case of errors. |
|
|
|
* to make it more aggressive about resetting the bus in case of errors. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
void start(); |
|
|
|
void start(); |
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Stop the automatic measurement state machine. |
|
|
|
* Stop the automatic measurement state machine. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
void stop(); |
|
|
|
void stop(); |
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Perform a poll cycle; collect from the previous measurement |
|
|
|
* Perform a poll cycle; collect from the previous measurement |
|
|
|
* and start a new one. |
|
|
|
* and start a new one. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
void cycle(); |
|
|
|
void cycle(); |
|
|
|
int measure(); |
|
|
|
int measure(); |
|
|
|
int collect(); |
|
|
|
int collect(); |
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Static trampoline from the workq context; because we don't have a |
|
|
|
* Static trampoline from the workq context; because we don't have a |
|
|
@ -173,7 +173,7 @@ private: |
|
|
|
* |
|
|
|
* |
|
|
|
* @param arg Instance pointer for the driver that is polling. |
|
|
|
* @param arg Instance pointer for the driver that is polling. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
static void cycle_trampoline(void *arg); |
|
|
|
static void cycle_trampoline(void *arg); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}; |
|
|
|
}; |
|
|
@ -230,6 +230,7 @@ ETSAirspeed::init() |
|
|
|
/* allocate basic report buffers */ |
|
|
|
/* allocate basic report buffers */ |
|
|
|
_num_reports = 2; |
|
|
|
_num_reports = 2; |
|
|
|
_reports = new struct differential_pressure_s[_num_reports]; |
|
|
|
_reports = new struct differential_pressure_s[_num_reports]; |
|
|
|
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < _num_reports; i++) |
|
|
|
for (unsigned i = 0; i < _num_reports; i++) |
|
|
|
_reports[i].max_differential_pressure_pa = 0; |
|
|
|
_reports[i].max_differential_pressure_pa = 0; |
|
|
|
|
|
|
|
|
|
|
@ -432,12 +433,12 @@ ETSAirspeed::measure() |
|
|
|
uint8_t cmd = READ_CMD; |
|
|
|
uint8_t cmd = READ_CMD; |
|
|
|
ret = transfer(&cmd, 1, nullptr, 0); |
|
|
|
ret = transfer(&cmd, 1, nullptr, 0); |
|
|
|
|
|
|
|
|
|
|
|
if (OK != ret) |
|
|
|
if (OK != ret) { |
|
|
|
{ |
|
|
|
|
|
|
|
perf_count(_comms_errors); |
|
|
|
perf_count(_comms_errors); |
|
|
|
log("i2c::transfer returned %d", ret); |
|
|
|
log("i2c::transfer returned %d", ret); |
|
|
|
return ret; |
|
|
|
return ret; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
ret = OK; |
|
|
|
ret = OK; |
|
|
|
|
|
|
|
|
|
|
|
return ret; |
|
|
|
return ret; |
|
|
@ -466,11 +467,12 @@ ETSAirspeed::collect() |
|
|
|
|
|
|
|
|
|
|
|
if (diff_pres_pa < _diff_pres_offset + MIN_ACCURATE_DIFF_PRES_PA) { |
|
|
|
if (diff_pres_pa < _diff_pres_offset + MIN_ACCURATE_DIFF_PRES_PA) { |
|
|
|
diff_pres_pa = 0; |
|
|
|
diff_pres_pa = 0; |
|
|
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
} else { |
|
|
|
diff_pres_pa -= _diff_pres_offset; |
|
|
|
diff_pres_pa -= _diff_pres_offset; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// XXX we may want to smooth out the readings to remove noise.
|
|
|
|
// XXX we may want to smooth out the readings to remove noise.
|
|
|
|
|
|
|
|
|
|
|
|
_reports[_next_report].timestamp = hrt_absolute_time(); |
|
|
|
_reports[_next_report].timestamp = hrt_absolute_time(); |
|
|
|
_reports[_next_report].differential_pressure_pa = diff_pres_pa; |
|
|
|
_reports[_next_report].differential_pressure_pa = diff_pres_pa; |
|
|
@ -517,11 +519,13 @@ ETSAirspeed::start() |
|
|
|
true, |
|
|
|
true, |
|
|
|
true, |
|
|
|
true, |
|
|
|
true, |
|
|
|
true, |
|
|
|
SUBSYSTEM_TYPE_DIFFPRESSURE}; |
|
|
|
SUBSYSTEM_TYPE_DIFFPRESSURE |
|
|
|
|
|
|
|
}; |
|
|
|
static orb_advert_t pub = -1; |
|
|
|
static orb_advert_t pub = -1; |
|
|
|
|
|
|
|
|
|
|
|
if (pub > 0) { |
|
|
|
if (pub > 0) { |
|
|
|
orb_publish(ORB_ID(subsystem_info), pub, &info); |
|
|
|
orb_publish(ORB_ID(subsystem_info), pub, &info); |
|
|
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
} else { |
|
|
|
pub = orb_advertise(ORB_ID(subsystem_info), &info); |
|
|
|
pub = orb_advertise(ORB_ID(subsystem_info), &info); |
|
|
|
} |
|
|
|
} |
|
|
@ -653,8 +657,7 @@ start(int i2c_bus) |
|
|
|
|
|
|
|
|
|
|
|
fail: |
|
|
|
fail: |
|
|
|
|
|
|
|
|
|
|
|
if (g_dev != nullptr)
|
|
|
|
if (g_dev != nullptr) { |
|
|
|
{ |
|
|
|
|
|
|
|
delete g_dev; |
|
|
|
delete g_dev; |
|
|
|
g_dev = nullptr; |
|
|
|
g_dev = nullptr; |
|
|
|
} |
|
|
|
} |
|
|
@ -668,15 +671,14 @@ fail: |
|
|
|
void |
|
|
|
void |
|
|
|
stop() |
|
|
|
stop() |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (g_dev != nullptr) |
|
|
|
if (g_dev != nullptr) { |
|
|
|
{ |
|
|
|
|
|
|
|
delete g_dev; |
|
|
|
delete g_dev; |
|
|
|
g_dev = nullptr; |
|
|
|
g_dev = nullptr; |
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
} else { |
|
|
|
{ |
|
|
|
|
|
|
|
errx(1, "driver not running"); |
|
|
|
errx(1, "driver not running"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
exit(0); |
|
|
|
exit(0); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -776,7 +778,7 @@ info() |
|
|
|
static void |
|
|
|
static void |
|
|
|
ets_airspeed_usage() |
|
|
|
ets_airspeed_usage() |
|
|
|
{ |
|
|
|
{ |
|
|
|
fprintf(stderr, "usage: ets_airspeed [options] command\n"); |
|
|
|
fprintf(stderr, "usage: ets_airspeed command [options]\n"); |
|
|
|
fprintf(stderr, "options:\n"); |
|
|
|
fprintf(stderr, "options:\n"); |
|
|
|
fprintf(stderr, "\t-b --bus i2cbus (%d)\n", PX4_I2C_BUS_DEFAULT); |
|
|
|
fprintf(stderr, "\t-b --bus i2cbus (%d)\n", PX4_I2C_BUS_DEFAULT); |
|
|
|
fprintf(stderr, "command:\n"); |
|
|
|
fprintf(stderr, "command:\n"); |
|
|
@ -789,6 +791,7 @@ ets_airspeed_main(int argc, char *argv[]) |
|
|
|
int i2c_bus = PX4_I2C_BUS_DEFAULT; |
|
|
|
int i2c_bus = PX4_I2C_BUS_DEFAULT; |
|
|
|
|
|
|
|
|
|
|
|
int i; |
|
|
|
int i; |
|
|
|
|
|
|
|
|
|
|
|
for (i = 1; i < argc; i++) { |
|
|
|
for (i = 1; i < argc; i++) { |
|
|
|
if (strcmp(argv[i], "-b") == 0 || strcmp(argv[i], "--bus") == 0) { |
|
|
|
if (strcmp(argv[i], "-b") == 0 || strcmp(argv[i], "--bus") == 0) { |
|
|
|
if (argc > i + 1) { |
|
|
|
if (argc > i + 1) { |
|
|
@ -803,11 +806,11 @@ ets_airspeed_main(int argc, char *argv[]) |
|
|
|
if (!strcmp(argv[1], "start")) |
|
|
|
if (!strcmp(argv[1], "start")) |
|
|
|
ets_airspeed::start(i2c_bus); |
|
|
|
ets_airspeed::start(i2c_bus); |
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* Stop the driver |
|
|
|
* Stop the driver |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
if (!strcmp(argv[1], "stop")) |
|
|
|
if (!strcmp(argv[1], "stop")) |
|
|
|
ets_airspeed::stop(); |
|
|
|
ets_airspeed::stop(); |
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* Test the driver/device. |
|
|
|
* Test the driver/device. |
|
|
|