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 #ifndef SYS_ID_AUTO_DOUBLETS_TIME
49 #define SYS_ID_AUTO_DOUBLETS_TIME 0.5
50 #endif
51 
52 #ifndef SYS_ID_AUTO_DOUBLETS_INTERVAL
53 #define SYS_ID_AUTO_DOUBLETS_INTERVAL 5.0
54 #endif
55 
56 #ifndef SYS_ID_AUTO_DOUBLETS_REPEATS
57 #define SYS_ID_AUTO_DOUBLETS_REPEATS 5
58 #endif
59 
60 uint8_t sys_id_auto_doublets_actuators[SYS_ID_AUTO_DOUBLETS_N_ACTUATORS] = SYS_ID_AUTO_DOUBLETS_ACTUATORS;
61 int16_t sys_id_auto_doublets_amplitude[SYS_ID_AUTO_DOUBLETS_N_ACTUATORS] = SYS_ID_AUTO_DOUBLETS_AMPLITUDE;
62 
65 int8_t sys_id_auto_doublets_n_repeat = SYS_ID_AUTO_DOUBLETS_REPEATS; // The number of times a doublet has to be repeated on a single actuator
66 
68 
69 // Other variables needed for the periodic loop
71 
75 
76 inline void perform_sys_id_auto_doublets(uint8_t actuator_index);
77 inline void sys_id_auto_doublets_on_deactivation(void);
78 
80 {
81  sys_id_auto_doublets_n_doublets = SYS_ID_AUTO_DOUBLETS_N_ACTUATORS * sys_id_auto_doublets_n_repeat;
85 }
86 
88 {
89  // your periodic code here.
90  // freq = 20.0 Hz
91 
92  // Run if doublet activated
94  {
95  float current_time_s = get_sys_time_float();
97 
98  // Check when to increase the counters and perform doublet
100 
101  // stop doublets when all doublets done
102  if (current_index >= sys_id_auto_doublets_n_doublets)
103  {
105  }
106  else
107  { // continue doublets when not finished yet
108  // Check if doublet should be performed and index inxreased
109  if (current_index > sys_id_auto_doublets_counter)
110  {
111  uint8_t actuator_index = current_index / sys_id_auto_doublets_n_repeat;
112  perform_sys_id_auto_doublets(actuator_index);
114  }
115  }
116  }
117 }
118 
120 {
121  // Do nothing id doublet index is invalid
122  if (actuator_index >= SYS_ID_AUTO_DOUBLETS_N_ACTUATORS)
123  {
124  return;
125  }
126  // Set correct settings
130 
131  // call doublet activation handler
133 }
134 
136 {
138  // If the activation boolean is set to true
140  {
142  {
143  // Do nothing if already activated
144  }
145  else
146  {
147  // Activate auto doublet if not activated yet
151  }
152  }
153  else
154  { // If the activation boolean is set to false
156  }
157 }
158 
160 {
161  // call doublet deactivation handler
166  doublet_amplitude = 0;
167 }
uint8_t sys_id_auto_doublets_n_doublets
#define SYS_ID_AUTO_DOUBLETS_REPEATS
uint8_t sys_id_auto_doublets_actuators[SYS_ID_AUTO_DOUBLETS_N_ACTUATORS]
#define SYS_ID_AUTO_DOUBLETS_INTERVAL
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
#define SYS_ID_AUTO_DOUBLETS_TIME
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