Paparazzi UAS v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
Loading...
Searching...
No Matches
mav_exercise.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2021 Matteo Barbera <matteo.barbera97@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
21#include "mav_exercise.h"
22#include "modules/core/abi.h"
24#include "state.h"
25#include "autopilot_static.h"
26#include <stdio.h>
27
28#define NAV_C // needed to get the nav functions like Inside...
29#include "generated/flight_plan.h"
30
31#define PRINT(string, ...) fprintf(stderr, "[mav_exercise->%s()] " string,__FUNCTION__ , ##__VA_ARGS__)
32
36
43
44// define and initialise global variables
45float oa_color_count_frac = 0.18f;
47int32_t color_count = 0; // orange color count from color filter for obstacle detection
48int16_t obstacle_free_confidence = 0; // a measure of how certain we are that the way ahead is safe.
49float moveDistance = 2; // waypoint displacement [m]
50float oob_haeding_increment = 5.f; // heading angle increment if out of bounds [deg]
51const int16_t max_trajectory_confidence = 5; // number of consecutive negative object detections to be sure we are obstacle free
52
53
54// needed to receive output from a separate module running on a parallel process
55#ifndef ORANGE_AVOIDER_VISUAL_DETECTION_ID
56#define ORANGE_AVOIDER_VISUAL_DETECTION_ID ABI_BROADCAST
57#endif
63 int32_t quality, int16_t __attribute__((unused)) extra) {
64 color_count = quality;
65}
66
68 // bind our colorfilter callbacks to receive the color filter outputs
70}
71
73 // only evaluate our state machine if we are flying
74 if (!autopilot_in_flight()) {
75 return;
76 }
77
78 // compute current color thresholds
79 // front_camera defined in airframe xml, with the video_capture module
81
82 PRINT("Color_count: %d threshold: %d state: %d \n", color_count, color_count_threshold, navigation_state);
83
84 // update our safe confidence using color threshold
87 } else {
88 obstacle_free_confidence -= 2; // be more cautious with positive obstacle detections
89 }
90
91 // bound obstacle_free_confidence
93
94 switch (navigation_state) {
95 case SAFE:
99 } else if (obstacle_free_confidence == 0) {
101 } else {
103 }
104 break;
105 case OBSTACLE_FOUND:
106 // TODO Change behavior
107 // stop as soon as obstacle is found
110
112 break;
113 case OUT_OF_BOUNDS:
114 // stop
117
120
122 // add offset to head back into arena
125 }
126 break;
127 case HOLD:
128 default:
129 break;
130 }
131}
132
133/*
134 * Increases the NAV heading. Assumes heading is an INT32_ANGLE. It is bound in this function.
135 */
138
139 // normalize heading to [-pi, pi]
141
142 // set heading
144
145 return false;
146}
147
148/*
149 * Calculates coordinates of a distance of 'distanceMeters' forward w.r.t. current position and heading
150 */
153
154 // Now determine where to place the waypoint you want to go to
157 return false;
158}
159
160/*
161 * Sets waypoint 'waypoint' to the coordinates of 'new_coor'
162 */
167
168/*
169 * Calculates coordinates of distance forward and sets waypoint 'waypoint' to those coordinates
170 */
Main include for ABI (AirBorneInterface).
Event structure to store callbacks in a linked list.
Definition abi_common.h:67
bool autopilot_in_flight(void)
get in_flight flag
Definition autopilot.c:340
#define WaypointX(_wp)
Definition common_nav.h:45
#define WaypointY(_wp)
Definition common_nav.h:46
float psi
in radians
#define FLOAT_ANGLE_NORMALIZE(_a)
#define POS_BFP_OF_REAL(_af)
int32_t y
North.
int32_t x
East.
vector in East North Up coordinates
static struct FloatEulers * stateGetNedToBodyEulers_f(void)
Get vehicle body attitude euler angles (float).
Definition state.h:1306
static struct EnuCoor_i * stateGetPositionEnu_i(void)
Get position in local ENU coordinates (int).
Definition state.h:803
float new_heading
uint16_t foo
Definition main_demo5.c:58
static void color_detection_cb(uint8_t sender_id, int16_t pixel_x, int16_t pixel_y, int16_t pixel_width, int16_t pixel_height, int32_t quality, int16_t extra)
uint8_t increase_nav_heading(float incrementDegrees)
static abi_event color_detection_ev
float moveDistance
static uint8_t calculateForwards(struct EnuCoor_i *new_coor, float distanceMeters)
void mav_exercise_periodic(void)
int16_t obstacle_free_confidence
uint8_t moveWaypointForward(uint8_t waypoint, float distanceMeters)
float oa_color_count_frac
void mav_exercise_init(void)
const int16_t max_trajectory_confidence
float oob_haeding_increment
uint8_t moveWaypoint(uint8_t waypoint, struct EnuCoor_i *new_coor)
int32_t color_count
navigation_state_t
@ HOLD
@ OUT_OF_BOUNDS
@ SAFE
@ OBSTACLE_FOUND
#define ORANGE_AVOIDER_VISUAL_DETECTION_ID
#define PRINT(string,...)
#define front_camera
Definition mt9f002_nps.c:3
void waypoint_move_xy_i(uint8_t wp_id, int32_t x, int32_t y)
Definition waypoints.c:214
void waypoint_move_here_2d(uint8_t wp_id)
Definition waypoints.c:310
struct RotorcraftNavigation nav
Definition navigation.c:51
Rotorcraft navigation functions.
float heading
heading setpoint (in radians)
Definition navigation.h:133
API to get/set the generic vehicle states.
int int32_t
Typedef defining 32 bit int type.
short int16_t
Typedef defining 16 bit short type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
navigation_state
Camera focal length, in pixels (i.e. distance between camera.
Definition wedgebug.c:209
float heading
Definition wedgebug.c:258