Paparazzi UAS  v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
range_sensor_uavcan.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2023 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, write to
18  * the Free Software Foundation, 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  */
21 
26 #include "range_sensor_uavcan.h"
27 #include "uavcan/uavcan.h"
28 #include "core/abi.h"
29 
30 
31 /* uavcan EQUIPMENT_RANGE_SENSOR_MEASUREMENT message definition */
32 #define UAVCAN_EQUIPMENT_RANGE_SENSOR_MEASUREMENT_ID 1050
33 #define UAVCAN_EQUIPMENT_RANGE_SENSOR_MEASUREMENT_SIGNATURE (0x68FFFE70FC771952ULL)
34 #define UAVCAN_EQUIPMENT_RANGE_SENSOR_MEASUREMENT_MAX_SIZE ((120 + 7)/8)
35 
36 /* Local structure */
38  float range;
40 };
41 
42 /* Local variables */
43 static struct range_sensor_uavcan_t range_sensor_uavcan = {0};
45 
46 #if PERIODIC_TELEMETRY
48 
49 static void range_sensor_uavcan_send_lidar(struct transport_tx *trans, struct link_device *dev)
50 {
51  uint8_t nul = 0;
52  pprz_msg_send_LIDAR(trans, dev, AC_ID,
55  &nul);
56 }
57 
58 #endif
59 
60 static void range_sensor_uavcan_cb(struct uavcan_iface_t *iface __attribute__((unused)), CanardRxTransfer *transfer) {
61  uint16_t tmp_float = 0;
62 
63  /* Decode the message */
64  //canardDecodeScalar(transfer, (uint32_t)0, 56, false, (void*)&dest->usec);
65  //canardDecodeScalar(transfer, (uint32_t)56, 8, false, (void*)&dest->sensor_id);
66  //canardDecodeScalar(transfer, (uint32_t)64, 5, true, (void*)(dest->fixed_axis_roll_pitch_yaw + 0));
67  //canardDecodeScalar(transfer, (uint32_t)69, 5, true, (void*)(dest->fixed_axis_roll_pitch_yaw + 1));
68  //canardDecodeScalar(transfer, (uint32_t)74, 5, true, (void*)(dest->fixed_axis_roll_pitch_yaw + 2));
69  //canardDecodeScalar(transfer, (uint32_t)79, 1, false, (void*)&dest->orientation_defined);
70  //canardDecodeScalar(transfer, (uint32_t)80, 16, false, (void*)&tmp_float);
71  //float fov = canardConvertFloat16ToNativeFloat(tmp_float);
72  //canardDecodeScalar(transfer, (uint32_t)96, 5, false, (void*)&dest->sensor_type);
73  canardDecodeScalar(transfer, (uint32_t)101, 3, false, (void*)&range_sensor_uavcan.reading_type);
74  canardDecodeScalar(transfer, (uint32_t)104, 16, false, (void*)&tmp_float);
75  range_sensor_uavcan.range = canardConvertFloat16ToNativeFloat(tmp_float);
76 
77  // Send the range over ABI
78  if(!isnan(range_sensor_uavcan.range)) {
79  uint32_t now_ts = get_sys_time_usec();
80  AbiSendMsgAGL(AGL_UAVCAN_ID, now_ts, range_sensor_uavcan.range);
81  }
82 }
83 
85 {
86  // Bind uavcan MEASUREMENT message from EQUIPMENT.RANGE_SENSOR
88 
89 #if PERIODIC_TELEMETRY
91 #endif
92 }
Main include for ABI (AirBorneInterface).
#define AGL_UAVCAN_ID
uint32_t get_sys_time_usec(void)
Get the time in microseconds since startup.
Definition: sys_time_arch.c:71
Main uavcan event structure for registering/calling callbacks.
Definition: uavcan.h:60
static struct range_sensor_uavcan_t range_sensor_uavcan
static void range_sensor_uavcan_cb(struct uavcan_iface_t *iface, CanardRxTransfer *transfer)
void range_sensor_uavcan_init(void)
#define UAVCAN_EQUIPMENT_RANGE_SENSOR_MEASUREMENT_ID
static uavcan_event range_sensor_uavcan_ev
#define UAVCAN_EQUIPMENT_RANGE_SENSOR_MEASUREMENT_SIGNATURE
static void range_sensor_uavcan_send_lidar(struct transport_tx *trans, struct link_device *dev)
Range sensor sensor on the uavcan bus.
uavcan interface structure
Definition: uavcan.h:34
static const struct usb_device_descriptor dev
Definition: usb_ser_hw.c:74
int8_t register_periodic_telemetry(struct periodic_telemetry *_pt, uint8_t _id, telemetry_cb _cb)
Register a telemetry callback function.
Definition: telemetry.c:51
Periodic telemetry system header (includes downlink utility and generated code).
#define DefaultPeriodic
Set default periodic telemetry.
Definition: telemetry.h:66
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:412
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
Definition: vl53l1_types.h:88
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
int transfer(const Mat *from, const image_t *to)