53 #include <px4_platform_common/getopt.h> 64 #define I2C_ADDRESS_MS4515DO 0x46 65 #define I2C_ADDRESS_MS4525DO 0x28 66 #define PATH_MS4525 "/dev/ms4525" 69 #define ADDR_READ_MR 0x00 73 #define MEAS_DRIVER_FILTER_FREQ 1.2f 74 #define CONVERSION_INTERVAL (1000000 / MEAS_RATE) 118 int ret = transfer(&cmd, 1,
nullptr, 0);
131 uint8_t val[4] = {0, 0, 0, 0};
135 int ret = transfer(
nullptr, 0, &val[0], 4);
143 uint8_t
status = (val[0] & 0xC0) >> 6;
165 int16_t dp_raw = 0, dT_raw = 0;
166 dp_raw = (val[0] << 8) + val[1];
168 dp_raw = 0x3FFF & dp_raw;
169 dT_raw = (val[2] << 8) + val[3];
170 dT_raw = (0xFFE0 & dT_raw) >> 5;
173 if (dT_raw == 2047) {
178 float temperature = ((200.0f * dT_raw) / 2047) - 50;
182 const float P_min = -1.0f;
183 const float P_max = 1.0f;
184 const float PSI_to_Pa = 6894.757f;
193 float diff_press_PSI = -((dp_raw - 0.1f * 16383) * (P_max - P_min) / (0.8f * 16383) + P_min);
194 float diff_press_pa_raw = diff_press_PSI * PSI_to_Pa;
285 #if defined(ADC_SCALED_V5_SENSE) 296 bool updated =
false;
308 const float slope = 65.0f;
314 if (voltage_diff > 0.5
f) {
318 if (voltage_diff < -0.5
f) {
319 voltage_diff = -0.5f;
322 diff_press_pa -= voltage_diff * slope;
327 const float temp_slope = 0.887f;
330 if (voltage_diff > 0.5
f) {
334 if (voltage_diff < -1.0
f) {
335 voltage_diff = -1.0f;
338 temperature -= voltage_diff * temp_slope;
339 #endif // defined(ADC_SCALED_V5_SENSE) 387 if (g_dev !=
nullptr) {
388 PX4_ERR(
"already started");
396 if (g_dev ==
nullptr) {
400 if (
OK != g_dev->
init()) {
419 if (g_dev !=
nullptr) {
433 if (g_dev !=
nullptr) {
438 PX4_ERR(
"driver not running");
459 PX4_ERR(
"driver reset failed");
464 PX4_ERR(
"driver poll restart failed");
477 PX4_INFO(
"usage: ms4525 command [options]");
478 PX4_INFO(
"options:");
480 PX4_INFO(
"\t-a --all");
481 PX4_INFO(
"command:");
482 PX4_INFO(
"\tstart|stop|reset");
492 const char *myoptarg =
nullptr;
496 bool start_all =
false;
498 while ((ch = px4_getopt(argc, argv,
"ab:T:", &myoptind, &myoptarg)) != EOF) {
501 i2c_bus = atoi(myoptarg);
509 device_type = atoi(myoptarg);
518 if (myoptind >= argc) {
526 if (!strcmp(argv[myoptind],
"start")) {
541 if (!strcmp(argv[myoptind],
"stop")) {
548 if (!strcmp(argv[myoptind],
"reset")) {
orb_advert_t _airspeed_pub
#define I2C_ADDRESS_MS4515DO
int orb_copy(const struct orb_metadata *meta, int handle, void *buffer)
void stop()
Stop the automatic measurement state machine.
static struct vehicle_status_s status
__EXPORT int ms4525_airspeed_main(int argc, char *argv[])
float differential_pressure_raw_pa
#define MEAS_DRIVER_FILTER_FREQ
#define SENSOR_POLLRATE_DEFAULT
poll at driver normal rate
static void meas_airspeed_usage()
int stop()
Stop the driver.
int start()
Attempt to start driver on all available I2C busses.
int start_bus(int i2c_bus, int address)
Start the driver on a specific bus.
#define CONVERSION_INTERVAL
system_power_s system_power
#define SENSORIOCSPOLLRATE
Set the driver polling rate to (arg) Hz, or one of the SENSOR_POLLRATE constants. ...
int orb_subscribe(const struct orb_metadata *meta)
static constexpr uint8_t PX4_I2C_BUS_DEFAULT
#define ORB_ID(_name)
Generates a pointer to the uORB metadata structure for a given topic.
void perf_count(perf_counter_t handle)
Count a performance event.
Vector< float, 6 > f(float t, const Matrix< float, 6, 1 > &, const Matrix< float, 3, 1 > &)
perf_counter_t _sample_perf
void Run() override
Perform a poll cycle; collect from the previous measurement and start a new one.
void perf_end(perf_counter_t handle)
End a performance event.
#define I2C_ADDRESS_MS4525DO
7-bit address.
int orb_publish(const struct orb_metadata *meta, orb_advert_t handle, const void *data)
static const int i2c_bus_options[]
math::LowPassFilter2p _filter
MEASAirspeed(int bus, int address=I2C_ADDRESS_MS4525DO, const char *path=PATH_MS4525)
int reset()
Reset the driver.
#define DRV_DIFF_PRESS_DEVTYPE_MS4525
float apply(float sample)
Add a new raw value to the filter.
int orb_check(int handle, bool *updated)
#define SENSORIOCRESET
Reset the sensor to its default configuration.
uint64_t perf_event_count(perf_counter_t handle)
Return current event_count.
Local functions in support of the shell command.
#define NUM_I2C_BUS_OPTIONS
void voltage_correction(float &diff_pres_pa, float &temperature)
Correct for 5V rail voltage variations.
float differential_pressure_filtered_pa
void perf_begin(perf_counter_t handle)
Begin a performance event.
#define DEVICE_DEBUG(FMT,...)
perf_counter_t _comms_errors
__EXPORT hrt_abstime hrt_absolute_time(void)
Get absolute time in [us] (does not wrap).
void start()
Initialise the automatic measurement state machine and start it.