Paparazzi UAS v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
Loading...
Searching...
No Matches
mag_uavcan.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2025 FabienB <fabien-b@github.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
27#include "uavcan/uavcan.h"
28#include "core/abi.h"
29#include "uavcan.equipment.ahrs.MagneticFieldStrength.h"
30#include "uavcan.equipment.ahrs.MagneticFieldStrength2.h"
31#include "imu/imu.h"
33
36
37static struct FloatVect3 default_uavcan_mag_scale = {1,1,1};
38
39
41 // current timestamp
43
46 return; // decode error
47 }
48
49 // The LIS3MDL module configure a +/- 4 gauss sensitivity, for 16bits data.
50 // (2**15)/4 = 8192
51 struct Int32Vect3 mag = {
52 msg.magnetic_field_ga[0] * 8192,
53 msg.magnetic_field_ga[1] * 8192,
54 msg.magnetic_field_ga[2] * 8192,
55 };
56
58
59#if MAG_UAVCAN_SYNC_SEND
61 DOWNLINK_SEND_IMU_MAG_RAW(DefaultChannel, DefaultDevice, &abi_id, &mag.x, &mag.y, &mag.z);
62#endif
63
64}
65
67 // current timestamp
69
72 return; // decode error
73 }
74
75 // The LIS3MDL module configure a +/- 4 gauss sensitivity, for 16bits data.
76 // (2**15)/4 = 8192
77 struct Int32Vect3 mag = {
78 msg.magnetic_field_ga[0] * 8192,
79 msg.magnetic_field_ga[1] * 8192,
80 msg.magnetic_field_ga[2] * 8192,
81 };
82
83 // use sensor_id as abi_id
84 AbiSendMsgIMU_MAG_RAW(msg.sensor_id, now_ts, &mag);
85
86#if MAG_UAVCAN_SYNC_SEND
87 DOWNLINK_SEND_IMU_MAG_RAW(DefaultChannel, DefaultDevice, &msg.sensor_id, &mag.x, &mag.y, &mag.z);
88#endif
89
90}
91
92
93
Main include for ABI (AirBorneInterface).
#define MAG_UAVCAN_SENDER_ID
uint32_t get_sys_time_usec(void)
Get the time in microseconds since startup.
Main uavcan event structure for registering/calling callbacks.
Definition uavcan.h:76
#define int32_rmat_of_eulers
Rotation matrix from Euler angles.
euler angles
rotation matrix
uint8_t msg[10]
Buffer used for general comunication over SPI (out buffer)
void imu_set_defaults_mag(uint8_t abi_id, const struct Int32RMat *imu_to_sensor, const struct Int32Vect3 *neutral, const struct FloatVect3 *scale_f)
Set the defaults for a mag sensor WARNING: Should be called before sensor is publishing messages to e...
Definition imu.c:674
Inertial Measurement Unit interface.
void mag_uavcan_init(void)
Definition mag_uavcan.c:94
static uavcan_event mag_uavcan_ev
Definition mag_uavcan.c:34
static struct FloatVect3 default_uavcan_mag_scale
Definition mag_uavcan.c:37
static void mag_uavcan_cb(struct uavcan_iface_t *iface, CanardRxTransfer *transfer)
Definition mag_uavcan.c:40
static uavcan_event mag_uavcan_ev2
Definition mag_uavcan.c:35
static void mag_uavcan_cb2(struct uavcan_iface_t *iface, CanardRxTransfer *transfer)
Definition mag_uavcan.c:66
uint16_t foo
Definition main_demo5.c:58
uavcan interface structure
Definition uavcan.h:46
void uavcan_bind(uint16_t data_type_id, uint64_t data_type_signature, uavcan_event *ev, uavcan_callback cb)
Bind to a receiving message from uavcan.
Definition uavcan.c:250
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
int transfer(const Mat *from, const image_t *to)