Paparazzi UAS  v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
mag_lis3mdl.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2019 Gautier Hattenberger <gautier.hattenberger@enac.fr>
3  *
4  * This file is part of paparazzi.
5  *
6  * paparazzi is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2, or (at your option)
9  * any later version.
10  *
11  * paparazzi is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with paparazzi; see the file COPYING. If not, see
18  * <http://www.gnu.org/licenses/>.
19  */
20 
28 #include "mcu_periph/uart.h"
29 #include "pprzlink/messages.h"
31 #include "generated/airframe.h"
32 #include "modules/core/abi.h"
33 
34 #ifndef LIS3MDL_CHAN_X
35 #define LIS3MDL_CHAN_X 0
36 #endif
37 #ifndef LIS3MDL_CHAN_Y
38 #define LIS3MDL_CHAN_Y 1
39 #endif
40 #ifndef LIS3MDL_CHAN_Z
41 #define LIS3MDL_CHAN_Z 2
42 #endif
43 #ifndef LIS3MDL_CHAN_X_SIGN
44 #define LIS3MDL_CHAN_X_SIGN +
45 #endif
46 #ifndef LIS3MDL_CHAN_Y_SIGN
47 #define LIS3MDL_CHAN_Y_SIGN +
48 #endif
49 #ifndef LIS3MDL_CHAN_Z_SIGN
50 #define LIS3MDL_CHAN_Z_SIGN +
51 #endif
52 
53 struct Lis3mdl mag_lis3mdl;
54 
56 {
57  lis3mdl_init(&mag_lis3mdl, &(MAG_LIS3MDL_I2C_DEV), LIS3MDL_ADDR1,
62 
63 #if MODULE_LIS3MDL_UPDATE_AHRS && defined(LIS3MDL_MAG_TO_IMU_PHI) && defined(LIS3MDL_MAG_TO_IMU_THETA) && defined(LIS3MDL_MAG_TO_IMU_PSI)
64  struct Int32RMat mag_to_imu;
65  struct Int32Eulers mag_to_imu_eulers = {
66  ANGLE_BFP_OF_REAL(LIS3MDL_MAG_TO_IMU_PHI),
67  ANGLE_BFP_OF_REAL(LIS3MDL_MAG_TO_IMU_THETA),
68  ANGLE_BFP_OF_REAL(LIS3MDL_MAG_TO_IMU_PSI)
69  };
70  int32_rmat_of_eulers(&mag_to_imu, &mag_to_imu_eulers);
71 
72  imu_set_defaults_mag(MAG_LIS3MDL_SENDER_ID, &mag_to_imu, NULL, NULL);
73 #endif
74 }
75 
77 {
79 }
80 
82 {
84 
86 #if MODULE_LIS3MDL_UPDATE_AHRS
87  // current timestamp
88  uint32_t now_ts = get_sys_time_usec();
89 
90  // set channel order
91  struct Int32Vect3 mag = {
95  };
96 
97  AbiSendMsgIMU_MAG_RAW(MAG_LIS3MDL_SENDER_ID, now_ts, &mag);
98 #endif
99 #if MODULE_LIS3MDL_SYNC_SEND
101 #endif
102 #if MODULE_LIS3MDL_UPDATE_AHRS || MODULE_LIS3MDL_SYNC_SEND
103  mag_lis3mdl.data_available = false;
104 #endif
105  }
106 }
107 
109 {
111  struct Int32Vect3 mag = {
115  };
116  DOWNLINK_SEND_IMU_MAG_RAW(DefaultChannel, DefaultDevice, &id, &mag.x, &mag.y, &mag.z);
117 }
Main include for ABI (AirBorneInterface).
#define MAG_LIS3MDL_SENDER_ID
uint32_t get_sys_time_usec(void)
Get the time in microseconds since startup.
Definition: sys_time_arch.c:71
#define ANGLE_BFP_OF_REAL(_af)
#define int32_rmat_of_eulers
Rotation matrix from Euler angles.
euler angles
rotation matrix
void imu_set_defaults_mag(uint8_t abi_id, const struct Int32RMat *imu_to_sensor, const struct Int32Vect3 *neutral, const struct Int32Vect3 *scale)
Set the defaults for a mag sensor WARNING: Should be called before sensor is publishing messages to e...
Definition: imu.c:551
void lis3mdl_init(struct Lis3mdl *mag, struct i2c_periph *i2c_p, uint8_t addr, uint8_t data_rate, uint8_t scale, uint8_t mode, uint8_t perf)
Definition: lis3mdl.c:60
void lis3mdl_event(struct Lis3mdl *mag)
Definition: lis3mdl.c:127
#define LIS3MDL_ADDR1
Definition: lis3mdl.h:34
volatile bool data_available
data ready flag
Definition: lis3mdl.h:74
union Lis3mdl::@331 data
static void lis3mdl_periodic(struct Lis3mdl *mag)
convenience function: read or start configuration if not already initialized
Definition: lis3mdl.h:88
#define LIS3MDL_PERFORMANCE_ULTRA_HIGH
Definition: lis3mdl.h:40
#define LIS3MDL_DATA_RATE_80_HZ
Definition: lis3mdl.h:49
#define LIS3MDL_SCALE_4_GAUSS
Definition: lis3mdl.h:55
#define LIS3MDL_MODE_CONTINUOUS
Definition: lis3mdl.h:51
struct Lis3mdl mag_lis3mdl
Definition: mag_lis3mdl.c:53
#define LIS3MDL_CHAN_Y
Definition: mag_lis3mdl.c:38
#define LIS3MDL_CHAN_Y_SIGN
Definition: mag_lis3mdl.c:47
#define LIS3MDL_CHAN_X
Definition: mag_lis3mdl.c:35
void mag_lis3mdl_module_init(void)
Definition: mag_lis3mdl.c:55
#define LIS3MDL_CHAN_X_SIGN
Definition: mag_lis3mdl.c:44
void mag_lis3mdl_module_event(void)
Definition: mag_lis3mdl.c:81
#define LIS3MDL_CHAN_Z_SIGN
Definition: mag_lis3mdl.c:50
void mag_lis3mdl_report(void)
Definition: mag_lis3mdl.c:108
#define LIS3MDL_CHAN_Z
Definition: mag_lis3mdl.c:41
void mag_lis3mdl_module_periodic(void)
Definition: mag_lis3mdl.c:76
Module wrapper for ST LIS3MDL magnetometers.
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
int int32_t
Typedef defining 32 bit int type.
Definition: vl53l1_types.h:83
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
Definition: vl53l1_types.h:78
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
Definition: vl53l1_types.h:98