Paparazzi UAS  v5.2.2_stable-0-gd6b9f29
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures 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/ahrs.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  hmc58xx_init(&mag_hmc58xx, &(MAG_HMC58XX_I2C_DEV), HMC58XX_ADDR);
53 }
54 
57 }
58 
61 #if MODULE_HMC58XX_UPDATE_AHRS
63  // set channel order
64  struct Int32Vect3 mag = {
65  (int32_t)(mag_hmc58xx.data.value[HMC58XX_CHAN_X]),
66  (int32_t)(mag_hmc58xx.data.value[HMC58XX_CHAN_Y]),
67  (int32_t)(mag_hmc58xx.data.value[HMC58XX_CHAN_Z])
68  };
69  // unscaled vector
71  // scale vector
73  // update ahrs
74  if (ahrs.status == AHRS_RUNNING) {
76  }
78  }
79 #endif
80 #if MODULE_HMC58XX_SYNC_SEND
84  }
85 #endif
86 }
87 
88 void mag_hmc58xx_report(void) {
89  struct Int32Vect3 mag = {
93  };
94  DOWNLINK_SEND_IMU_MAG_RAW(DefaultChannel, DefaultDevice, &mag.x, &mag.y, &mag.z);
95 }
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
Attitude and Heading Reference System interface.
struct Ahrs ahrs
global AHRS state
Definition: ahrs.c:30
#define ImuScaleMag(_imu)
Definition: ahrs_gx3.h:59
union Hmc58xx::@29 data
#define HMC58XX_ADDR
Definition: hmc58xx_regs.h:31
void mag_hmc58xx_module_event(void)
Definition: mag_hmc58xx.c:59
#define FALSE
Definition: imu_chimu.h:141
int16_t value[3]
data values accessible by channel index
Definition: hmc58xx.h:68
void ahrs_update_mag(void)
Update AHRS state with magnetometer measurements.
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:47
uint8_t status
status of the AHRS, AHRS_UNINIT or AHRS_RUNNING
Definition: ahrs.h:45
void mag_hmc58xx_module_periodic(void)
Definition: mag_hmc58xx.c:55
Inertial Measurement Unit interface.
struct Int32Vect3 mag_unscaled
unscaled magnetometer measurements
Definition: imu.h:51
signed long int32_t
Definition: types.h:19
struct Int16Vect3 vect
data vector in mag coordinate system
Definition: hmc58xx.h:67
Module wrapper for Honeywell HMC5843 and HMC5883 magnetometers.
static void hmc58xx_periodic(struct Hmc58xx *hmc)
convenience function: read or start configuration if not already initialized
Definition: hmc58xx.h:84
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
#define VECT3_COPY(_a, _b)
Definition: pprz_algebra.h:129
void hmc58xx_event(struct Hmc58xx *hmc)
Definition: hmc58xx.c:151
volatile bool_t data_available
data ready flag
Definition: hmc58xx.h:65
void mag_hmc58xx_report(void)
Definition: mag_hmc58xx.c:88
#define AHRS_RUNNING
Definition: ahrs.h:36