Paparazzi UAS  v6.2.0_stable
Paparazzi is a free software Unmanned Aircraft System.
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
nps_sensor_accel.c
Go to the documentation of this file.
1 #include "nps_sensor_accel.h"
2 
3 #include "nps_fdm.h"
4 #include "nps_random.h"
5 #include "nps_sensors.h"
7 
8 void nps_sensor_accel_init(struct NpsSensorAccel *accel, double time)
9 {
10  FLOAT_VECT3_ZERO(accel->value);
11  accel->min = NPS_ACCEL_MIN;
12  accel->max = NPS_ACCEL_MAX;
14  NPS_ACCEL_SENSITIVITY_XX, NPS_ACCEL_SENSITIVITY_YY, NPS_ACCEL_SENSITIVITY_ZZ);
15  VECT3_ASSIGN(accel->neutral,
16  NPS_ACCEL_NEUTRAL_X, NPS_ACCEL_NEUTRAL_Y, NPS_ACCEL_NEUTRAL_Z);
18  NPS_ACCEL_NOISE_STD_DEV_X, NPS_ACCEL_NOISE_STD_DEV_Y, NPS_ACCEL_NOISE_STD_DEV_Z);
19  VECT3_ASSIGN(accel->bias,
20  NPS_ACCEL_BIAS_X, NPS_ACCEL_BIAS_Y, NPS_ACCEL_BIAS_Z);
21  accel->next_update = time;
22  accel->data_available = FALSE;
23 }
24 
25 void nps_sensor_accel_run_step(struct NpsSensorAccel *accel, double time, struct DoubleRMat *body_to_imu)
26 {
27  if (time < accel->next_update) {
28  return;
29  }
30 
31  /* transform to imu frame */
32  struct DoubleVect3 accelero_imu;
33  MAT33_VECT3_MUL(accelero_imu, *body_to_imu, fdm.body_accel);
34 
35  /* compute accelero readings */
36  MAT33_VECT3_MUL(accel->value, accel->sensitivity, accelero_imu);
37  VECT3_ADD(accel->value, accel->neutral);
38 
39  /* Compute sensor error */
40  struct DoubleVect3 accelero_error;
41  /* constant bias */
42  VECT3_COPY(accelero_error, accel->bias);
43  /* white noise */
44  double_vect3_add_gaussian_noise(&accelero_error, &accel->noise_std_dev);
45  /* scale */
46  struct DoubleVect3 gain = {accel->sensitivity.m[0], accel->sensitivity.m[4], accel->sensitivity.m[8]};
47  VECT3_EW_MUL(accelero_error, accelero_error, gain);
48  /* add error */
49  VECT3_ADD(accel->value, accelero_error);
50 
51  /* round signal to account for adc discretisation */
52  DOUBLE_VECT3_ROUND(accel->value);
53  /* saturate */
54  VECT3_BOUND_CUBE(accel->value, accel->min, accel->max);
55 
56  accel->next_update += NPS_ACCEL_DT;
57  accel->data_available = TRUE;
58 }
59 
double m[3 *3]
#define DOUBLE_VECT3_ROUND(_v)
rotation matrix
#define FLOAT_VECT3_ZERO(_v)
#define FLOAT_MAT33_DIAG(_m, _d00, _d11, _d22)
#define VECT3_BOUND_CUBE(_v, _min, _max)
Definition: pprz_algebra.h:224
#define VECT3_EW_MUL(_vo, _va, _vb)
Definition: pprz_algebra.h:217
#define MAT33_VECT3_MUL(_vout, _mat, _vin)
Definition: pprz_algebra.h:463
#define VECT3_ASSIGN(_a, _x, _y, _z)
Definition: pprz_algebra.h:125
#define VECT3_COPY(_a, _b)
Definition: pprz_algebra.h:140
#define VECT3_ADD(_a, _b)
Definition: pprz_algebra.h:147
struct DoubleVect3 body_accel
acceleration in body frame as measured by an accelerometer (incl.
Definition: nps_fdm.h:87
struct NpsFdm fdm
Holds all necessary NPS FDM state information.
void double_vect3_add_gaussian_noise(struct DoubleVect3 *vect, struct DoubleVect3 *std_dev)
Definition: nps_random.c:34
void nps_sensor_accel_init(struct NpsSensorAccel *accel, double time)
void nps_sensor_accel_run_step(struct NpsSensorAccel *accel, double time, struct DoubleRMat *body_to_imu)
struct DoubleVect3 noise_std_dev
struct DoubleVect3 neutral
struct DoubleMat33 sensitivity
struct DoubleVect3 bias
struct DoubleVect3 value
Paparazzi fixed point algebra.
#define TRUE
Definition: std.h:4
#define FALSE
Definition: std.h:5