Paparazzi UAS  v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
wing_rotation_adc_sensor.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2022 Dennis van Wijngaarden <D.C.vanWijngaarden@tudelft.nl>
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 "generated/airframe.h"
28 #include "modules/core/abi.h"
29 
30 #include <stdlib.h>
31 #include "mcu_periph/adc.h"
32 
33 /*** ADC channel connected to the wing rotation potentiometer */
34 #ifndef ADC_CHANNEL_WING_ROTATION_CONTROLLER_POSITION
35 #define ADC_CHANNEL_WING_ROTATION_CONTROLLER_POSITION ADC_5
36 #endif
37 
38 #ifndef ADC_CHANNEL_WING_ROTATION_CONTROLLER_POSITION_NB_SAMPLES
39 #define ADC_CHANNEL_WING_ROTATION_CONTROLLER_POSITION_NB_SAMPLES 16
40 #endif
41 
42 #ifndef ADC_WING_ROT_OFFSET
43 #error "ADC_WING_ROT_OFFSET not defined"
44 #endif
45 
46 #ifndef ADC_WING_ROT_SCALE
47 #error "ADC_WING_ROT_SCALE not defined"
48 #endif
49 
50 #ifdef ADC_WING_ROT_OFFSET
51 static float adc_offset = ADC_WING_ROT_OFFSET;
52 #endif
53 
54 #ifdef ADC_WING_ROT_SCALE
55 static float adc_scale = ADC_WING_ROT_SCALE;
56 #endif
57 
58 static struct adc_buf buf_wing_rot_pos;
59 // Initialization
61 {
62  // ADC init
65 }
66 
68 {
69  float adc_wing_rotation = buf_wing_rot_pos.sum / buf_wing_rot_pos.av_nb_sample;
70  float wing_angle_deg = adc_scale * adc_wing_rotation + adc_offset;
71 
72  // SEND ABI Message to ctr_eff_sched and other modules that want Actuator position feedback
73  struct act_feedback_t feedback = {0};
74  feedback.idx = SERVO_ROTATION_MECH_IDX;
75  feedback.position = 0.5 * M_PI - RadOfDeg(wing_angle_deg);
76  feedback.set.position = true;
77 
78  // Send ABI message
79  AbiSendMsgACT_FEEDBACK(ACT_FEEDBACK_UAVCAN_ID, &feedback, 1);
80 }
Main include for ABI (AirBorneInterface).
#define ACT_FEEDBACK_UAVCAN_ID
arch independent ADC (Analog to Digital Converter) API
uint32_t sum
Definition: adc.h:54
uint8_t av_nb_sample
Definition: adc.h:57
Generic interface for all ADC hardware drivers, independent from microcontroller architecture.
Definition: adc.h:53
void adc_buf_channel(uint8_t adc_channel, struct adc_buf *s, uint8_t av_nb_sample)
Link between ChibiOS ADC drivers and Paparazzi adc_buffers.
Definition: adc_arch.c:312
bool position
Position is set.
Definition: actuators.h:48
struct act_feedback_t::act_feedback_set_t set
Bitset registering what is set as feedback.
uint8_t idx
General index of the actuators (generated in airframe.h)
Definition: actuators.h:45
float position
In radians.
Definition: actuators.h:52
#define ADC_CHANNEL_WING_ROTATION_CONTROLLER_POSITION
void wing_rotation_adc_to_deg(void)
void wing_rotation_adc_init(void)
static struct adc_buf buf_wing_rot_pos
#define ADC_CHANNEL_WING_ROTATION_CONTROLLER_POSITION_NB_SAMPLES