Paparazzi UAS v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
glide_wing_lock.c
Go to the documentation of this file.
1/*
2 * Copyright (C) Kevin van Hecke
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 */
27
28#include "pprzlink/messages.h"
29#include "mcu_periph/uart.h"
31
32#include "mcu_periph/adc.h"
35#include "autopilot.h"
36
38
40
41#ifndef WING_POS_DOWN_THRESH
42#define WING_POS_DOWN_THRESH 100
43#endif
44#ifndef WING_POS_LOCK_MIN_THRESH
45#define WING_POS_LOCK_MIN_THRESH 2000
46#endif
47#ifndef WING_POS_LOCK_MAX_THRESH
48#define WING_POS_LOCK_MAX_THRESH 2100
49#endif
50#ifndef WING_POS_NOMINAL_THRUST
51#define WING_POS_NOMINAL_THRUST 5000
52#endif
53#ifndef WING_POS_LOCK_SWITCH
54#define WING_POS_LOCK_SWITCH RADIO_AUX2
55#endif
56
57
62
64{
65 static int lockstate = 0;
66 if (radio_control.values[WING_POS_LOCK_SWITCH] > (MIN_PPRZ / 2)) { // check glide switch
68 switch (lockstate) {
69 case 0:
70 if (wpos < WING_POS_DOWN_THRESH) { //set wings to fixed speed for one rotation starting from when wings are at lowest position
71 lock_wings = 1;
72 lockstate++;
73 }
74 break;
75 case 1:
76 if (wpos > WING_POS_LOCK_MIN_THRESH) { //start wait for a rotation
77 lockstate++;
78 }
79 break;
80 case 2:
81 if (wpos < WING_POS_DOWN_THRESH) { //rotation finished
82 lockstate++;
83 }
84 break;
85 case 3:
86 if (wpos > WING_POS_LOCK_MIN_THRESH && wpos < WING_POS_LOCK_MAX_THRESH) { // wait for exact wing position
87 //esc brakes when throttle = 0, which should lock the wing in this position;
88 lock_wings = 2;
89 lockstate++;
90 }
91 break;
92 default:
93 break;
94 }
95 } else {
96 lock_wings = 0;
97 lockstate = 0;
98 }
99}
100
106
107void set_rotorcraft_commands(pprz_t *cmd_out, int32_t *cmd_in, bool in_flight, bool motors_on)
108{
109 if (!(in_flight)) { cmd_in[COMMAND_YAW] = 0; }
110 if (!(motors_on)) { cmd_in[COMMAND_THRUST] = 0; }
115
116 if (lock_wings == 1 && motors_on && cmd_out[COMMAND_THRUST] > 0) {
118 } else if (lock_wings == 2) {
120 }
121}
122
123
124
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
Core autopilot interface common to all firmwares.
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
Hardware independent code for commands handling.
#define WING_POS_LOCK_MIN_THRESH
int lock_wings
void glide_wing_lock_init(void)
struct adc_buf adcbuf
void set_rotorcraft_commands(pprz_t *cmd_out, int32_t *cmd_in, bool in_flight, bool motors_on)
Set Rotorcraft commands.
#define WING_POS_NOMINAL_THRUST
#define WING_POS_DOWN_THRESH
#define WING_POS_LOCK_MAX_THRESH
void glide_wing_lock_event()
#define WING_POS_LOCK_SWITCH
void glide_wing_lock_periodic()
uint16_t foo
Definition main_demo5.c:58
int16_t pprz_t
Definition paparazzi.h:6
#define MIN_PPRZ
Definition paparazzi.h:9
struct RadioControl radio_control
Generic interface for radio control modules.
pprz_t values[RADIO_CONTROL_NB_CHANNEL]
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
int int32_t
Typedef defining 32 bit int type.