Paparazzi UAS v7.1_unstable
Paparazzi is a free software Unmanned Aircraft System.
Loading...
Searching...
No Matches
radio_control_uavcan.c
Go to the documentation of this file.
1 /*
2 * Radio control over uavcan
3 * Copyright (C) 2026 Fabien-B <fabien-b@github.com>
4 * This file is part of paparazzi. See LICENCE file.
5 */
6
11
14#include "uavcan/uavcan.h"
15#include "modules/core/abi.h"
17#include "dronecan.sensors.rc.RCInput.h"
18#include "generated/radio.h"
19
21
22struct dronecan_sensors_rc_RCInput rc_dronecan_msg;
25
26
27static void rc_uavcan_cb(struct uavcan_iface_t *iface __attribute__((unused)), CanardRxTransfer *transfer) {
28 if(pprz_mtx_trylock(&rc_mtx) == 0) {
29 if(dronecan_sensors_rc_RCInput_decode(transfer, &rc_dronecan_msg)) {
30 return; // decode error
31 }
32 rc_frame_available = true;
34 }
35}
36
38{
40 rc_frame_available = false;
41 radio_control.nb_channel = 32; // max value
42 uavcan_bind(DRONECAN_SENSORS_RC_RCINPUT_ID, DRONECAN_SENSORS_RC_RCINPUT_SIGNATURE, &rc_uavcan_ev, &rc_uavcan_cb);
43}
44
45
47{
48 bool send_abi = false;
50 if(pprz_mtx_trylock(&rc_mtx) == 0) {
51 if((rc_dronecan_msg.status & DRONECAN_SENSORS_RC_RCINPUT_STATUS_FAILSAFE) ||
52 (rc_dronecan_msg.status & DRONECAN_SENSORS_RC_RCINPUT_STATUS_QUALITY_VALID && rc_dronecan_msg.quality == 0)) {
53 // RC LOST
54 } else {
55 radio_control.nb_channel = rc_dronecan_msg.rcin.len;
56 radio_control.frame_cpt++;
57 radio_control.time_since_last_frame = 0;
58 radio_control.radio_ok_cpt = 0;
59 radio_control.status = RC_OK;
60
61 NormalizePpmIIR(rc_dronecan_msg.rcin.data, radio_control);
62
63 send_abi = true;
64 }
65
66 rc_frame_available = false;
68 }
69
70 if(send_abi) {
71 AbiSendMsgRADIO_CONTROL(RADIO_CONTROL_UAVCAN_ID, &radio_control);
72 }
73 }
74}
75
76
Main include for ABI (AirBorneInterface).
#define RADIO_CONTROL_UAVCAN_ID
int pprz_mtx_trylock(pprz_mutex_t *mtx)
Performs a nonblocking lock on the mutex.
int pprz_mtx_unlock(pprz_mutex_t *mtx)
int pprz_mtx_init(pprz_mutex_t *mtx)
struct RadioControl radio_control
Generic interface for radio control modules.
#define RC_OK
static pprz_mutex_t rc_mtx
void rc_uavcan_init(void)
static bool rc_frame_available
static void rc_uavcan_cb(struct uavcan_iface_t *iface, CanardRxTransfer *transfer)
static uavcan_event rc_uavcan_ev
struct dronecan_sensors_rc_RCInput rc_dronecan_msg
void rc_uavcan_event(void)
struct pprzMutex pprz_mutex_t
Definition threads.h:21
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:272
struct uavcan_event_t uavcan_event
Definition uavcan.h:98
int transfer(const Mat *from, const image_t *to)