PX4 Firmware
PX4 Autopilot Software http://px4.io
sensors.cpp
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * Copyright (c) 2012-2018 PX4 Development Team. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in
13  * the documentation and/or other materials provided with the
14  * distribution.
15  * 3. Neither the name PX4 nor the names of its contributors may be
16  * used to endorse or promote products derived from this software
17  * without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
26  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  *
32  ****************************************************************************/
33 
34 /**
35  * @file sensors.cpp
36  *
37  * @author Lorenz Meier <lorenz@px4.io>
38  * @author Julian Oes <julian@oes.ch>
39  * @author Thomas Gubler <thomas@px4.io>
40  * @author Anton Babushkin <anton@px4.io>
41  * @author Beat Küng <beat-kueng@gmx.net>
42  */
43 
44 #include <drivers/drv_adc.h>
45 #include <drivers/drv_airspeed.h>
46 #include <drivers/drv_hrt.h>
47 #include <lib/airspeed/airspeed.h>
49 #include <lib/mathlib/mathlib.h>
50 #include <lib/parameters/param.h>
51 #include <lib/perf/perf_counter.h>
52 #include <px4_platform_common/getopt.h>
53 #include <px4_platform_common/module.h>
54 #include <px4_platform_common/module_params.h>
55 #include <px4_platform_common/posix.h>
56 #include <px4_platform_common/px4_config.h>
57 #include <px4_platform_common/tasks.h>
58 #include <px4_platform_common/time.h>
59 #include <uORB/Publication.hpp>
61 #include <uORB/Subscription.hpp>
63 #include <uORB/topics/airspeed.h>
70 
71 #include <DevMgr.hpp>
72 
73 #include "parameters.h"
74 #include "voted_sensors_update.h"
75 
78 
79 using namespace DriverFramework;
80 using namespace sensors;
81 using namespace time_literals;
82 
83 /**
84  * HACK - true temperature is much less than indicated temperature in baro,
85  * subtract 5 degrees in an attempt to account for the electrical upheating of the PCB
86  */
87 #define PCB_TEMP_ESTIMATE_DEG 5.0f
88 class Sensors : public ModuleBase<Sensors>, public ModuleParams
89 {
90 public:
91  explicit Sensors(bool hil_enabled);
92  ~Sensors() override;
93 
94  /** @see ModuleBase */
95  static int task_spawn(int argc, char *argv[]);
96 
97  /** @see ModuleBase */
98  static Sensors *instantiate(int argc, char *argv[]);
99 
100  /** @see ModuleBase */
101  static int custom_command(int argc, char *argv[]);
102 
103  /** @see ModuleBase */
104  static int print_usage(const char *reason = nullptr);
105 
106  /** @see ModuleBase::run() */
107  void run() override;
108 
109  /** @see ModuleBase::print_status() */
110  int print_status() override;
111 
112 private:
113  const bool _hil_enabled; /**< if true, HIL is active */
114  bool _armed{false}; /**< arming status of the vehicle */
115 
116  uORB::Subscription _actuator_ctrl_0_sub{ORB_ID(actuator_controls_0)}; /**< attitude controls sub */
117  uORB::Subscription _diff_pres_sub{ORB_ID(differential_pressure)}; /**< raw differential pressure subscription */
118  uORB::Subscription _parameter_update_sub{ORB_ID(parameter_update)}; /**< notification of parameter updates */
119  uORB::Subscription _vcontrol_mode_sub{ORB_ID(vehicle_control_mode)}; /**< vehicle control mode subscription */
120 
121  uORB::Publication<airspeed_s> _airspeed_pub{ORB_ID(airspeed)}; /**< airspeed */
122  uORB::Publication<sensor_combined_s> _sensor_pub{ORB_ID(sensor_combined)}; /**< combined sensor data topic */
123  uORB::Publication<sensor_preflight_s> _sensor_preflight{ORB_ID(sensor_preflight)}; /**< sensor preflight topic */
124  uORB::Publication<vehicle_air_data_s> _airdata_pub{ORB_ID(vehicle_air_data)}; /**< combined sensor data topic */
125  uORB::Publication<vehicle_magnetometer_s> _magnetometer_pub{ORB_ID(vehicle_magnetometer)}; /**< combined sensor data topic */
126 
127  perf_counter_t _loop_perf; /**< loop performance counter */
128 
129  DataValidator _airspeed_validator; /**< data validator to monitor airspeed */
130 
131 #ifdef ADC_AIRSPEED_VOLTAGE_CHANNEL
132  DevHandle _h_adc; /**< ADC driver handle */
133 
134  hrt_abstime _last_adc{0}; /**< last time we took input from the ADC */
135 
136  differential_pressure_s _diff_pres {};
137  uORB::PublicationMulti<differential_pressure_s> _diff_pres_pub{ORB_ID(differential_pressure)}; /**< differential_pressure */
138 #endif /* ADC_AIRSPEED_VOLTAGE_CHANNEL */
139 
140  Parameters _parameters{}; /**< local copies of interesting parameters */
141  ParameterHandles _parameter_handles{}; /**< handles for interesting parameters */
142 
144 
145 
148 
149 
150  /**
151  * Update our local parameter cache.
152  */
153  int parameters_update();
154 
155  /**
156  * Poll the differential pressure sensor for updated data.
157  *
158  * @param raw Combined sensor data structure into which
159  * data should be returned.
160  */
161  void diff_pres_poll(const vehicle_air_data_s &airdata);
162 
163  /**
164  * Check for changes in parameters.
165  */
166  void parameter_update_poll(bool forced = false);
167 
168  /**
169  * Do adc-related initialisation.
170  */
171  int adc_init();
172 
173  /**
174  * Poll the ADC and update readings to suit.
175  *
176  * @param raw Combined sensor data structure into which
177  * data should be returned.
178  */
179  void adc_poll();
180 
181 };
182 
183 Sensors::Sensors(bool hil_enabled) :
184  ModuleParams(nullptr),
185  _hil_enabled(hil_enabled),
186  _loop_perf(perf_alloc(PC_ELAPSED, "sensors")),
187  _voted_sensors_update(_parameters, hil_enabled)
188 {
190 
193 
196 }
197 
199 {
202 }
203 
204 int
206 {
207  if (_armed) {
208  return 0;
209  }
210 
211  /* read the parameter values into _parameters */
213 
215 
216  return PX4_OK;
217 }
218 
219 int
221 {
222  if (!_hil_enabled) {
223 #ifdef ADC_AIRSPEED_VOLTAGE_CHANNEL
224 
225 
226 
227  DevMgr::getHandle(ADC0_DEVICE_PATH, _h_adc);
228 
229  if (!_h_adc.isValid()) {
230  PX4_ERR("no ADC found: %s (%d)", ADC0_DEVICE_PATH, _h_adc.getError());
231  return PX4_ERROR;
232  }
233 
234 
235 #endif // ADC_AIRSPEED_VOLTAGE_CHANNEL
236  }
237 
238  return OK;
239 }
240 
241 void
243 {
244  differential_pressure_s diff_pres{};
245 
246  if (_diff_pres_sub.update(&diff_pres)) {
247 
248  float air_temperature_celsius = (diff_pres.temperature > -300.0f) ? diff_pres.temperature :
250 
251  airspeed_s airspeed;
252  airspeed.timestamp = diff_pres.timestamp;
253 
254  /* push data into validator */
255  float airspeed_input[3] = { diff_pres.differential_pressure_raw_pa, diff_pres.temperature, 0.0f };
256 
257  _airspeed_validator.put(airspeed.timestamp, airspeed_input, diff_pres.error_count,
258  ORB_PRIO_HIGH);
259 
261 
262  enum AIRSPEED_SENSOR_MODEL smodel;
263 
264  switch ((diff_pres.device_id >> 16) & 0xFF) {
266 
267  /* fallthrough */
269 
270  /* fallthrough */
272  /* fallthrough */
274  break;
275 
276  default:
278  break;
279  }
280 
281  /* don't risk to feed negative airspeed into the system */
285  diff_pres.differential_pressure_filtered_pa, raw.baro_pressure_pa,
286  air_temperature_celsius);
287 
289  air_temperature_celsius); // assume that EAS = IAS as we don't have an EAS-scale here
290 
291  airspeed.air_temperature_celsius = air_temperature_celsius;
292 
293  if (PX4_ISFINITE(airspeed.indicated_airspeed_m_s) && PX4_ISFINITE(airspeed.true_airspeed_m_s)) {
294  _airspeed_pub.publish(airspeed);
295  }
296  }
297 }
298 
299 void
301 {
302  // check for parameter updates
303  if (_parameter_update_sub.updated() || forced) {
304  // clear update
305  parameter_update_s pupdate;
306  _parameter_update_sub.copy(&pupdate);
307 
308  // update parameters from storage
310  updateParams();
311 
312  /* update airspeed scale */
314 
315  /* this sensor is optional, abort without error */
316  if (fd >= 0) {
317  struct airspeed_scale airscale = {
319  1.0f,
320  };
321 
322  if (OK != px4_ioctl(fd, AIRSPEEDIOCSSCALE, (long unsigned int)&airscale)) {
323  warn("WARNING: failed to set scale / offsets for airspeed sensor");
324  }
325 
326  px4_close(fd);
327  }
328  }
329 }
330 
331 void
333 {
334 #ifdef ADC_AIRSPEED_VOLTAGE_CHANNEL
335 
336  /* only read if not in HIL mode */
337  if (_hil_enabled) {
338  return;
339  }
340 
341  if (_parameters.diff_pres_analog_scale > 0.0f) {
342 
344 
345  /* rate limit to 100 Hz */
346  if (t - _last_adc >= 10000) {
347  /* make space for a maximum of twelve channels (to ensure reading all channels at once) */
349  /* read all channels available */
350  int ret = _h_adc.read(&buf_adc, sizeof(buf_adc));
351 
352  if (ret >= (int)sizeof(buf_adc[0])) {
353 
354  /* Read add channels we got */
355  for (unsigned i = 0; i < ret / sizeof(buf_adc[0]); i++) {
356  if (ADC_AIRSPEED_VOLTAGE_CHANNEL == buf_adc[i].am_channel) {
357 
358  /* calculate airspeed, raw is the difference from */
359  const float voltage = (float)(buf_adc[i].am_data) * 3.3f / 4096.0f * 2.0f; // V_ref/4096 * (voltage divider factor)
360 
361  /**
362  * The voltage divider pulls the signal down, only act on
363  * a valid voltage from a connected sensor. Also assume a non-
364  * zero offset from the sensor if its connected.
365  */
366  if (voltage > 0.4f) {
367  const float diff_pres_pa_raw = voltage * _parameters.diff_pres_analog_scale - _parameters.diff_pres_offset_pa;
368 
369  _diff_pres.timestamp = t;
370  _diff_pres.differential_pressure_raw_pa = diff_pres_pa_raw;
371  _diff_pres.differential_pressure_filtered_pa = (_diff_pres.differential_pressure_filtered_pa * 0.9f) +
372  (diff_pres_pa_raw * 0.1f);
373  _diff_pres.temperature = -1000.0f;
374 
375  _diff_pres_pub.publish(_diff_pres);
376  }
377  }
378  }
379 
380  _last_adc = t;
381  }
382  }
383  }
384 
385 #endif /* ADC_AIRSPEED_VOLTAGE_CHANNEL */
386 }
387 
388 void
390 {
391  adc_init();
392 
393  sensor_combined_s raw = {};
394  sensor_preflight_s preflt = {};
395  vehicle_air_data_s airdata = {};
396  vehicle_magnetometer_s magnetometer = {};
397 
399 
400  /* (re)load params and calibration */
401  parameter_update_poll(true);
402 
403  /* get a set of initial values */
404  _voted_sensors_update.sensorsPoll(raw, airdata, magnetometer);
405 
406  diff_pres_poll(airdata);
407 
408  /* wakeup source */
409  px4_pollfd_struct_t poll_fds = {};
410  poll_fds.events = POLLIN;
411 
412  uint64_t last_config_update = hrt_absolute_time();
413 
414  while (!should_exit()) {
415 
416  /* use the best-voted gyro to pace output */
417  poll_fds.fd = _voted_sensors_update.bestGyroFd();
418 
419  /* wait for up to 50ms for data (Note that this implies, we can have a fail-over time of 50ms,
420  * if a gyro fails) */
421  int pret = px4_poll(&poll_fds, 1, 50);
422 
423  /* If pret == 0 it timed out but we should still do all checks and potentially copy
424  * other gyros. */
425 
426  /* this is undesirable but not much we can do - might want to flag unhappy status */
427  if (pret < 0) {
428  /* if the polling operation failed because no gyro sensor is available yet,
429  * then attempt to subscribe once again
430  */
431  if (_voted_sensors_update.numGyros() == 0) {
433  }
434 
435  px4_usleep(1000);
436  continue;
437  }
438 
440 
441  /* check vehicle status for changes to publication state */
442  if (_vcontrol_mode_sub.updated()) {
443  vehicle_control_mode_s vcontrol_mode{};
444  _vcontrol_mode_sub.copy(&vcontrol_mode);
445  _armed = vcontrol_mode.flag_armed;
446  }
447 
448  /* the timestamp of the raw struct is updated by the gyroPoll() method (this makes the gyro
449  * a mandatory sensor) */
450  const uint64_t airdata_prev_timestamp = airdata.timestamp;
451  const uint64_t magnetometer_prev_timestamp = magnetometer.timestamp;
452 
453  _voted_sensors_update.sensorsPoll(raw, airdata, magnetometer);
454 
455  /* check analog airspeed */
456  adc_poll();
457 
458  diff_pres_poll(airdata);
459 
460  if (raw.timestamp > 0) {
461 
463 
464  _sensor_pub.publish(raw);
465 
466  if (airdata.timestamp != airdata_prev_timestamp) {
467  _airdata_pub.publish(airdata);
468  }
469 
470  if (magnetometer.timestamp != magnetometer_prev_timestamp) {
471  _magnetometer_pub.publish(magnetometer);
472  }
473 
475 
476  /* If the the vehicle is disarmed calculate the length of the maximum difference between
477  * IMU units as a consistency metric and publish to the sensor preflight topic
478  */
479  if (!_armed) {
480  preflt.timestamp = hrt_absolute_time();
484 
485  _sensor_preflight.publish(preflt);
486  }
487  }
488 
489  /* keep adding sensors as long as we are not armed,
490  * when not adding sensors poll for param updates
491  */
492  if (!_armed && hrt_elapsed_time(&last_config_update) > 500_ms) {
494  last_config_update = hrt_absolute_time();
495 
496  } else {
497 
498  /* check parameters for updates */
500  }
501 
503  }
504 
506 }
507 
508 int Sensors::task_spawn(int argc, char *argv[])
509 {
510  /* start the task */
511  _task_id = px4_task_spawn_cmd("sensors",
512  SCHED_DEFAULT,
513  SCHED_PRIORITY_SENSOR_HUB,
514  2000,
515  (px4_main_t)&run_trampoline,
516  (char *const *)argv);
517 
518  if (_task_id < 0) {
519  _task_id = -1;
520  return -errno;
521  }
522 
523  return 0;
524 }
525 
527 {
529 
530  PX4_INFO("Airspeed status:");
532 
535 
536  return 0;
537 }
538 
539 int Sensors::custom_command(int argc, char *argv[])
540 {
541  return print_usage("unknown command");
542 }
543 
544 int Sensors::print_usage(const char *reason)
545 {
546  if (reason) {
547  PX4_WARN("%s\n", reason);
548  }
549 
550  PRINT_MODULE_DESCRIPTION(
551  R"DESCR_STR(
552 ### Description
553 The sensors module is central to the whole system. It takes low-level output from drivers, turns
554 it into a more usable form, and publishes it for the rest of the system.
555 
556 The provided functionality includes:
557 - Read the output from the sensor drivers (`sensor_gyro`, etc.).
558  If there are multiple of the same type, do voting and failover handling.
559  Then apply the board rotation and temperature calibration (if enabled). And finally publish the data; one of the
560  topics is `sensor_combined`, used by many parts of the system.
561 - Make sure the sensor drivers get the updated calibration parameters (scale & offset) when the parameters change or
562  on startup. The sensor drivers use the ioctl interface for parameter updates. For this to work properly, the
563  sensor drivers must already be running when `sensors` is started.
564 - Do preflight sensor consistency checks and publish the `sensor_preflight` topic.
565 
566 ### Implementation
567 It runs in its own thread and polls on the currently selected gyro topic.
568 
569 )DESCR_STR");
570 
571  PRINT_MODULE_USAGE_NAME("sensors", "system");
572  PRINT_MODULE_USAGE_COMMAND("start");
573  PRINT_MODULE_USAGE_PARAM_FLAG('h', "Start in HIL mode", true);
574  PRINT_MODULE_USAGE_DEFAULT_COMMANDS();
575 
576  return 0;
577 }
578 
579 Sensors *Sensors::instantiate(int argc, char *argv[])
580 {
581  bool hil_enabled = false;
582  bool error_flag = false;
583 
584  int myoptind = 1;
585  int ch;
586  const char *myoptarg = nullptr;
587 
588  while ((ch = px4_getopt(argc, argv, "h", &myoptind, &myoptarg)) != EOF) {
589  switch (ch) {
590  case 'h':
591  hil_enabled = true;
592  break;
593 
594  case '?':
595  error_flag = true;
596  break;
597 
598  default:
599  PX4_WARN("unrecognized flag");
600  error_flag = true;
601  break;
602  }
603  }
604 
605  if (error_flag) {
606  return nullptr;
607  }
608 
609  return new Sensors(hil_enabled);
610 }
611 
612 extern "C" __EXPORT int sensors_main(int argc, char *argv[])
613 {
614  return Sensors::main(argc, argv);
615 }
ParameterHandles _parameter_handles
handles for interesting parameters
Definition: sensors.cpp:141
class VotedSensorsUpdate
#define PCB_TEMP_ESTIMATE_DEG
HACK - true temperature is much less than indicated temperature in baro, subtract 5 degrees in an att...
Definition: sensors.cpp:87
px4_adc_msg_t
Definition: drv_adc.h:56
void sensorsPoll(sensor_combined_s &raw, vehicle_air_data_s &airdata, vehicle_magnetometer_s &magnetometer)
read new sensor data
measure the time elapsed performing an event
Definition: perf_counter.h:56
float air_tube_diameter_mm
Definition: parameters.h:63
float calc_IAS_corrected(enum AIRSPEED_COMPENSATION_MODEL pmodel, enum AIRSPEED_SENSOR_MODEL smodel, float tube_len, float tube_dia_mm, float differential_pressure, float pressure_ambient, float temperature_celsius)
Calculate indicated airspeed.
Definition: airspeed.cpp:58
struct uart_esc::@19 _parameter_handles
perf_counter_t _loop_perf
loop performance counter
Definition: sensors.cpp:127
static void parameter_update_poll()
poll parameter update
#define PX4_MAX_ADC_CHANNELS
Definition: drv_adc.h:52
void parameter_update_poll(bool forced=false)
Check for changes in parameters.
Definition: sensors.cpp:300
float calc_TAS_from_EAS(float speed_equivalent, float pressure_ambient, float temperature_celsius)
Calculate true airspeed (TAS) from equivalent airspeed (EAS).
Definition: airspeed.cpp:218
uORB::Subscription _diff_pres_sub
raw differential pressure subscription
Definition: sensors.cpp:117
#define AIRSPEED0_DEVICE_PATH
Definition: drv_airspeed.h:52
void setRelativeTimestamps(sensor_combined_s &raw)
set the relative timestamps of each sensor timestamp, based on the last sensorsPoll, so that the data can be published.
Sensors(bool hil_enabled)
Definition: sensors.cpp:183
float true_airspeed_m_s
Definition: airspeed.h:55
int main(int argc, char **argv)
Definition: main.cpp:3
int adc_init()
Do adc-related initialisation.
Definition: sensors.cpp:220
#define DRV_DIFF_PRESS_DEVTYPE_SDP33
Definition: drv_sensor.h:101
uORB::Publication< sensor_preflight_s > _sensor_preflight
sensor preflight topic
Definition: sensors.cpp:123
float air_temperature_celsius
Definition: airspeed.h:56
Definition: I2C.hpp:51
int px4_poll(px4_pollfd_struct_t *fds, nfds_t nfds, int timeout)
void print_status()
Definition: Commander.cpp:517
static int custom_command(int argc, char *argv[])
Definition: sensors.cpp:539
VehicleAcceleration _vehicle_acceleration
Definition: sensors.cpp:146
ADC driver interface.
static void print_usage()
#define DRV_DIFF_PRESS_DEVTYPE_SDP31
Definition: drv_sensor.h:99
#define ADC0_DEVICE_PATH
Definition: drv_adc.h:59
uORB::Subscription _parameter_update_sub
notification of parameter updates
Definition: sensors.cpp:118
void initializeSensors()
This tries to find new sensor instances.
Vector rotation library.
High-resolution timer with callouts and timekeeping.
int init(sensor_combined_s &raw)
initialize subscriptions etc.
~Sensors() override
Definition: sensors.cpp:198
void calcMagInconsistency(sensor_preflight_s &preflt)
Calculates the magnitude in Gauss of the largest difference between the primary and any other magneto...
Global flash based parameter store.
uORB::Subscription _vcontrol_mode_sub
vehicle control mode subscription
Definition: sensors.cpp:119
uORB::Publication< vehicle_magnetometer_s > _magnetometer_pub
combined sensor data topic
Definition: sensors.cpp:125
AIRSPEED_SENSOR_MODEL
Definition: airspeed.h:49
uORB::Publication< vehicle_air_data_s > _airdata_pub
combined sensor data topic
Definition: sensors.cpp:124
int print_status() override
Definition: sensors.cpp:526
float confidence
Definition: airspeed.h:57
#define ORB_ID(_name)
Generates a pointer to the uORB metadata structure for a given topic.
Definition: uORB.h:87
float diff_pres_offset_pa
Definition: parameters.h:50
VehicleAngularVelocity _vehicle_angular_velocity
Definition: sensors.cpp:147
void diff_pres_poll(const vehicle_air_data_s &airdata)
Poll the differential pressure sensor for updated data.
Definition: sensors.cpp:242
bool publish(const T &data)
Publish the struct.
Definition: Publication.hpp:68
airspeed scaling factors; out = (in * Vscale) + offset
Definition: drv_airspeed.h:67
Header common to all counters.
static void parameters_update()
update all parameters
DataValidator _airspeed_validator
data validator to monitor airspeed
Definition: sensors.cpp:129
void print()
Print the validator value.
void set_timeout(uint32_t timeout_interval_us)
Set the timeout value.
void run() override
Definition: sensors.cpp:389
#define perf_alloc(a, b)
Definition: px4io.h:59
static int task_spawn(int argc, char *argv[])
Definition: sensors.cpp:508
static Sensors * instantiate(int argc, char *argv[])
Definition: sensors.cpp:579
Vector< float, 6 > f(float t, const Matrix< float, 6, 1 > &, const Matrix< float, 3, 1 > &)
Definition: integration.cpp:8
static hrt_abstime hrt_elapsed_time(const hrt_abstime *then)
Compute the delta between a timestamp taken in the past and now.
Definition: drv_hrt.h:102
float indicated_airspeed_m_s
Definition: airspeed.h:54
uORB::Publication< airspeed_s > _airspeed_pub
airspeed
Definition: sensors.cpp:121
void perf_end(perf_counter_t handle)
End a performance event.
bool updated()
Check if there is a new update.
__BEGIN_DECLS typedef uint64_t hrt_abstime
Absolute time, in microsecond units.
Definition: drv_hrt.h:58
static int print_usage(const char *reason=nullptr)
Definition: sensors.cpp:544
int fd
Definition: dataman.cpp:146
void initialize_parameter_handles(ParameterHandles &parameter_handles)
initialize ParameterHandles struct
Definition: parameters.cpp:49
Definition: common.h:43
__EXPORT int sensors_main(int argc, char *argv[])
Definition: sensors.cpp:612
#define AIRSPEEDIOCSSCALE
Definition: drv_airspeed.h:64
struct uart_esc::@18 _parameters
int update_parameters(const ParameterHandles &parameter_handles, Parameters &parameters)
Read out the parameters using the handles into the parameters struct.
Definition: parameters.cpp:60
int px4_open(const char *path, int flags,...)
void set_equal_value_threshold(uint32_t threshold)
Set the equal count threshold.
uint64_t timestamp
Definition: airspeed.h:53
void calcAccelInconsistency(sensor_preflight_s &preflt)
Calculates the magnitude in m/s/s of the largest difference between the primary and any other accel s...
VotedSensorsUpdate _voted_sensors_update
Definition: sensors.cpp:143
AIRSPEED_COMPENSATION_MODEL
Definition: airspeed.h:54
bool _armed
arming status of the vehicle
Definition: sensors.cpp:114
void parametersUpdate()
call this whenever parameters got updated.
const bool _hil_enabled
if true, HIL is active
Definition: sensors.cpp:113
int parameters_update()
Update our local parameter cache.
Definition: sensors.cpp:205
Parameters _parameters
local copies of interesting parameters
Definition: sensors.cpp:140
void put(uint64_t timestamp, float val, uint64_t error_count, int priority)
Put an item into the validator.
Base publication multi wrapper class.
#define OK
Definition: uavcan_main.cpp:71
bool update(void *dst)
Update the struct.
uORB::Publication< sensor_combined_s > _sensor_pub
combined sensor data topic
Definition: sensors.cpp:122
void adc_poll()
Poll the ADC and update readings to suit.
Definition: sensors.cpp:332
float confidence(uint64_t timestamp)
Get the confidence of this validator.
Airspeed driver interface.
bool copy(void *dst)
Copy the struct.
#define warn(...)
Definition: err.h:94
int adc_init(void)
Sensors/misc inputs.
Definition: adc.c:82
void deinit()
deinitialize the object (we cannot use the destructor because it is called on the wrong thread) ...
void checkFailover()
check if a failover event occured.
void perf_begin(perf_counter_t handle)
Begin a performance event.
void calcGyroInconsistency(sensor_preflight_s &preflt)
Calculates the magnitude in rad/s of the largest difference between the primary and any other gyro se...
__EXPORT hrt_abstime hrt_absolute_time(void)
Get absolute time in [us] (does not wrap).
int px4_close(int fd)
Performance measuring tools.
#define DRV_DIFF_PRESS_DEVTYPE_SDP32
Definition: drv_sensor.h:100
int px4_ioctl(int fd, int cmd, unsigned long arg)