Paparazzi UAS v7.1_unstable
Paparazzi is a free software Unmanned Aircraft System.
Loading...
Searching...
No Matches
imu_pixhawk6x.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2022 Freek van tieen <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, write to
18 * the Free Software Foundation, 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
20 */
21
27#include "generated/modules.h"
28#include "modules/imu/imu.h"
29#include "modules/core/abi.h"
30#include "mcu_periph/spi.h"
34
35/* Different IMU's for different revisions */
36#if IMU_PIXHAWK6X_REV == 8
37static struct invensense3_456_t imu1;
38static struct invensense3_456_t imu2;
39static struct invensense3_456_t imu3;
40#else
41static struct invensense3_t imu1;
42static struct invensense3_t imu2;
43static struct invensense2_t imu3;
44#endif
45
47{
48 struct Int32RMat rmat;
49 struct Int32Eulers eulers;
50
51 /* IMU 1 */
52#if IMU_PIXHAWK6X_REV == 8
53 // ICM45686
56 imu1.spi.slave_idx = PIXHAWK6X_IMU1_SPI_SLAVE_IDX;
59
60 // Rotation 90 yaw
61 eulers.phi = ANGLE_BFP_OF_REAL(0);
62 eulers.theta = ANGLE_BFP_OF_REAL(0);
63 eulers.psi = ANGLE_BFP_OF_REAL(RadOfDeg(90));
64 int32_rmat_of_eulers(&rmat, &eulers);
67#else
68 // ICM42670
73 imu1.spi.slave_idx = PIXHAWK6X_IMU1_SPI_SLAVE_IDX;
74
79 imu1.gyro_aaf = 977; // ~ODR/4
80 imu1.accel_aaf = 213; // Fixed
82
83 // Rotation 90 yaw
84 eulers.phi = ANGLE_BFP_OF_REAL(0);
85 eulers.theta = ANGLE_BFP_OF_REAL(0);
86 eulers.psi = ANGLE_BFP_OF_REAL(RadOfDeg(90));
87 int32_rmat_of_eulers(&rmat, &eulers);
90#endif
91
92 /* IMU 2 */
93#if IMU_PIXHAWK6X_REV == 8
94 // ICM45686
97 imu2.spi.slave_idx = PIXHAWK6X_IMU2_SPI_SLAVE_IDX;
100
101 // Rotation 180 roll
102 eulers.phi = ANGLE_BFP_OF_REAL(RadOfDeg(180));
103 eulers.theta = ANGLE_BFP_OF_REAL(0);
104 eulers.psi = ANGLE_BFP_OF_REAL(0);
105 int32_rmat_of_eulers(&rmat, &eulers);
108#else
109 // ICM42670
114 imu2.spi.slave_idx = PIXHAWK6X_IMU2_SPI_SLAVE_IDX;
115
120 imu2.gyro_aaf = 977; // ~ODR/4
121 imu2.accel_aaf = 213; // Fixed
123
124 // Rotation 180 pitch and 90 yaw
125 eulers.phi = ANGLE_BFP_OF_REAL(0);
126 eulers.theta = ANGLE_BFP_OF_REAL(RadOfDeg(180));
127 eulers.psi = ANGLE_BFP_OF_REAL(RadOfDeg(90));
128 int32_rmat_of_eulers(&rmat, &eulers);
131#endif
132
133 /* IMU 3 */
134#if IMU_PIXHAWK6X_REV == 8
135 // ICM45686
138 imu3.spi.slave_idx = PIXHAWK6X_IMU3_SPI_SLAVE_IDX;
141
142 // Rotation 180 roll
143 eulers.phi = ANGLE_BFP_OF_REAL(RadOfDeg(180));
144 eulers.theta = ANGLE_BFP_OF_REAL(0);
145 eulers.psi = ANGLE_BFP_OF_REAL(0);
146 int32_rmat_of_eulers(&rmat, &eulers);
149#else
150 // ICM42670
154 imu3.spi.slave_idx = PIXHAWK6X_IMU3_SPI_SLAVE_IDX;
160
161 //Rotation 180 yaw
162 eulers.phi = ANGLE_BFP_OF_REAL(0);
163 eulers.theta = ANGLE_BFP_OF_REAL(0);
164 eulers.psi = ANGLE_BFP_OF_REAL(RadOfDeg(180));
165 int32_rmat_of_eulers(&rmat, &eulers);
168#endif
169}
170
172{
173#if IMU_PIXHAWK6X_REV == 8
177#else
181#endif
182}
183
185{
186#if IMU_PIXHAWK6X_REV == 8
190#else
194#endif
195}
Main include for ABI (AirBorneInterface).
#define IMU_PIXHAWK2_ID
#define IMU_PIXHAWK3_ID
#define IMU_PIXHAWK1_ID
int32_t phi
in rad with INT32_ANGLE_FRAC
int32_t psi
in rad with INT32_ANGLE_FRAC
int32_t theta
in rad with INT32_ANGLE_FRAC
#define ANGLE_BFP_OF_REAL(_af)
#define int32_rmat_of_eulers
Rotation matrix from Euler angles.
euler angles
rotation matrix
void imu_set_defaults_gyro(uint8_t abi_id, const struct Int32RMat *imu_to_sensor, const struct Int32Rates *neutral, const struct FloatRates *scale_f)
Set the defaults for a gyro sensor WARNING: Should be called before sensor is publishing messages to ...
Definition imu.c:640
void imu_set_defaults_accel(uint8_t abi_id, const struct Int32RMat *imu_to_sensor, const struct Int32Vect3 *neutral, const struct FloatVect3 *scale_f)
Set the defaults for a accel sensor WARNING: Should be called before sensor is publishing messages to...
Definition imu.c:669
Inertial Measurement Unit interface.
static struct invensense2_t imu3
void imu_pixhawk6x_init(void)
static struct invensense3_t imu1
static struct invensense3_t imu2
void imu_pixhawk6x_event(void)
void imu_pixhawk6x_periodic(void)
void invensense2_event(struct invensense2_t *inv)
Should be called in the event thread.
void invensense2_periodic(struct invensense2_t *inv)
Should be called periodically to request sensor readings.
void invensense2_init(struct invensense2_t *inv)
Initialize the invensense v2 sensor instance.
Definition invensense2.c:69
Driver for the Invensense V2 IMUs ICM20948, ICM20648 and ICM20649.
enum invensense2_accel_range_t accel_range
Accelerometer range configuration.
@ INVENSENSE2_GYRO_DLPF_229HZ
Definition invensense2.h:82
@ INVENSENSE2_GYRO_RANGE_4000DPS
Only possible for ICM20649.
Definition invensense2.h:98
enum invensense2_gyro_dlpf_t gyro_dlpf
Gyro DLPF configuration.
@ INVENSENSE2_ACCEL_RANGE_30G
Only possible for ICM20649.
@ INVENSENSE2_ACCEL_DLPF_265HZ
enum invensense2_bus_t bus
The communication bus used to connect the device SPI/I2C.
enum invensense2_accel_dlpf_t accel_dlpf
Accelerometer DLPF configuration.
uint8_t abi_id
The ABI id used to broadcast the device measurements.
@ INVENSENSE2_SPI
Definition invensense2.h:60
enum invensense2_gyro_range_t gyro_range
Gyro range configuration.
void invensense3_periodic(struct invensense3_t *inv)
Should be called periodically to request sensor readings.
void invensense3_event(struct invensense3_t *inv)
Should be called in the event thread.
void invensense3_init(struct invensense3_t *inv)
Initialize the invensense v3 sensor instance.
Driver for the Invensense V3 IMUs ICM40605, ICM40609, ICM42605, IIM42652 and ICM42688.
enum invensense3_gyro_range_t gyro_range
Gyro range configuration.
@ INVENSENSE3_ACCEL_RANGE_32G
Only possible for ICM40609.
@ INVENSENSE3_GYRO_ODR_4KHZ
Definition invensense3.h:99
enum invensense3_parser_t parser
Parser of the device.
uint16_t accel_aaf
Accelerometer Anti-alias filter 3dB Bandwidth configuration [Hz].
@ INVENSENSE3_PARSER_FIFO
Definition invensense3.h:74
enum invensense3_accel_odr_t accel_odr
Accelerometer Output Data Rate configuration.
@ INVENSENSE3_ACCEL_ODR_4KHZ
enum invensense3_bus_t bus
The communication bus used to connect the device SPI/I2C.
@ INVENSENSE3_GYRO_RANGE_2000DPS
@ INVENSENSE3_SPI
Definition invensense3.h:60
enum invensense3_accel_range_t accel_range
Accelerometer range configuration.
uint8_t abi_id
The ABI id used to broadcast the device measurements.
uint16_t gyro_aaf
Gyro Anti-alias filter 3dB Bandwidth configuration [Hz].
enum invensense3_gyro_odr_t gyro_odr
Gyro Output Data Rate configuration.
void invensense3_456_init(struct invensense3_456_t *inv)
Initialize the invensense v3 sensor instance.
void invensense3_456_event(struct invensense3_456_t *inv)
Should be called in the event thread.
void invensense3_456_periodic(struct invensense3_456_t *inv)
Should be called periodically to request sensor readings.
Driver for the Invensense 456XY IMUs:
@ INVENSENSE3_456_ODR_6_4KHZ
uint16_t foo
Definition main_demo5.c:58
Architecture independent SPI (Serial Peripheral Interface) API.