Paparazzi UAS  v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
sys_id_auto_doublets.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2023 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 
25 #include "std.h"
26 
30 
31 #include "mcu_periph/sys_time.h"
32 #include "generated/airframe.h"
33 
34 // Perform checks if mandatory macros are defined
35 
36 #ifndef SYS_ID_AUTO_DOUBLETS_N_ACTUATORS
37 #error No doublet actuators SYS_ID_AUTO_DOUBLETS_N_ACTUATORS defined
38 #endif
39 
40 #ifndef SYS_ID_AUTO_DOUBLETS_ACTUATORS
41 #error No doublet actuators SYS_ID_AUTO_DOUBLETS_ACTUATORS defined
42 #endif
43 
44 #ifndef SYS_ID_AUTO_DOUBLETS_AMPLITUDE
45 #error No doublet actuators SYS_ID_AUTO_DOUBLETS_AMPLITUDE defined
46 #endif
47 
48 uint8_t sys_id_auto_doublets_actuators[SYS_ID_AUTO_DOUBLETS_N_ACTUATORS] = SYS_ID_AUTO_DOUBLETS_ACTUATORS;
49 int16_t sys_id_auto_doublets_amplitude[SYS_ID_AUTO_DOUBLETS_N_ACTUATORS] = SYS_ID_AUTO_DOUBLETS_AMPLITUDE;
50 
51 float sys_id_auto_doublets_time = 0.5; // time of one doublet
52 float sys_id_auto_doublets_interval_time = 5.; // time interval for doublets
53 int8_t sys_id_auto_doublets_n_repeat = 5; // The number of times a doublet has to be repeated on a single actuator
54 
56 
57 // Other variables needed for the periodic loop
59 
63 
64 inline void perform_sys_id_auto_doublets(uint8_t actuator_index);
65 inline void sys_id_auto_doublets_on_deactivation(void);
66 
68 {
69  sys_id_auto_doublets_n_doublets = SYS_ID_AUTO_DOUBLETS_N_ACTUATORS * sys_id_auto_doublets_n_repeat;
73 }
74 
76 {
77  // your periodic code here.
78  // freq = 20.0 Hz
79 
80  // Run if doublet activated
82  {
83  float current_time_s = get_sys_time_float();
85 
86  // Check when to increase the counters and perform doublet
88 
89  // stop doublets when all doublets done
90  if (current_index >= sys_id_auto_doublets_n_doublets)
91  {
93  }
94  else
95  { // continue doublets when not finished yet
96  // Check if doublet should be performed and index inxreased
97  if (current_index > sys_id_auto_doublets_counter)
98  {
99  uint8_t actuator_index = current_index / sys_id_auto_doublets_n_repeat;
100  perform_sys_id_auto_doublets(actuator_index);
102  }
103  }
104  }
105 }
106 
108 {
109  // Do nothing id doublet index is invalid
110  if (actuator_index >= SYS_ID_AUTO_DOUBLETS_N_ACTUATORS)
111  {
112  return;
113  }
114  // Set correct settings
118 
119  // call doublet activation handler
121 }
122 
124 {
126  // If the activation boolean is set to true
128  {
130  {
131  // Do nothing if already activated
132  }
133  else
134  {
135  // Activate auto doublet if not activated yet
139  }
140  }
141  else
142  { // If the activation boolean is set to false
144  }
145 }
146 
148 {
149  // call doublet deactivation handler
154  doublet_amplitude = 0;
155 }
uint8_t sys_id_auto_doublets_n_doublets
uint8_t sys_id_auto_doublets_actuators[SYS_ID_AUTO_DOUBLETS_N_ACTUATORS]
int8_t sys_id_auto_doublets_n_repeat
float sys_id_auto_doublets_interval_time
void periodic_sys_id_auto_doublets(void)
void sys_id_auto_doublets_on_deactivation(void)
void init_sys_id_auto_doublets(void)
void perform_sys_id_auto_doublets(uint8_t actuator_index)
bool sys_id_auto_doublets_activated
uint8_t sys_id_auto_doublets_counter
float sys_id_auto_doublets_time
void sys_id_auto_doublets_on_activation(uint8_t active)
float sys_id_auto_doublets_start_time_s
float sys_id_auto_doublets_timer
int16_t sys_id_auto_doublets_amplitude[SYS_ID_AUTO_DOUBLETS_N_ACTUATORS]
void sys_id_doublet_activate_handler(uint8_t activate)
float doublet_length_s
void sys_id_doublet_axis_handler(uint8_t axis)
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
short int16_t
Typedef defining 16 bit short type.
Definition: vl53l1_types.h:93
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