Paparazzi UAS  v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
sys_id_doublet.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) Alessandro Collicelli
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  */
34 #include "std.h"
35 
36 #include "sys_id_doublet.h"
37 #include "pprz_doublet.h"
38 
40 #include "generated/airframe.h"
41 #include "mcu_periph/sys_time.h"
42 
43 #ifndef SYS_ID_DOUBLET_AXES
44 #define SYS_ID_DOUBLET_AXES {COMMAND_ROLL,COMMAND_PITCH,COMMAND_YAW,COMMAND_THRUST}
45 #endif
46 
47 #ifndef SYS_ID_DOUBLET_ENABLED
48 #define SYS_ID_DOUBLET_ENABLED TRUE
49 #endif
50 
51 #ifdef SYS_ID_DOUBLET_RADIO_CHANNEL
53 pprz_t previous_radio_value_doublet = 0;
54 #endif
55 
56 
57 static struct doublet_t doublet;
58 
61 
63 
65 float doublet_length_s = 0.5f;
67 
68 
69 
71 #define SYS_ID_DOUBLET_NB_AXES sizeof SYS_ID_ACTIVE_DOUBLET_AXES / sizeof SYS_ID_ACTIVE_DOUBLET_AXES[0] // Number of items in ACTIVE_DOUBLET_AXES
72 
74 
75 static void set_current_doublet_values(void)
76 {
77  if (doublet_active) {
79 
80  } else {
81  for (uint8_t i = 0; i < SYS_ID_DOUBLET_NB_AXES; i++) {
83  }
84  }
85 }
86 
87 static void send_doublet(struct transport_tx *trans, struct link_device *dev){
88  pprz_msg_send_DOUBLET(trans, dev, AC_ID, &doublet_active,
91 }
92 
93 static void start_doublet(void)
94 {
96  doublet_active = true;
98 }
99 
100 static void stop_doublet(void)
101 {
103  doublet_active = false;
105 }
106 
108  return doublet_active;
109 }
110 
112 {
113  doublet_active = activate;
114  #ifdef DOUBLET_RADIO_CHANNEL
115  // Don't activate doublet when radio signal is low
116  if (radio_control.values[SYS_ID_DOUBLET_RADIO_CHANNEL] < 1750)
117  {
118  doublet_active = 0;
119  }
120  #endif
121  if (doublet_active) {
123  start_doublet();
124  } else {
125  stop_doublet();
126  }
127 }
128 
130 {
131  if (axis < SYS_ID_DOUBLET_NB_AXES) {
132  doublet_axis = axis;
133  }
134 }
135 
137  doublet_mode = mode;
138 }
139 
141 {
143 
146 
147  for (uint8_t i = 0; i < SYS_ID_DOUBLET_NB_AXES; i++) {
148  current_doublet_values[i] = 0;
149  }
150 }
151 
153 {
154  #ifdef SYS_ID_DOUBLET_RADIO_CHANNEL
155  // Check if doublet switched on when off before
156  if (previous_radio_value_doublet < 1750)
157  {
158  if (radio_control.values[SYS_ID_DOUBLET_RADIO_CHANNEL] > 1750)
159  {
160  // Activate doublet
162  }
163  }
164  // Check if doublet switched off when on before
165  if (previous_radio_value_doublet > 1750)
166  {
167  if (radio_control.values[SYS_ID_DOUBLET_RADIO_CHANNEL] < 1750)
168  {
169  // Deactivate doublet
171  }
172  }
173  previous_radio_value_doublet = radio_control.values[SYS_ID_DOUBLET_RADIO_CHANNEL];
174  #endif
175  if (doublet_active) {
177  stop_doublet();
178  } else {
181  }
182  }
183 
184 
185 }
186 
187 void sys_id_doublet_add_values(bool UNUSED motors_on, bool UNUSED override_on, pprz_t UNUSED in_cmd[])
188 {
189 
190 #if SYS_ID_DOUBLET_ENABLED
191 
192 if (motors_on) {
193  for (uint8_t i = 0; i < SYS_ID_DOUBLET_NB_AXES; i++) {
195  BoundAbs(in_cmd[SYS_ID_ACTIVE_DOUBLET_AXES[i]], MAX_PPRZ);
196  }
197 }
198 
199 #endif
200 }
uint8_t last_wp UNUSED
int16_t pprz_t
Definition: paparazzi.h:6
#define MAX_PPRZ
Definition: paparazzi.h:8
void doublet_init(struct doublet_t *doublet, float length_s, float extra_waiting_time_s, float current_time_s, uint8_t mod)
Definition: pprz_doublet.c:31
bool doublet_is_running(struct doublet_t *doublet, float current_time_s)
Definition: pprz_doublet.c:67
void doublet_reset(struct doublet_t *doublet, float current_time_s)
Definition: pprz_doublet.c:61
float doublet_update(struct doublet_t *doublet, float current_time_s)
Definition: pprz_doublet.c:72
float current_value
Definition: pprz_doublet.h:65
Initialize with doublet_init.
Definition: pprz_doublet.h:56
struct RadioControl radio_control
Definition: radio_control.c:33
Generic interface for radio control modules.
pprz_t values[RADIO_CONTROL_NB_CHANNEL]
Definition: radio_control.h:67
static uint8_t mode
mode holds the current sonar mode mode = 0 used at high altitude, uses 16 wave patterns mode = 1 used...
Definition: sonar_bebop.c:65
static const struct usb_device_descriptor dev
Definition: usb_ser_hw.c:74
static pprz_t current_doublet_values[SYS_ID_DOUBLET_NB_AXES]
uint8_t doublet_active
uint8_t doublet_mode
static struct doublet_t doublet
void sys_id_doublet_activate_handler(uint8_t activate)
static void send_doublet(struct transport_tx *trans, struct link_device *dev)
float doublet_extra_waiting_time_s
static void set_current_doublet_values(void)
void sys_id_doublet_add_values(bool UNUSED motors_on, bool UNUSED override_on, pprz_t UNUSED in_cmd[])
void sys_id_doublet_init(void)
float doublet_length_s
#define SYS_ID_DOUBLET_AXES
#define SYS_ID_DOUBLET_NB_AXES
void sys_id_doublet_axis_handler(uint8_t axis)
void sys_id_doublet_run(void)
uint8_t doublet_axis
uint8_t sys_id_doublet_running(void)
static void stop_doublet(void)
static void start_doublet(void)
void sys_id_doublet_mod_handler(uint8_t mode)
static const int8_t SYS_ID_ACTIVE_DOUBLET_AXES[]
pprz_t doublet_amplitude
Architecture independent timing functions.
static float get_sys_time_float(void)
Get the time in seconds since startup.
Definition: sys_time.h:138
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
int int32_t
Typedef defining 32 bit int type.
Definition: vl53l1_types.h:83
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
Definition: vl53l1_types.h:98
signed char int8_t
Typedef defining 8 bit char type.
Definition: vl53l1_types.h:103