Paparazzi UAS v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
Loading...
Searching...
No Matches
nav_shakestart.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2025 MAVLab <microuav@gmail.com>
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 "modules/core/abi.h"
28
30#include "autopilot.h"
32
33
34#ifndef NAV_SHAKE_START_ACC_ID
35#define NAV_SHAKE_START_ACC_ID ABI_BROADCAST
36#endif
37
38
39static bool nav_shakestart_detected = false;
40static float nav_shakestart_accel = 0;
41
42
44
46{
47 // your abi callback code here
48 // Convert to float
52
54}
55
61
63{
64 // Reset the shake start detection
67}
68
70{
71 // your periodic code here.
72 // freq = 20.0 Hz
73
74 static uint32_t timer = 0;
75 static int shake_state = 0;
76
77 // If shake_state is even, we are waiting for a positive acceleration
78 if (shake_state % 2 == 0) {
79 // Check if the acceleration is above a threshold
80 if (nav_shakestart_accel > 12.0f) { // Threshold of 2g
81 timer = 15;
83 }
84 } else {
85 // Check is the acceleration is below a threshold
86 if (nav_shakestart_accel <= 12.0f) { // Threshold of 1.2g
87 timer = 15;
89 }
90 }
91
92 if (timer > 0) {
93 timer--;
94 } else {
95 shake_state = 0; // Reset shake_state
96 }
97
98 if (shake_state >= 9) {
100 }
101
102}
103
105{
106 NavAttitude(RadOfDeg(0.f));
109 return !nav_shakestart_detected; // return true (continue) while the shake was not detected
110}
111
112
Main include for ABI (AirBorneInterface).
Event structure to store callbacks in a linked list.
Definition abi_common.h:67
Core autopilot interface common to all firmwares.
Fixed wing horizontal control.
#define ACCEL_FLOAT_OF_BFP(_ai)
uint16_t foo
Definition main_demo5.c:58
Fixedwing Navigation library.
#define NavVerticalThrottleMode(_throttle)
Set the vertical mode to fixed throttle with the specified setpoint.
Definition nav.h:204
#define NavAttitude(_roll)
Definition nav.h:214
#define NavVerticalAutoThrottleMode(_pitch)
Set the climb control to auto-throttle with the specified pitch pre-command.
Definition nav.h:177
void nav_shakestart_init(void)
bool nav_shakestart_run(void)
void nav_shakestart_periodic(void)
#define NAV_SHAKE_START_ACC_ID
void nav_shakestart_reset(void)
static float nav_shakestart_accel
static void nav_shake_start_acc_cb(uint8_t sender_id, uint32_t stamp, struct Int32Vect3 *accel)
static bool nav_shakestart_detected
static abi_event nav_shake_start_acc_ev
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.