mirror of
https://gitee.com/xiaohuolufeihua/bizhang_-obav.git
synced 2026-05-21 01:12:11 +00:00
differential_pressure sensors: use driver base class
This commit is contained in:
@@ -24,7 +24,8 @@ if [ ${VEHICLE_TYPE} = fw -o ${VEHICLE_TYPE} = vtol ]
|
|||||||
then
|
then
|
||||||
if param compare CBRK_AIRSPD_CHK 0
|
if param compare CBRK_AIRSPD_CHK 0
|
||||||
then
|
then
|
||||||
sdp3x_airspeed start -a
|
sdp3x_airspeed start -X
|
||||||
|
sdp3x_airspeed start -X -a 0x22
|
||||||
|
|
||||||
# Pixhawk 2.1 has a MS5611 on I2C which gets wrongly
|
# Pixhawk 2.1 has a MS5611 on I2C which gets wrongly
|
||||||
# detected as MS5525 because the chip manufacturer was so
|
# detected as MS5525 because the chip manufacturer was so
|
||||||
@@ -32,14 +33,14 @@ then
|
|||||||
# register.
|
# register.
|
||||||
if [ $BOARD_FMUV3 = 21 ]
|
if [ $BOARD_FMUV3 = 21 ]
|
||||||
then
|
then
|
||||||
ms5525_airspeed start -b 2
|
ms5525_airspeed start -X -b 2
|
||||||
else
|
else
|
||||||
ms5525_airspeed start -a
|
ms5525_airspeed start -X
|
||||||
fi
|
fi
|
||||||
|
|
||||||
ms4525_airspeed start -a
|
ms4525_airspeed start -X
|
||||||
|
|
||||||
ets_airspeed start -a
|
ets_airspeed start -X
|
||||||
|
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -21,31 +21,19 @@ if adc start
|
|||||||
then
|
then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if sdp3x_airspeed start
|
if sdp3x_airspeed start -X
|
||||||
then
|
then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ms5525_airspeed start
|
if ms5525_airspeed start -X
|
||||||
then
|
then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ms5525_airspeed start -b 2
|
if ms4525_airspeed start -X
|
||||||
then
|
then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ms4525_airspeed start
|
if ets_airspeed start -X
|
||||||
then
|
|
||||||
fi
|
|
||||||
|
|
||||||
if ms4525_airspeed start -b 2
|
|
||||||
then
|
|
||||||
fi
|
|
||||||
|
|
||||||
if ets_airspeed start
|
|
||||||
then
|
|
||||||
fi
|
|
||||||
|
|
||||||
if ets_airspeed start -b 1
|
|
||||||
then
|
then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ lps22hb -s start
|
|||||||
|
|
||||||
lsm303agr -R 4 start
|
lsm303agr -R 4 start
|
||||||
|
|
||||||
ms4525_airspeed -T 4515 -b 3 start
|
ms4525_airspeed -T 4515 -I -b 3 start
|
||||||
|
|
||||||
if ! param greater SENS_EN_PMW3901 0
|
if ! param greater SENS_EN_PMW3901 0
|
||||||
then
|
then
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ adc start
|
|||||||
battery_status start
|
battery_status start
|
||||||
|
|
||||||
gps start -d /dev/spidev0.0 -i spi -p ubx
|
gps start -d /dev/spidev0.0 -i spi -p ubx
|
||||||
ms4525_airspeed start
|
ms4525_airspeed start -X
|
||||||
rc_update start
|
rc_update start
|
||||||
sensors start
|
sensors start
|
||||||
commander start
|
commander start
|
||||||
|
|||||||
@@ -42,6 +42,8 @@
|
|||||||
|
|
||||||
#include <drivers/airspeed/airspeed.h>
|
#include <drivers/airspeed/airspeed.h>
|
||||||
#include <px4_platform_common/getopt.h>
|
#include <px4_platform_common/getopt.h>
|
||||||
|
#include <px4_platform_common/module.h>
|
||||||
|
#include <px4_platform_common/i2c_spi_buses.h>
|
||||||
|
|
||||||
/* 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 */
|
||||||
@@ -59,21 +61,22 @@
|
|||||||
/* Measurement rate is 100Hz */
|
/* Measurement rate is 100Hz */
|
||||||
#define CONVERSION_INTERVAL (1000000 / 100) /* microseconds */
|
#define CONVERSION_INTERVAL (1000000 / 100) /* microseconds */
|
||||||
|
|
||||||
class ETSAirspeed : public Airspeed
|
class ETSAirspeed : public Airspeed, public I2CSPIDriver<ETSAirspeed>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ETSAirspeed(int bus, int address = I2C_ADDRESS, const char *path = ETS_PATH);
|
ETSAirspeed(I2CSPIBusOption bus_option, const int bus, int bus_frequency, int address = I2C_ADDRESS,
|
||||||
|
const char *path = ETS_PATH);
|
||||||
|
|
||||||
|
virtual ~ETSAirspeed() = default;
|
||||||
|
|
||||||
|
static I2CSPIDriverBase *instantiate(const BusCLIArguments &cli, const BusInstanceIterator &iterator,
|
||||||
|
int runtime_instance);
|
||||||
|
static void print_usage();
|
||||||
|
|
||||||
|
void RunImpl();
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
/**
|
|
||||||
* Perform a poll cycle; collect from the previous measurement
|
|
||||||
* and start a new one.
|
|
||||||
*/
|
|
||||||
void Run() override;
|
|
||||||
int measure() override;
|
int measure() override;
|
||||||
int collect() override;
|
int collect() override;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -81,8 +84,9 @@ protected:
|
|||||||
*/
|
*/
|
||||||
extern "C" __EXPORT int ets_airspeed_main(int argc, char *argv[]);
|
extern "C" __EXPORT int ets_airspeed_main(int argc, char *argv[]);
|
||||||
|
|
||||||
ETSAirspeed::ETSAirspeed(int bus, int address, const char *path) : Airspeed(bus, address,
|
ETSAirspeed::ETSAirspeed(I2CSPIBusOption bus_option, const int bus, int bus_frequency, int address, const char *path)
|
||||||
CONVERSION_INTERVAL, path)
|
: Airspeed(bus, bus_frequency, address, CONVERSION_INTERVAL, path),
|
||||||
|
I2CSPIDriver(MODULE_NAME, px4::device_bus_to_wq(get_device_id()), bus_option, bus, address)
|
||||||
{
|
{
|
||||||
_device_id.devid_s.devtype = DRV_DIFF_PRESS_DEVTYPE_MS4525;
|
_device_id.devid_s.devtype = DRV_DIFF_PRESS_DEVTYPE_MS4525;
|
||||||
}
|
}
|
||||||
@@ -157,7 +161,7 @@ ETSAirspeed::collect()
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ETSAirspeed::Run()
|
ETSAirspeed::RunImpl()
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
@@ -170,8 +174,9 @@ ETSAirspeed::Run()
|
|||||||
if (OK != ret) {
|
if (OK != ret) {
|
||||||
perf_count(_comms_errors);
|
perf_count(_comms_errors);
|
||||||
/* restart the measurement state machine */
|
/* restart the measurement state machine */
|
||||||
start();
|
_collect_phase = false;
|
||||||
_sensor_ok = false;
|
_sensor_ok = false;
|
||||||
|
ScheduleNow();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -206,206 +211,63 @@ ETSAirspeed::Run()
|
|||||||
ScheduleDelayed(CONVERSION_INTERVAL);
|
ScheduleDelayed(CONVERSION_INTERVAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
I2CSPIDriverBase *ETSAirspeed::instantiate(const BusCLIArguments &cli, const BusInstanceIterator &iterator,
|
||||||
* Local functions in support of the shell command.
|
int runtime_instance)
|
||||||
*/
|
|
||||||
namespace ets_airspeed
|
|
||||||
{
|
{
|
||||||
|
ETSAirspeed *instance = new ETSAirspeed(iterator.configuredBusOption(), iterator.bus(), cli.bus_frequency);
|
||||||
|
|
||||||
ETSAirspeed *g_dev = nullptr;
|
if (instance == nullptr) {
|
||||||
|
PX4_ERR("alloc failed");
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
int start();
|
if (instance->init() != PX4_OK) {
|
||||||
int start_bus(int i2c_bus);
|
delete instance;
|
||||||
int stop();
|
return nullptr;
|
||||||
int reset();
|
}
|
||||||
int info();
|
|
||||||
|
|
||||||
/**
|
instance->ScheduleNow();
|
||||||
* Attempt to start driver on all available I2C busses.
|
return instance;
|
||||||
*
|
}
|
||||||
* This function will return as soon as the first sensor
|
|
||||||
* is detected on one of the available busses or if no
|
|
||||||
* sensors are detected.
|
void
|
||||||
*
|
ETSAirspeed::print_usage()
|
||||||
*/
|
|
||||||
int
|
|
||||||
start()
|
|
||||||
{
|
{
|
||||||
for (unsigned i = 0; i < NUM_I2C_BUS_OPTIONS; i++) {
|
PRINT_MODULE_USAGE_NAME("ets_airspeed", "driver");
|
||||||
if (start_bus(i2c_bus_options[i]) == PX4_OK) {
|
PRINT_MODULE_USAGE_COMMAND("start");
|
||||||
return PX4_OK;
|
PRINT_MODULE_USAGE_PARAMS_I2C_SPI_DRIVER(true, false);
|
||||||
}
|
PRINT_MODULE_USAGE_DEFAULT_COMMANDS();
|
||||||
}
|
|
||||||
|
|
||||||
return PX4_ERROR;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Start the driver on a specific bus.
|
|
||||||
*
|
|
||||||
* This function only returns if the sensor is up and running
|
|
||||||
* or could not be detected successfully.
|
|
||||||
*/
|
|
||||||
int
|
|
||||||
start_bus(int i2c_bus)
|
|
||||||
{
|
|
||||||
int fd;
|
|
||||||
|
|
||||||
if (g_dev != nullptr) {
|
|
||||||
PX4_ERR("already started");
|
|
||||||
return PX4_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* create the driver */
|
|
||||||
g_dev = new ETSAirspeed(i2c_bus);
|
|
||||||
|
|
||||||
if (g_dev == nullptr) {
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (OK != g_dev->init()) {
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* set the poll rate to default, starts automatic data collection */
|
|
||||||
fd = px4_open(AIRSPEED0_DEVICE_PATH, O_RDONLY);
|
|
||||||
|
|
||||||
if (fd < 0) {
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (px4_ioctl(fd, SENSORIOCSPOLLRATE, SENSOR_POLLRATE_DEFAULT) < 0) {
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
return PX4_OK;
|
|
||||||
|
|
||||||
fail:
|
|
||||||
|
|
||||||
if (g_dev != nullptr) {
|
|
||||||
delete g_dev;
|
|
||||||
g_dev = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
return PX4_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Stop the driver
|
|
||||||
*/
|
|
||||||
int
|
|
||||||
stop()
|
|
||||||
{
|
|
||||||
if (g_dev != nullptr) {
|
|
||||||
delete g_dev;
|
|
||||||
g_dev = nullptr;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
PX4_ERR("driver not running");
|
|
||||||
return PX4_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
return PX4_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reset the driver.
|
|
||||||
*/
|
|
||||||
int
|
|
||||||
reset()
|
|
||||||
{
|
|
||||||
int fd = px4_open(ETS_PATH, O_RDONLY);
|
|
||||||
|
|
||||||
if (fd < 0) {
|
|
||||||
PX4_ERR("failed");
|
|
||||||
return PX4_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (px4_ioctl(fd, SENSORIOCRESET, 0) < 0) {
|
|
||||||
PX4_ERR("driver reset failed");
|
|
||||||
return PX4_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (px4_ioctl(fd, SENSORIOCSPOLLRATE, SENSOR_POLLRATE_DEFAULT) < 0) {
|
|
||||||
PX4_ERR("driver poll restart failed");
|
|
||||||
return PX4_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
return PX4_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
|
||||||
ets_airspeed_usage()
|
|
||||||
{
|
|
||||||
PX4_INFO("usage: ets_airspeed command [options]");
|
|
||||||
PX4_INFO("options:");
|
|
||||||
PX4_INFO("\t-b --bus i2cbus (%d)", PX4_I2C_BUS_DEFAULT);
|
|
||||||
PX4_INFO("\t-a --all");
|
|
||||||
PX4_INFO("command:");
|
|
||||||
PX4_INFO("\tstart|stop|reset|info");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
ets_airspeed_main(int argc, char *argv[])
|
ets_airspeed_main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int i2c_bus = PX4_I2C_BUS_DEFAULT;
|
using ThisDriver = ETSAirspeed;
|
||||||
|
BusCLIArguments cli{true, false};
|
||||||
|
cli.default_i2c_frequency = 100000;
|
||||||
|
|
||||||
int myoptind = 1;
|
const char *verb = cli.parseDefaultArguments(argc, argv);
|
||||||
int ch;
|
|
||||||
const char *myoptarg = nullptr;
|
|
||||||
bool start_all = false;
|
|
||||||
|
|
||||||
while ((ch = px4_getopt(argc, argv, "ab:", &myoptind, &myoptarg)) != EOF) {
|
if (!verb) {
|
||||||
switch (ch) {
|
ThisDriver::print_usage();
|
||||||
case 'b':
|
|
||||||
i2c_bus = atoi(myoptarg);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'a':
|
|
||||||
start_all = true;
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
ets_airspeed_usage();
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (myoptind >= argc) {
|
|
||||||
ets_airspeed_usage();
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
BusInstanceIterator iterator(MODULE_NAME, cli, DRV_DIFF_PRESS_DEVTYPE_ETS3);
|
||||||
* Start/load the driver.
|
|
||||||
*/
|
|
||||||
if (!strcmp(argv[myoptind], "start")) {
|
|
||||||
if (start_all) {
|
|
||||||
return ets_airspeed::start();
|
|
||||||
|
|
||||||
} else {
|
if (!strcmp(verb, "start")) {
|
||||||
return ets_airspeed::start_bus(i2c_bus);
|
return ThisDriver::module_start(cli, iterator);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
if (!strcmp(verb, "stop")) {
|
||||||
* Stop the driver
|
return ThisDriver::module_stop(iterator);
|
||||||
*/
|
|
||||||
if (!strcmp(argv[myoptind], "stop")) {
|
|
||||||
return ets_airspeed::stop();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
if (!strcmp(verb, "status")) {
|
||||||
* Reset the driver.
|
return ThisDriver::module_status(iterator);
|
||||||
*/
|
|
||||||
if (!strcmp(argv[myoptind], "reset")) {
|
|
||||||
return ets_airspeed::reset();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ets_airspeed_usage();
|
ThisDriver::print_usage();
|
||||||
return 0;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,6 +51,8 @@
|
|||||||
|
|
||||||
#include <mathlib/math/filter/LowPassFilter2p.hpp>
|
#include <mathlib/math/filter/LowPassFilter2p.hpp>
|
||||||
#include <px4_platform_common/getopt.h>
|
#include <px4_platform_common/getopt.h>
|
||||||
|
#include <px4_platform_common/module.h>
|
||||||
|
#include <px4_platform_common/i2c_spi_buses.h>
|
||||||
#include <uORB/topics/system_power.h>
|
#include <uORB/topics/system_power.h>
|
||||||
|
|
||||||
#include <drivers/airspeed/airspeed.h>
|
#include <drivers/airspeed/airspeed.h>
|
||||||
@@ -74,18 +76,22 @@ enum MS_DEVICE_TYPE {
|
|||||||
#define CONVERSION_INTERVAL (1000000 / MEAS_RATE) /* microseconds */
|
#define CONVERSION_INTERVAL (1000000 / MEAS_RATE) /* microseconds */
|
||||||
|
|
||||||
|
|
||||||
class MEASAirspeed : public Airspeed
|
class MEASAirspeed : public Airspeed, public I2CSPIDriver<MEASAirspeed>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MEASAirspeed(int bus, int address = I2C_ADDRESS_MS4525DO, const char *path = PATH_MS4525);
|
MEASAirspeed(I2CSPIBusOption bus_option, const int bus, int bus_frequency, int address = I2C_ADDRESS_MS4525DO,
|
||||||
|
const char *path = PATH_MS4525);
|
||||||
|
|
||||||
|
virtual ~MEASAirspeed() = default;
|
||||||
|
|
||||||
|
static I2CSPIDriverBase *instantiate(const BusCLIArguments &cli, const BusInstanceIterator &iterator,
|
||||||
|
int runtime_instance);
|
||||||
|
static void print_usage();
|
||||||
|
|
||||||
|
void RunImpl();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
/**
|
|
||||||
* Perform a poll cycle; collect from the previous measurement
|
|
||||||
* and start a new one.
|
|
||||||
*/
|
|
||||||
void Run() override;
|
|
||||||
int measure() override;
|
int measure() override;
|
||||||
int collect() override;
|
int collect() override;
|
||||||
|
|
||||||
@@ -105,7 +111,9 @@ protected:
|
|||||||
*/
|
*/
|
||||||
extern "C" __EXPORT int ms4525_airspeed_main(int argc, char *argv[]);
|
extern "C" __EXPORT int ms4525_airspeed_main(int argc, char *argv[]);
|
||||||
|
|
||||||
MEASAirspeed::MEASAirspeed(int bus, int address, const char *path) : Airspeed(bus, address, CONVERSION_INTERVAL, path)
|
MEASAirspeed::MEASAirspeed(I2CSPIBusOption bus_option, const int bus, int bus_frequency, int address, const char *path)
|
||||||
|
: Airspeed(bus, bus_frequency, address, CONVERSION_INTERVAL, path),
|
||||||
|
I2CSPIDriver(MODULE_NAME, px4::device_bus_to_wq(get_device_id()), bus_option, bus, address)
|
||||||
{
|
{
|
||||||
_device_id.devid_s.devtype = DRV_DIFF_PRESS_DEVTYPE_MS4525;
|
_device_id.devid_s.devtype = DRV_DIFF_PRESS_DEVTYPE_MS4525;
|
||||||
}
|
}
|
||||||
@@ -221,7 +229,7 @@ MEASAirspeed::collect()
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
MEASAirspeed::Run()
|
MEASAirspeed::RunImpl()
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
@@ -233,8 +241,9 @@ MEASAirspeed::Run()
|
|||||||
|
|
||||||
if (OK != ret) {
|
if (OK != ret) {
|
||||||
/* restart the measurement state machine */
|
/* restart the measurement state machine */
|
||||||
start();
|
_collect_phase = false;
|
||||||
_sensor_ok = false;
|
_sensor_ok = false;
|
||||||
|
ScheduleNow();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -336,216 +345,83 @@ MEASAirspeed::voltage_correction(float &diff_press_pa, float &temperature)
|
|||||||
#endif // defined(ADC_SCALED_V5_SENSE)
|
#endif // defined(ADC_SCALED_V5_SENSE)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
I2CSPIDriverBase *MEASAirspeed::instantiate(const BusCLIArguments &cli, const BusInstanceIterator &iterator,
|
||||||
* Local functions in support of the shell command.
|
int runtime_instance)
|
||||||
*/
|
|
||||||
namespace meas_airspeed
|
|
||||||
{
|
{
|
||||||
|
MEASAirspeed *instance = new MEASAirspeed(iterator.configuredBusOption(), iterator.bus(), cli.bus_frequency,
|
||||||
|
cli.i2c_address);
|
||||||
|
|
||||||
MEASAirspeed *g_dev = nullptr;
|
if (instance == nullptr) {
|
||||||
|
PX4_ERR("alloc failed");
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
int start();
|
if (instance->init() != PX4_OK) {
|
||||||
int start_bus(int i2c_bus, int address);
|
delete instance;
|
||||||
int stop();
|
return nullptr;
|
||||||
int reset();
|
}
|
||||||
|
|
||||||
/**
|
instance->ScheduleNow();
|
||||||
* Attempt to start driver on all available I2C busses.
|
return instance;
|
||||||
*
|
}
|
||||||
* This function will return as soon as the first sensor
|
|
||||||
* is detected on one of the available busses or if no
|
|
||||||
* sensors are detected.
|
void
|
||||||
*
|
MEASAirspeed::print_usage()
|
||||||
*/
|
|
||||||
int
|
|
||||||
start()
|
|
||||||
{
|
{
|
||||||
for (unsigned i = 0; i < NUM_I2C_BUS_OPTIONS; i++) {
|
PRINT_MODULE_USAGE_NAME("ms4525_airspeed", "driver");
|
||||||
if (start_bus(i2c_bus_options[i], I2C_ADDRESS_MS4525DO) == PX4_OK) {
|
PRINT_MODULE_USAGE_COMMAND("start");
|
||||||
return PX4_OK;
|
PRINT_MODULE_USAGE_PARAMS_I2C_SPI_DRIVER(true, false);
|
||||||
}
|
PRINT_MODULE_USAGE_PARAM_STRING('T', "4525", "4525|4515", "Device type", true);
|
||||||
}
|
PRINT_MODULE_USAGE_DEFAULT_COMMANDS();
|
||||||
|
|
||||||
return PX4_ERROR;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Start the driver on a specific bus.
|
|
||||||
*
|
|
||||||
* This function call only returns once the driver is up and running
|
|
||||||
* or failed to detect the sensor.
|
|
||||||
*/
|
|
||||||
int
|
|
||||||
start_bus(int i2c_bus, int address)
|
|
||||||
{
|
|
||||||
int fd;
|
|
||||||
|
|
||||||
if (g_dev != nullptr) {
|
|
||||||
PX4_ERR("already started");
|
|
||||||
return PX4_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* create the driver, try the MS4525DO first */
|
|
||||||
g_dev = new MEASAirspeed(i2c_bus, address, PATH_MS4525);
|
|
||||||
|
|
||||||
/* check if the MS4525DO was instantiated */
|
|
||||||
if (g_dev == nullptr) {
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (OK != g_dev->init()) {
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* set the poll rate to default, starts automatic data collection */
|
|
||||||
fd = px4_open(PATH_MS4525, O_RDONLY);
|
|
||||||
|
|
||||||
if (fd < 0) {
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (px4_ioctl(fd, SENSORIOCSPOLLRATE, SENSOR_POLLRATE_DEFAULT) < 0) {
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
return PX4_OK;
|
|
||||||
|
|
||||||
fail:
|
|
||||||
|
|
||||||
if (g_dev != nullptr) {
|
|
||||||
delete g_dev;
|
|
||||||
g_dev = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
return PX4_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Stop the driver
|
|
||||||
*/
|
|
||||||
int
|
|
||||||
stop()
|
|
||||||
{
|
|
||||||
if (g_dev != nullptr) {
|
|
||||||
delete g_dev;
|
|
||||||
g_dev = nullptr;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
PX4_ERR("driver not running");
|
|
||||||
return PX4_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
return PX4_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reset the driver.
|
|
||||||
*/
|
|
||||||
int
|
|
||||||
reset()
|
|
||||||
{
|
|
||||||
int fd = px4_open(PATH_MS4525, O_RDONLY);
|
|
||||||
|
|
||||||
if (fd < 0) {
|
|
||||||
PX4_ERR("failed");
|
|
||||||
return PX4_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (px4_ioctl(fd, SENSORIOCRESET, 0) < 0) {
|
|
||||||
PX4_ERR("driver reset failed");
|
|
||||||
return PX4_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (px4_ioctl(fd, SENSORIOCSPOLLRATE, SENSOR_POLLRATE_DEFAULT) < 0) {
|
|
||||||
PX4_ERR("driver poll restart failed");
|
|
||||||
return PX4_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
return PX4_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
|
||||||
meas_airspeed_usage()
|
|
||||||
{
|
|
||||||
PX4_INFO("usage: ms4525 command [options]");
|
|
||||||
PX4_INFO("options:");
|
|
||||||
PX4_INFO("\t-b --bus i2cbus (%d)", PX4_I2C_BUS_DEFAULT);
|
|
||||||
PX4_INFO("\t-a --all");
|
|
||||||
PX4_INFO("command:");
|
|
||||||
PX4_INFO("\tstart|stop|reset");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
ms4525_airspeed_main(int argc, char *argv[])
|
ms4525_airspeed_main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int i2c_bus = PX4_I2C_BUS_DEFAULT;
|
|
||||||
|
|
||||||
int myoptind = 1;
|
|
||||||
int ch;
|
int ch;
|
||||||
const char *myoptarg = nullptr;
|
using ThisDriver = MEASAirspeed;
|
||||||
|
BusCLIArguments cli{true, false};
|
||||||
|
cli.default_i2c_frequency = 100000;
|
||||||
int device_type = DEVICE_TYPE_MS4525;
|
int device_type = DEVICE_TYPE_MS4525;
|
||||||
|
|
||||||
bool start_all = false;
|
while ((ch = cli.getopt(argc, argv, "T:")) != EOF) {
|
||||||
|
|
||||||
while ((ch = px4_getopt(argc, argv, "ab:T:", &myoptind, &myoptarg)) != EOF) {
|
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
case 'b':
|
|
||||||
i2c_bus = atoi(myoptarg);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'a':
|
|
||||||
start_all = true;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'T':
|
case 'T':
|
||||||
device_type = atoi(myoptarg);
|
device_type = atoi(cli.optarg());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
|
||||||
meas_airspeed_usage();
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (myoptind >= argc) {
|
const char *verb = cli.optarg();
|
||||||
meas_airspeed_usage();
|
|
||||||
|
if (!verb) {
|
||||||
|
ThisDriver::print_usage();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
if (device_type == DEVICE_TYPE_MS4525) {
|
||||||
* Start/load the driver.
|
cli.i2c_address = I2C_ADDRESS_MS4525DO;
|
||||||
*/
|
|
||||||
if (!strcmp(argv[myoptind], "start")) {
|
|
||||||
if (start_all) {
|
|
||||||
return meas_airspeed::start();
|
|
||||||
|
|
||||||
} else if (device_type == DEVICE_TYPE_MS4515) {
|
} else {
|
||||||
return meas_airspeed::start_bus(i2c_bus, I2C_ADDRESS_MS4515DO);
|
cli.i2c_address = I2C_ADDRESS_MS4515DO;
|
||||||
|
|
||||||
} else if (device_type == DEVICE_TYPE_MS4525) {
|
|
||||||
return meas_airspeed::start_bus(i2c_bus, I2C_ADDRESS_MS4525DO);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
BusInstanceIterator iterator(MODULE_NAME, cli,
|
||||||
* Stop the driver
|
DRV_DIFF_PRESS_DEVTYPE_MS4525);
|
||||||
*/
|
|
||||||
if (!strcmp(argv[myoptind], "stop")) {
|
if (!strcmp(verb, "start")) {
|
||||||
return meas_airspeed::stop();
|
return ThisDriver::module_start(cli, iterator);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
if (!strcmp(verb, "stop")) {
|
||||||
* Reset the driver.
|
return ThisDriver::module_stop(iterator);
|
||||||
*/
|
|
||||||
if (!strcmp(argv[myoptind], "reset")) {
|
|
||||||
return meas_airspeed::reset();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
meas_airspeed_usage();
|
if (!strcmp(verb, "status")) {
|
||||||
return 0;
|
return ThisDriver::module_status(iterator);
|
||||||
|
}
|
||||||
|
|
||||||
|
ThisDriver::print_usage();
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -269,7 +269,7 @@ MS5525::collect()
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
MS5525::Run()
|
MS5525::RunImpl()
|
||||||
{
|
{
|
||||||
int ret = PX4_ERROR;
|
int ret = PX4_ERROR;
|
||||||
|
|
||||||
@@ -280,8 +280,9 @@ MS5525::Run()
|
|||||||
|
|
||||||
if (OK != ret) {
|
if (OK != ret) {
|
||||||
/* restart the measurement state machine */
|
/* restart the measurement state machine */
|
||||||
start();
|
_collect_phase = false;
|
||||||
_sensor_ok = false;
|
_sensor_ok = false;
|
||||||
|
ScheduleNow();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,13 +31,14 @@
|
|||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#ifndef DRIVERS_MS5525_AIRSPEED_HPP_
|
#pragma once
|
||||||
#define DRIVERS_MS5525_AIRSPEED_HPP_
|
|
||||||
|
|
||||||
#include <drivers/airspeed/airspeed.h>
|
#include <drivers/airspeed/airspeed.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <mathlib/math/filter/LowPassFilter2p.hpp>
|
#include <mathlib/math/filter/LowPassFilter2p.hpp>
|
||||||
#include <px4_platform_common/getopt.h>
|
#include <px4_platform_common/getopt.h>
|
||||||
|
#include <px4_platform_common/module.h>
|
||||||
|
#include <px4_platform_common/i2c_spi_buses.h>
|
||||||
|
|
||||||
/* The MS5525DSO address is 111011Cx, where C is the complementary value of the pin CSB */
|
/* The MS5525DSO address is 111011Cx, where C is the complementary value of the pin CSB */
|
||||||
static constexpr uint8_t I2C_ADDRESS_1_MS5525DSO = 0x76;
|
static constexpr uint8_t I2C_ADDRESS_1_MS5525DSO = 0x76;
|
||||||
@@ -49,24 +50,26 @@ static constexpr unsigned MEAS_RATE = 100;
|
|||||||
static constexpr float MEAS_DRIVER_FILTER_FREQ = 1.2f;
|
static constexpr float MEAS_DRIVER_FILTER_FREQ = 1.2f;
|
||||||
static constexpr int64_t CONVERSION_INTERVAL = (1000000 / MEAS_RATE); /* microseconds */
|
static constexpr int64_t CONVERSION_INTERVAL = (1000000 / MEAS_RATE); /* microseconds */
|
||||||
|
|
||||||
class MS5525 : public Airspeed
|
class MS5525 : public Airspeed, public I2CSPIDriver<MS5525>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MS5525(uint8_t bus, uint8_t address = I2C_ADDRESS_1_MS5525DSO, const char *path = PATH_MS5525) :
|
MS5525(I2CSPIBusOption bus_option, const int bus, int bus_frequency, int address = I2C_ADDRESS_1_MS5525DSO,
|
||||||
Airspeed(bus, address, CONVERSION_INTERVAL, path)
|
const char *path = PATH_MS5525) :
|
||||||
|
Airspeed(bus, bus_frequency, address, CONVERSION_INTERVAL, path),
|
||||||
|
I2CSPIDriver(MODULE_NAME, px4::device_bus_to_wq(get_device_id()), bus_option, bus, address)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
~MS5525() override = default;
|
virtual ~MS5525() = default;
|
||||||
|
|
||||||
|
static I2CSPIDriverBase *instantiate(const BusCLIArguments &cli, const BusInstanceIterator &iterator,
|
||||||
|
int runtime_instance);
|
||||||
|
static void print_usage();
|
||||||
|
|
||||||
|
void RunImpl();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
/**
|
|
||||||
* Perform a poll cycle; collect from the previous measurement
|
|
||||||
* and start a new one.
|
|
||||||
*/
|
|
||||||
void Run() override;
|
|
||||||
|
|
||||||
int measure() override;
|
int measure() override;
|
||||||
int collect() override;
|
int collect() override;
|
||||||
|
|
||||||
@@ -127,5 +130,3 @@ private:
|
|||||||
uint8_t prom_crc4(uint16_t n_prom[]) const;
|
uint8_t prom_crc4(uint16_t n_prom[]) const;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* DRIVERS_MS5525_AIRSPEED_HPP_ */
|
|
||||||
|
|||||||
@@ -33,199 +33,66 @@
|
|||||||
|
|
||||||
#include "MS5525.hpp"
|
#include "MS5525.hpp"
|
||||||
|
|
||||||
// Driver 'main' command.
|
|
||||||
extern "C" __EXPORT int ms5525_airspeed_main(int argc, char *argv[]);
|
extern "C" __EXPORT int ms5525_airspeed_main(int argc, char *argv[]);
|
||||||
|
|
||||||
// Local functions in support of the shell command.
|
I2CSPIDriverBase *MS5525::instantiate(const BusCLIArguments &cli, const BusInstanceIterator &iterator,
|
||||||
namespace ms5525_airspeed
|
int runtime_instance)
|
||||||
{
|
{
|
||||||
MS5525 *g_dev = nullptr;
|
MS5525 *instance = new MS5525(iterator.configuredBusOption(), iterator.bus(), cli.bus_frequency);
|
||||||
|
|
||||||
int start();
|
if (instance == nullptr) {
|
||||||
int start_bus(uint8_t i2c_bus);
|
PX4_ERR("alloc failed");
|
||||||
int stop();
|
return nullptr;
|
||||||
int reset();
|
}
|
||||||
|
|
||||||
/**
|
if (instance->init() != PX4_OK) {
|
||||||
* Attempt to start driver on all available I2C busses.
|
delete instance;
|
||||||
*
|
return nullptr;
|
||||||
* This function will return as soon as the first sensor
|
}
|
||||||
* is detected on one of the available busses or if no
|
|
||||||
* sensors are detected.
|
instance->ScheduleNow();
|
||||||
*
|
return instance;
|
||||||
*/
|
}
|
||||||
int
|
|
||||||
start()
|
|
||||||
|
void
|
||||||
|
MS5525::print_usage()
|
||||||
{
|
{
|
||||||
for (unsigned i = 0; i < NUM_I2C_BUS_OPTIONS; i++) {
|
PRINT_MODULE_USAGE_NAME("ms5525_airspeed", "driver");
|
||||||
if (start_bus(i2c_bus_options[i]) == PX4_OK) {
|
PRINT_MODULE_USAGE_COMMAND("start");
|
||||||
return PX4_OK;
|
PRINT_MODULE_USAGE_PARAMS_I2C_SPI_DRIVER(true, false);
|
||||||
}
|
PRINT_MODULE_USAGE_DEFAULT_COMMANDS();
|
||||||
}
|
|
||||||
|
|
||||||
return PX4_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Start the driver on a specific bus.
|
|
||||||
*
|
|
||||||
* This function call only returns once the driver is up and running
|
|
||||||
* or failed to detect the sensor.
|
|
||||||
*/
|
|
||||||
int
|
|
||||||
start_bus(uint8_t i2c_bus)
|
|
||||||
{
|
|
||||||
int fd = -1;
|
|
||||||
|
|
||||||
if (g_dev != nullptr) {
|
|
||||||
PX4_ERR("already started");
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
g_dev = new MS5525(i2c_bus, I2C_ADDRESS_1_MS5525DSO, PATH_MS5525);
|
|
||||||
|
|
||||||
/* check if the MS4525DO was instantiated */
|
|
||||||
if (g_dev == nullptr) {
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* try to initialize */
|
|
||||||
if (g_dev->init() != PX4_OK) {
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* set the poll rate to default, starts automatic data collection */
|
|
||||||
fd = px4_open(PATH_MS5525, O_RDONLY);
|
|
||||||
|
|
||||||
if (fd < 0) {
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (px4_ioctl(fd, SENSORIOCSPOLLRATE, SENSOR_POLLRATE_DEFAULT) < 0) {
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
return PX4_OK;
|
|
||||||
|
|
||||||
fail:
|
|
||||||
|
|
||||||
if (g_dev != nullptr) {
|
|
||||||
delete g_dev;
|
|
||||||
g_dev = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
return PX4_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
// stop the driver
|
|
||||||
int stop()
|
|
||||||
{
|
|
||||||
if (g_dev != nullptr) {
|
|
||||||
delete g_dev;
|
|
||||||
g_dev = nullptr;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
PX4_ERR("driver not running");
|
|
||||||
return PX4_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
return PX4_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
// reset the driver
|
|
||||||
int reset()
|
|
||||||
{
|
|
||||||
int fd = px4_open(PATH_MS5525, O_RDONLY);
|
|
||||||
|
|
||||||
if (fd < 0) {
|
|
||||||
PX4_ERR("failed ");
|
|
||||||
return PX4_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (px4_ioctl(fd, SENSORIOCRESET, 0) < 0) {
|
|
||||||
PX4_ERR("driver reset failed");
|
|
||||||
return PX4_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (px4_ioctl(fd, SENSORIOCSPOLLRATE, SENSOR_POLLRATE_DEFAULT) < 0) {
|
|
||||||
PX4_ERR("driver poll restart failed");
|
|
||||||
return PX4_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
return PX4_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace ms5525_airspeed
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
|
||||||
ms5525_airspeed_usage()
|
|
||||||
{
|
|
||||||
PX4_INFO("usage: ms5525_airspeed command [options]");
|
|
||||||
PX4_INFO("options:");
|
|
||||||
PX4_INFO("\t-b --bus i2cbus (%d)", PX4_I2C_BUS_DEFAULT);
|
|
||||||
PX4_INFO("\t-a --all");
|
|
||||||
PX4_INFO("command:");
|
|
||||||
PX4_INFO("\tstart|stop|reset");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
ms5525_airspeed_main(int argc, char *argv[])
|
ms5525_airspeed_main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
uint8_t i2c_bus = PX4_I2C_BUS_DEFAULT;
|
using ThisDriver = MS5525;
|
||||||
|
BusCLIArguments cli{true, false};
|
||||||
|
cli.default_i2c_frequency = 100000;
|
||||||
|
|
||||||
int myoptind = 1;
|
const char *verb = cli.parseDefaultArguments(argc, argv);
|
||||||
int ch;
|
|
||||||
const char *myoptarg = nullptr;
|
|
||||||
bool start_all = false;
|
|
||||||
|
|
||||||
while ((ch = px4_getopt(argc, argv, "ab:", &myoptind, &myoptarg)) != EOF) {
|
if (!verb) {
|
||||||
switch (ch) {
|
ThisDriver::print_usage();
|
||||||
case 'b':
|
|
||||||
i2c_bus = atoi(myoptarg);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'a':
|
|
||||||
start_all = true;
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
ms5525_airspeed_usage();
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (myoptind >= argc) {
|
|
||||||
ms5525_airspeed_usage();
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
BusInstanceIterator iterator(MODULE_NAME, cli,
|
||||||
* Start/load the driver.
|
DRV_DIFF_PRESS_DEVTYPE_MS5525);
|
||||||
*/
|
|
||||||
if (!strcmp(argv[myoptind], "start")) {
|
|
||||||
if (start_all) {
|
|
||||||
return ms5525_airspeed::start();
|
|
||||||
|
|
||||||
} else {
|
if (!strcmp(verb, "start")) {
|
||||||
return ms5525_airspeed::start_bus(i2c_bus);
|
return ThisDriver::module_start(cli, iterator);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
if (!strcmp(verb, "stop")) {
|
||||||
* Stop the driver
|
return ThisDriver::module_stop(iterator);
|
||||||
*/
|
|
||||||
if (!strcmp(argv[myoptind], "stop")) {
|
|
||||||
return ms5525_airspeed::stop();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
if (!strcmp(verb, "status")) {
|
||||||
* Reset the driver.
|
return ThisDriver::module_status(iterator);
|
||||||
*/
|
|
||||||
if (!strcmp(argv[myoptind], "reset")) {
|
|
||||||
return ms5525_airspeed::reset();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ms5525_airspeed_usage();
|
ThisDriver::print_usage();
|
||||||
return 0;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -166,7 +166,7 @@ SDP3X::collect()
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
SDP3X::Run()
|
SDP3X::RunImpl()
|
||||||
{
|
{
|
||||||
int ret = PX4_ERROR;
|
int ret = PX4_ERROR;
|
||||||
|
|
||||||
|
|||||||
@@ -39,13 +39,14 @@
|
|||||||
* Datasheet: https://www.sensirion.com/fileadmin/user_upload/customers/sensirion/Dokumente/8_Differential_Pressure/Sensirion_Differential_Pressure_Sensors_SDP3x_Digital_Datasheet_V0.8.pdf
|
* Datasheet: https://www.sensirion.com/fileadmin/user_upload/customers/sensirion/Dokumente/8_Differential_Pressure/Sensirion_Differential_Pressure_Sensors_SDP3x_Digital_Datasheet_V0.8.pdf
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef DRIVERS_SDP3X_AIRSPEED_HPP_
|
#pragma once
|
||||||
#define DRIVERS_SDP3X_AIRSPEED_HPP_
|
|
||||||
|
|
||||||
#include <drivers/airspeed/airspeed.h>
|
#include <drivers/airspeed/airspeed.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <mathlib/math/filter/LowPassFilter2p.hpp>
|
#include <mathlib/math/filter/LowPassFilter2p.hpp>
|
||||||
#include <px4_platform_common/getopt.h>
|
#include <px4_platform_common/getopt.h>
|
||||||
|
#include <px4_platform_common/module.h>
|
||||||
|
#include <px4_platform_common/i2c_spi_buses.h>
|
||||||
|
|
||||||
#define I2C_ADDRESS_1_SDP3X 0x21
|
#define I2C_ADDRESS_1_SDP3X 0x21
|
||||||
#define I2C_ADDRESS_2_SDP3X 0x22
|
#define I2C_ADDRESS_2_SDP3X 0x22
|
||||||
@@ -67,21 +68,26 @@
|
|||||||
#define SDP3X_MEAS_DRIVER_FILTER_FREQ 3.0f
|
#define SDP3X_MEAS_DRIVER_FILTER_FREQ 3.0f
|
||||||
#define CONVERSION_INTERVAL (1000000 / SPD3X_MEAS_RATE) /* microseconds */
|
#define CONVERSION_INTERVAL (1000000 / SPD3X_MEAS_RATE) /* microseconds */
|
||||||
|
|
||||||
class SDP3X : public Airspeed
|
class SDP3X : public Airspeed, public I2CSPIDriver<SDP3X>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SDP3X(int bus, int address = I2C_ADDRESS_1_SDP3X, const char *path = PATH_SDP3X) :
|
SDP3X(I2CSPIBusOption bus_option, const int bus, int bus_frequency, int address = I2C_ADDRESS_1_SDP3X,
|
||||||
Airspeed(bus, address, CONVERSION_INTERVAL, path)
|
const char *path = PATH_SDP3X) :
|
||||||
|
Airspeed(bus, bus_frequency, address, CONVERSION_INTERVAL, path),
|
||||||
|
I2CSPIDriver(MODULE_NAME, px4::device_bus_to_wq(get_device_id()), bus_option, bus, address)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual ~SDP3X() = default;
|
||||||
|
|
||||||
|
static I2CSPIDriverBase *instantiate(const BusCLIArguments &cli, const BusInstanceIterator &iterator,
|
||||||
|
int runtime_instance);
|
||||||
|
static void print_usage();
|
||||||
|
|
||||||
|
void RunImpl();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
/**
|
|
||||||
* Perform a poll cycle; collect from the previous measurement
|
|
||||||
* and start a new one.
|
|
||||||
*/
|
|
||||||
void Run() override;
|
|
||||||
int measure() override { return 0; }
|
int measure() override { return 0; }
|
||||||
int collect() override;
|
int collect() override;
|
||||||
int probe() override;
|
int probe() override;
|
||||||
@@ -102,5 +108,3 @@ private:
|
|||||||
|
|
||||||
uint16_t _scale{0};
|
uint16_t _scale{0};
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* DRIVERS_SDP3X_AIRSPEED_HPP_ */
|
|
||||||
|
|||||||
@@ -33,213 +33,67 @@
|
|||||||
|
|
||||||
#include "SDP3X.hpp"
|
#include "SDP3X.hpp"
|
||||||
|
|
||||||
// Driver 'main' command.
|
|
||||||
extern "C" __EXPORT int sdp3x_airspeed_main(int argc, char *argv[]);
|
extern "C" __EXPORT int sdp3x_airspeed_main(int argc, char *argv[]);
|
||||||
|
|
||||||
// Local functions in support of the shell command.
|
I2CSPIDriverBase *SDP3X::instantiate(const BusCLIArguments &cli, const BusInstanceIterator &iterator,
|
||||||
namespace sdp3x_airspeed
|
int runtime_instance)
|
||||||
{
|
{
|
||||||
SDP3X *g_dev = nullptr;
|
SDP3X *instance = new SDP3X(iterator.configuredBusOption(), iterator.bus(), cli.bus_frequency, cli.i2c_address);
|
||||||
|
|
||||||
int start();
|
if (instance == nullptr) {
|
||||||
int start_bus(uint8_t i2c_bus);
|
PX4_ERR("alloc failed");
|
||||||
int stop();
|
return nullptr;
|
||||||
int reset();
|
}
|
||||||
|
|
||||||
/**
|
if (instance->init() != PX4_OK) {
|
||||||
* Attempt to start driver on all available I2C busses.
|
delete instance;
|
||||||
*
|
return nullptr;
|
||||||
* This function will return as soon as the first sensor
|
}
|
||||||
* is detected on one of the available busses or if no
|
|
||||||
* sensors are detected.
|
instance->ScheduleNow();
|
||||||
*
|
return instance;
|
||||||
*/
|
}
|
||||||
int
|
|
||||||
start()
|
|
||||||
|
void
|
||||||
|
SDP3X::print_usage()
|
||||||
{
|
{
|
||||||
for (unsigned i = 0; i < NUM_I2C_BUS_OPTIONS; i++) {
|
PRINT_MODULE_USAGE_NAME("sdp3x_airspeed", "driver");
|
||||||
if (start_bus(i2c_bus_options[i]) == PX4_OK) {
|
PRINT_MODULE_USAGE_COMMAND("start");
|
||||||
return PX4_OK;
|
PRINT_MODULE_USAGE_PARAMS_I2C_SPI_DRIVER(true, false);
|
||||||
}
|
PRINT_MODULE_USAGE_PARAMS_I2C_ADDRESS(0x21);
|
||||||
}
|
PRINT_MODULE_USAGE_DEFAULT_COMMANDS();
|
||||||
|
|
||||||
return PX4_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Start the driver on a specific bus.
|
|
||||||
*
|
|
||||||
* This function call only returns once the driver is up and running
|
|
||||||
* or failed to detect the sensor.
|
|
||||||
*/
|
|
||||||
int
|
|
||||||
start_bus(uint8_t i2c_bus)
|
|
||||||
{
|
|
||||||
int fd = -1;
|
|
||||||
|
|
||||||
if (g_dev != nullptr) {
|
|
||||||
PX4_WARN("already started");
|
|
||||||
return PX4_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
g_dev = new SDP3X(i2c_bus, I2C_ADDRESS_1_SDP3X, PATH_SDP3X);
|
|
||||||
|
|
||||||
/* check if the SDP3XDSO was instantiated */
|
|
||||||
if (g_dev == nullptr) {
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* try the next SDP3XDSO if init fails */
|
|
||||||
if (g_dev->init() != PX4_OK) {
|
|
||||||
delete g_dev;
|
|
||||||
|
|
||||||
g_dev = new SDP3X(i2c_bus, I2C_ADDRESS_2_SDP3X, PATH_SDP3X);
|
|
||||||
|
|
||||||
/* check if the SDP3XDSO was instantiated */
|
|
||||||
if (g_dev == nullptr) {
|
|
||||||
PX4_ERR("SDP3X was not instantiated (RAM)");
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* both versions failed if the init for the SDP3XDSO fails, give up */
|
|
||||||
if (g_dev->init() != PX4_OK) {
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* set the poll rate to default, starts automatic data collection */
|
|
||||||
fd = px4_open(PATH_SDP3X, O_RDONLY);
|
|
||||||
|
|
||||||
if (fd < 0) {
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (px4_ioctl(fd, SENSORIOCSPOLLRATE, SENSOR_POLLRATE_DEFAULT) < 0) {
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
return PX4_OK;
|
|
||||||
|
|
||||||
fail:
|
|
||||||
|
|
||||||
if (g_dev != nullptr) {
|
|
||||||
delete g_dev;
|
|
||||||
g_dev = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
return PX4_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
// stop the driver
|
|
||||||
int stop()
|
|
||||||
{
|
|
||||||
if (g_dev != nullptr) {
|
|
||||||
delete g_dev;
|
|
||||||
g_dev = nullptr;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
PX4_ERR("driver not running");
|
|
||||||
return PX4_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
return PX4_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
// reset the driver
|
|
||||||
int reset()
|
|
||||||
{
|
|
||||||
int fd = px4_open(PATH_SDP3X, O_RDONLY);
|
|
||||||
|
|
||||||
if (fd < 0) {
|
|
||||||
PX4_ERR("failed ");
|
|
||||||
return PX4_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (px4_ioctl(fd, SENSORIOCRESET, 0) < 0) {
|
|
||||||
PX4_ERR("driver reset failed");
|
|
||||||
return PX4_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (px4_ioctl(fd, SENSORIOCSPOLLRATE, SENSOR_POLLRATE_DEFAULT) < 0) {
|
|
||||||
PX4_ERR("driver poll restart failed");
|
|
||||||
return PX4_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
return PX4_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace sdp3x_airspeed
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
|
||||||
sdp3x_airspeed_usage()
|
|
||||||
{
|
|
||||||
PX4_INFO("usage: sdp3x_airspeed command [options]");
|
|
||||||
PX4_INFO("options:");
|
|
||||||
PX4_INFO("\t-b --bus i2cbus (%d)", PX4_I2C_BUS_DEFAULT);
|
|
||||||
PX4_INFO("\t-a --all");
|
|
||||||
PX4_INFO("command:");
|
|
||||||
PX4_INFO("\tstart|stop|reset");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
sdp3x_airspeed_main(int argc, char *argv[])
|
sdp3x_airspeed_main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
uint8_t i2c_bus = PX4_I2C_BUS_DEFAULT;
|
using ThisDriver = SDP3X;
|
||||||
|
BusCLIArguments cli{true, false};
|
||||||
|
cli.default_i2c_frequency = 100000;
|
||||||
|
cli.i2c_address = I2C_ADDRESS_1_SDP3X;
|
||||||
|
|
||||||
int myoptind = 1;
|
const char *verb = cli.parseDefaultArguments(argc, argv);
|
||||||
int ch;
|
|
||||||
const char *myoptarg = nullptr;
|
|
||||||
bool start_all = false;
|
|
||||||
|
|
||||||
while ((ch = px4_getopt(argc, argv, "ab:", &myoptind, &myoptarg)) != EOF) {
|
if (!verb) {
|
||||||
switch (ch) {
|
ThisDriver::print_usage();
|
||||||
case 'b':
|
|
||||||
i2c_bus = atoi(myoptarg);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'a':
|
|
||||||
start_all = true;
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
sdp3x_airspeed_usage();
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (myoptind >= argc) {
|
|
||||||
sdp3x_airspeed_usage();
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BusInstanceIterator iterator(MODULE_NAME, cli, DRV_DIFF_PRESS_DEVTYPE_SDP31);
|
||||||
|
|
||||||
/*
|
if (!strcmp(verb, "start")) {
|
||||||
* Start/load the driver.
|
return ThisDriver::module_start(cli, iterator);
|
||||||
*/
|
|
||||||
if (!strcmp(argv[myoptind], "start")) {
|
|
||||||
if (start_all) {
|
|
||||||
return sdp3x_airspeed::start();
|
|
||||||
|
|
||||||
} else {
|
|
||||||
return sdp3x_airspeed::start_bus(i2c_bus);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
if (!strcmp(verb, "stop")) {
|
||||||
* Stop the driver
|
return ThisDriver::module_stop(iterator);
|
||||||
*/
|
|
||||||
if (!strcmp(argv[myoptind], "stop")) {
|
|
||||||
return sdp3x_airspeed::stop();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
if (!strcmp(verb, "status")) {
|
||||||
* Reset the driver.
|
return ThisDriver::module_status(iterator);
|
||||||
*/
|
|
||||||
if (!strcmp(argv[myoptind], "reset")) {
|
|
||||||
return sdp3x_airspeed::reset();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sdp3x_airspeed_usage();
|
ThisDriver::print_usage();
|
||||||
return 0;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,11 +56,10 @@
|
|||||||
|
|
||||||
#include <drivers/airspeed/airspeed.h>
|
#include <drivers/airspeed/airspeed.h>
|
||||||
|
|
||||||
Airspeed::Airspeed(int bus, int address, unsigned conversion_interval, const char *path) :
|
Airspeed::Airspeed(int bus, int bus_frequency, int address, unsigned conversion_interval, const char *path) :
|
||||||
I2C("Airspeed", path, bus, address, 100000),
|
I2C("Airspeed", path, bus, address, bus_frequency),
|
||||||
ScheduledWorkItem(MODULE_NAME, px4::device_bus_to_wq(get_device_id())),
|
|
||||||
_sensor_ok(false),
|
_sensor_ok(false),
|
||||||
_measure_interval(0),
|
_measure_interval(conversion_interval),
|
||||||
_collect_phase(false),
|
_collect_phase(false),
|
||||||
_diff_pres_offset(0.0f),
|
_diff_pres_offset(0.0f),
|
||||||
_airspeed_orb_class_instance(-1),
|
_airspeed_orb_class_instance(-1),
|
||||||
@@ -73,9 +72,6 @@ Airspeed::Airspeed(int bus, int address, unsigned conversion_interval, const cha
|
|||||||
|
|
||||||
Airspeed::~Airspeed()
|
Airspeed::~Airspeed()
|
||||||
{
|
{
|
||||||
/* make sure we are truly inactive */
|
|
||||||
stop();
|
|
||||||
|
|
||||||
if (_class_instance != -1) {
|
if (_class_instance != -1) {
|
||||||
unregister_class_devname(AIRSPEED_BASE_DEVICE_PATH, _class_instance);
|
unregister_class_devname(AIRSPEED_BASE_DEVICE_PATH, _class_instance);
|
||||||
}
|
}
|
||||||
@@ -121,57 +117,6 @@ int
|
|||||||
Airspeed::ioctl(device::file_t *filp, int cmd, unsigned long arg)
|
Airspeed::ioctl(device::file_t *filp, int cmd, unsigned long arg)
|
||||||
{
|
{
|
||||||
switch (cmd) {
|
switch (cmd) {
|
||||||
|
|
||||||
case SENSORIOCSPOLLRATE: {
|
|
||||||
switch (arg) {
|
|
||||||
|
|
||||||
/* zero would be bad */
|
|
||||||
case 0:
|
|
||||||
return -EINVAL;
|
|
||||||
|
|
||||||
/* set default polling rate */
|
|
||||||
case SENSOR_POLLRATE_DEFAULT: {
|
|
||||||
/* do we need to start internal polling? */
|
|
||||||
bool want_start = (_measure_interval == 0);
|
|
||||||
|
|
||||||
/* set interval for next measurement to minimum legal value */
|
|
||||||
_measure_interval = USEC2TICK(_conversion_interval);
|
|
||||||
|
|
||||||
/* if we need to start the poll state machine, do it */
|
|
||||||
if (want_start) {
|
|
||||||
start();
|
|
||||||
}
|
|
||||||
|
|
||||||
return OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* adjust to a legal polling interval in Hz */
|
|
||||||
default: {
|
|
||||||
/* do we need to start internal polling? */
|
|
||||||
bool want_start = (_measure_interval == 0);
|
|
||||||
|
|
||||||
/* convert hz to tick interval via microseconds */
|
|
||||||
unsigned interval = (1000000 / arg);
|
|
||||||
|
|
||||||
/* check against maximum rate */
|
|
||||||
if (interval < _conversion_interval) {
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* update interval for next measurement */
|
|
||||||
_measure_interval = interval;
|
|
||||||
|
|
||||||
/* if we need to start the poll state machine, do it */
|
|
||||||
if (want_start) {
|
|
||||||
start();
|
|
||||||
}
|
|
||||||
|
|
||||||
return OK;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case AIRSPEEDIOCSSCALE: {
|
case AIRSPEEDIOCSSCALE: {
|
||||||
struct airspeed_scale *s = (struct airspeed_scale *)arg;
|
struct airspeed_scale *s = (struct airspeed_scale *)arg;
|
||||||
_diff_pres_offset = s->offset_pa;
|
_diff_pres_offset = s->offset_pa;
|
||||||
@@ -184,18 +129,3 @@ Airspeed::ioctl(device::file_t *filp, int cmd, unsigned long arg)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
Airspeed::start()
|
|
||||||
{
|
|
||||||
/* reset the report ring and state machine */
|
|
||||||
_collect_phase = false;
|
|
||||||
|
|
||||||
/* schedule a cycle to start things */
|
|
||||||
ScheduleNow();
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
Airspeed::stop()
|
|
||||||
{
|
|
||||||
ScheduleClear();
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -42,34 +42,28 @@
|
|||||||
#include <perf/perf_counter.h>
|
#include <perf/perf_counter.h>
|
||||||
#include <uORB/topics/differential_pressure.h>
|
#include <uORB/topics/differential_pressure.h>
|
||||||
#include <uORB/PublicationMulti.hpp>
|
#include <uORB/PublicationMulti.hpp>
|
||||||
#include <px4_platform_common/px4_work_queue/ScheduledWorkItem.hpp>
|
|
||||||
|
|
||||||
/* Default I2C bus */
|
class __EXPORT Airspeed : public device::I2C
|
||||||
static constexpr uint8_t PX4_I2C_BUS_DEFAULT = PX4_I2C_BUS_EXPANSION;
|
|
||||||
|
|
||||||
class __EXPORT Airspeed : public device::I2C, public px4::ScheduledWorkItem
|
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Airspeed(int bus, int address, unsigned conversion_interval, const char *path);
|
Airspeed(int bus, int bus_frequency, int address, unsigned conversion_interval, const char *path);
|
||||||
virtual ~Airspeed();
|
virtual ~Airspeed();
|
||||||
|
|
||||||
virtual int init();
|
int init() override;
|
||||||
|
|
||||||
virtual int ioctl(device::file_t *filp, int cmd, unsigned long arg);
|
int ioctl(device::file_t *filp, int cmd, unsigned long arg) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/* this class has pointer data members and should not be copied */
|
Airspeed(const Airspeed &) = delete;
|
||||||
Airspeed(const Airspeed &);
|
Airspeed &operator=(const Airspeed &) = delete;
|
||||||
Airspeed &operator=(const Airspeed &);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual int probe();
|
int probe() override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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.
|
||||||
*/
|
*/
|
||||||
virtual void Run() = 0;
|
|
||||||
virtual int measure() = 0;
|
virtual int measure() = 0;
|
||||||
virtual int collect() = 0;
|
virtual int collect() = 0;
|
||||||
|
|
||||||
@@ -88,26 +82,6 @@ protected:
|
|||||||
|
|
||||||
perf_counter_t _sample_perf;
|
perf_counter_t _sample_perf;
|
||||||
perf_counter_t _comms_errors;
|
perf_counter_t _comms_errors;
|
||||||
|
|
||||||
/**
|
|
||||||
* Initialise the automatic measurement state machine and start it.
|
|
||||||
*
|
|
||||||
* @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.
|
|
||||||
*/
|
|
||||||
void start();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Stop the automatic measurement state machine.
|
|
||||||
*/
|
|
||||||
void stop();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* add a new report to the reports queue
|
|
||||||
*
|
|
||||||
* @param report differential_pressure_s report
|
|
||||||
*/
|
|
||||||
void new_report(const differential_pressure_s &report);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user