Paparazzi UAS  v5.8.2_stable-0-g6260b7c
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
mag_hmc58xx.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2013 Felix Ruess <felix.ruess@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, write to
18  * the Free Software Foundation, 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  */
21 
29 #include "mcu_periph/uart.h"
30 #include "messages.h"
32 
33 #if MODULE_HMC58XX_UPDATE_AHRS
34 #include "subsystems/imu.h"
35 #include "subsystems/abi.h"
36 
37 #ifndef HMC58XX_CHAN_X
38 #define HMC58XX_CHAN_X 0
39 #endif
40 #ifndef HMC58XX_CHAN_Y
41 #define HMC58XX_CHAN_Y 1
42 #endif
43 #ifndef HMC58XX_CHAN_Z
44 #define HMC58XX_CHAN_Z 2
45 #endif
46 
47 #endif
48 
50 
52 {
53  hmc58xx_init(&mag_hmc58xx, &(MAG_HMC58XX_I2C_DEV), HMC58XX_ADDR);
54 }
55 
57 {
59 }
60 
62 {
64 
66 #if MODULE_HMC58XX_UPDATE_AHRS
67  // current timestamp
68  uint32_t now_ts = get_sys_time_usec();
69 
70  // set channel order
71  struct Int32Vect3 mag = {
72  (int32_t)(mag_hmc58xx.data.value[HMC58XX_CHAN_X]),
73  (int32_t)(mag_hmc58xx.data.value[HMC58XX_CHAN_Y]),
74  (int32_t)(mag_hmc58xx.data.value[HMC58XX_CHAN_Z])
75  };
76  // unscaled vector
78  // scale vector
80 
81  AbiSendMsgIMU_MAG_INT32(MAG_HMC58XX_SENDER_ID, now_ts, &imu.mag);
82 #endif
83 #if MODULE_HMC58XX_SYNC_SEND
85 #endif
86 #if MODULE_HMC58XX_UPDATE_AHRS || MODULE_HMC58XX_SYNC_SEND
88 #endif
89  }
90 }
91 
93 {
94  struct Int32Vect3 mag = {
95  (int32_t)(mag_hmc58xx.data.value[HMC58XX_CHAN_X]),
96  (int32_t)(mag_hmc58xx.data.value[HMC58XX_CHAN_Y]),
97  (int32_t)(mag_hmc58xx.data.value[HMC58XX_CHAN_Z])
98  };
99  DOWNLINK_SEND_IMU_MAG_RAW(DefaultChannel, DefaultDevice, &mag.x, &mag.y, &mag.z);
100 }
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
#define MAG_HMC58XX_SENDER_ID
#define VECT3_COPY(_a, _b)
Definition: pprz_algebra.h:139
Main include for ABI (AirBorneInterface).
#define HMC58XX_ADDR
Definition: hmc58xx_regs.h:31
void mag_hmc58xx_module_event(void)
Definition: mag_hmc58xx.c:61
#define FALSE
Definition: std.h:5
static uint32_t get_sys_time_usec(void)
Get the time in microseconds since startup.
Definition: sys_time_arch.h:39
struct Int32Vect3 mag_unscaled
unscaled magnetometer measurements
Definition: imu.h:52
void mag_hmc58xx_module_init(void)
Definition: mag_hmc58xx.c:51
struct Hmc58xx mag_hmc58xx
Definition: mag_hmc58xx.c:49
struct Imu imu
global IMU state
Definition: imu_aspirin2.c:43
unsigned long uint32_t
Definition: types.h:18
void mag_hmc58xx_module_periodic(void)
Definition: mag_hmc58xx.c:56
struct Int32Vect3 mag
magnetometer measurements scaled to 1 in BFP with INT32_MAG_FRAC
Definition: imu.h:44
Inertial Measurement Unit interface.
volatile bool_t data_available
data ready flag
Definition: hmc58xx.h:65
signed long int32_t
Definition: types.h:19
Module wrapper for Honeywell HMC5843 and HMC5883 magnetometers.
union Hmc58xx::@33 data
void imu_scale_mag(struct Imu *_imu)
Definition: ahrs_gx3.c:351
static void hmc58xx_periodic(struct Hmc58xx *hmc)
convenience function: read or start configuration if not already initialized
Definition: hmc58xx.h:85
void hmc58xx_init(struct Hmc58xx *hmc, struct i2c_periph *i2c_p, uint8_t addr)
Initialize Hmc58xx struct and set default config options.
Definition: hmc58xx.c:75
void hmc58xx_event(struct Hmc58xx *hmc)
Definition: hmc58xx.c:152
void mag_hmc58xx_report(void)
Definition: mag_hmc58xx.c:92