Paparazzi UAS  v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
mag_ist8310.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2019 Freek van Tienen <freek.v.tienen@gmail.com>
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 IST8310_CHAN_X
35 #define IST8310_CHAN_X 1
36 #endif
37 #ifndef IST8310_CHAN_Y
38 #define IST8310_CHAN_Y 0
39 #endif
40 #ifndef IST8310_CHAN_Z
41 #define IST8310_CHAN_Z 2
42 #endif
43 #ifndef IST8310_CHAN_X_SIGN
44 #define IST8310_CHAN_X_SIGN +
45 #endif
46 #ifndef IST8310_CHAN_Y_SIGN
47 #define IST8310_CHAN_Y_SIGN +
48 #endif
49 #ifndef IST8310_CHAN_Z_SIGN
50 #define IST8310_CHAN_Z_SIGN +
51 #endif
52 
53 struct IST8310 mag_ist8310;
54 
56 {
57  ist8310_init(&mag_ist8310, &(MAG_IST8310_I2C_DEV), IST8310_ADDR);
58 
59 #if MODULE_IST8310_UPDATE_AHRS && defined(IST8310_MAG_TO_IMU_PHI) && defined(IST8310_MAG_TO_IMU_THETA) && defined(IST8310_MAG_TO_IMU_PSI)
60  struct Int32RMat mag_to_imu;
61  struct Int32Eulers mag_to_imu_eulers = {
62  ANGLE_BFP_OF_REAL(IST8310_MAG_TO_IMU_PHI),
63  ANGLE_BFP_OF_REAL(IST8310_MAG_TO_IMU_THETA),
64  ANGLE_BFP_OF_REAL(IST8310_MAG_TO_IMU_PSI)
65  };
66  int32_rmat_of_eulers(&mag_to_imu, &mag_to_imu_eulers);
67 
68  imu_set_defaults_mag(MAG_IST8310_SENDER_ID, &mag_to_imu, NULL, NULL);
69 #endif
70 }
71 
73 {
75 }
76 
78 {
80 
82 #if MODULE_IST8310_UPDATE_AHRS
83  // current timestamp
84  uint32_t now_ts = get_sys_time_usec();
85 
86  // set channel order
87  struct Int32Vect3 mag = {
91  };
92 
93  AbiSendMsgIMU_MAG_RAW(MAG_IST8310_SENDER_ID, now_ts, &mag);
94 #endif
95 #if MODULE_IST8310_SYNC_SEND
97 #endif
98 #if MODULE_IST8310_UPDATE_AHRS || MODULE_IST8310_SYNC_SEND
100 #endif
101  }
102 }
103 
105 {
107  struct Int32Vect3 mag = {
111  };
112  DOWNLINK_SEND_IMU_MAG_RAW(DefaultChannel, DefaultDevice, &id, &mag.x, &mag.y, &mag.z);
113 }
Main include for ABI (AirBorneInterface).
#define MAG_IST8310_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:640
void ist8310_event(struct IST8310 *ist)
Definition: ist8310.c:111
void ist8310_init(struct IST8310 *ist, struct i2c_periph *i2c_p, uint8_t addr)
Initialize IST8310 struct.
Definition: ist8310.c:34
union IST8310::@328 data
static void ist8310_periodic(struct IST8310 *ist)
convenience function: read or start configuration if not already initialized
Definition: ist8310.h:77
volatile bool data_available
data ready flag
Definition: ist8310.h:63
Default IST8310 structure.
Definition: ist8310.h:55
#define IST8310_ADDR
Definition: ist8310_regs.h:31
#define IST8310_CHAN_Y
Definition: mag_ist8310.c:38
#define IST8310_CHAN_Z_SIGN
Definition: mag_ist8310.c:50
void mag_ist8310_report(void)
Definition: mag_ist8310.c:104
#define IST8310_CHAN_Z
Definition: mag_ist8310.c:41
#define IST8310_CHAN_X
Definition: mag_ist8310.c:35
struct IST8310 mag_ist8310
Definition: mag_ist8310.c:53
#define IST8310_CHAN_X_SIGN
Definition: mag_ist8310.c:44
#define IST8310_CHAN_Y_SIGN
Definition: mag_ist8310.c:47
void mag_ist8310_module_event(void)
Definition: mag_ist8310.c:77
void mag_ist8310_module_periodic(void)
Definition: mag_ist8310.c:72
void mag_ist8310_module_init(void)
Definition: mag_ist8310.c:55
Module wrapper for Isentek IST8310 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