Paparazzi UAS  v5.18.0_stable
Paparazzi is a free software Unmanned Aircraft System.
avoid_navigation.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012-2013
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, write to
18  * the Free Software Foundation, 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  */
21 
28 // Own Header
29 #include "avoid_navigation.h"
30 
31 // Paparazzi Data
32 #include "state.h"
33 
34 // Interact with navigation
35 #include "navigation.h"
36 
37 // Know waypoint numbers and blocks
38 #include "generated/flight_plan.h"
39 
40 // To get data from the stereo cam
42 
43 // Downlink
44 #ifndef DOWNLINK_DEVICE
45 #define DOWNLINK_DEVICE DOWNLINK_AP_DEVICE
46 #endif
47 #include "pprzlink/messages.h"
49 
50 #include "led.h"
51 
52 
54 bool obstacle_detected = false;
56 
57 // Called once on paparazzi autopilot start
59 {
60  // Do nothing
62 }
63 
64 // Called on each vision analysis result after receiving the struct
66 {
67  // Send ALL vision data to the ground
69 
70  switch (avoid_navigation_data.mode) {
71  case 0: // Go to Goal and stop at obstacles
72  //count 4 subsequent obstacles
73  if (stereocam_data.data[0] > 60) {
74  counter = counter + 1;
75  if (counter > 1) {
76  counter = 0;
77  //Obstacle detected, go to turn until clear mode
78  obstacle_detected = true;
80  }
81  } else {
82  counter = 0;
83  }
84  break;
85  case 1: // Turn until clear
86  //count 20 subsequent free frames
87  if (stereocam_data.data[0] < 60) {
88  counter = counter + 1;
89  if (counter > 6) {
90  counter = 0;
91  //Stop and put waypoint 2.5 m ahead
92  struct EnuCoor_i new_coor;
93  struct EnuCoor_i *pos = stateGetPositionEnu_i();
94  float sin_heading = sinf(ANGLE_FLOAT_OF_BFP(nav_heading));
95  float cos_heading = cosf(ANGLE_FLOAT_OF_BFP(nav_heading));
96  new_coor.x = pos->x + POS_BFP_OF_REAL(sin_heading * (NAV_LINE_AVOID_SEGMENT_LENGTH));
97  new_coor.y = pos->y + POS_BFP_OF_REAL(cos_heading * (NAV_LINE_AVOID_SEGMENT_LENGTH));
98  new_coor.z = pos->z;
99  waypoint_set_xy_i(WP_W1, new_coor.x, new_coor.y);
100  obstacle_detected = false;
102  }
103  } else {
104  counter = 0;
105  }
106  break;
107  case 2:
108  break;
109  default: // do nothing
110  break;
111  }
115 }
116 
118 {
119  *heading = *heading + increment;
120 }
121 
obstacle_detected
bool obstacle_detected
Definition: avoid_navigation.c:54
ANGLE_FLOAT_OF_BFP
#define ANGLE_FLOAT_OF_BFP(_ai)
Definition: pprz_algebra_int.h:211
EnuCoor_i::y
int32_t y
North.
Definition: pprz_geodetic_int.h:79
EnuCoor_i::x
int32_t x
East.
Definition: pprz_geodetic_int.h:78
avoid_navigation_data
struct AvoidNavigationStruct avoid_navigation_data
global VIDEO state
Definition: avoid_navigation.c:53
stateGetPositionEnu_i
static struct EnuCoor_i * stateGetPositionEnu_i(void)
Get position in local ENU coordinates (int).
Definition: state.h:674
avoid_navigation.h
increase_nav_heading
void increase_nav_heading(int32_t *heading, int32_t increment)
Definition: avoid_navigation.c:117
nav_heading
int32_t nav_heading
with INT32_ANGLE_FRAC
Definition: navigation.c:108
counter
int32_t counter
Definition: avoid_navigation.c:55
run_avoid_navigation_onvision
void run_avoid_navigation_onvision(void)
Definition: avoid_navigation.c:65
waypoint_set_xy_i
void waypoint_set_xy_i(uint8_t wp_id, int32_t x, int32_t y)
Set only local XY coordinates of waypoint without update altitude.
Definition: waypoints.c:138
init_avoid_navigation
void init_avoid_navigation()
Definition: avoid_navigation.c:58
NAV_LINE_AVOID_SEGMENT_LENGTH
#define NAV_LINE_AVOID_SEGMENT_LENGTH
Definition: avoid_navigation.h:38
AvoidNavigationStruct
Definition: stereocam_droplet.c:69
AvoidNavigationStruct::stereo_bin
uint8_t stereo_bin[8]
Definition: stereocam_droplet.c:71
led.h
arch independent LED (Light Emitting Diodes) API
AvoidNavigationStruct::mode
uint8_t mode
0 = straight, 1 = right, 2 = left, ...
Definition: stereocam_droplet.c:70
stereocam.h
interface to the TU Delft serial stereocam
int32_t
signed long int32_t
Definition: types.h:19
POS_BFP_OF_REAL
#define POS_BFP_OF_REAL(_af)
Definition: pprz_algebra_int.h:216
EnuCoor_i::z
int32_t z
Up.
Definition: pprz_geodetic_int.h:80
state.h
EnuCoor_i
vector in East North Up coordinates
Definition: pprz_geodetic_int.h:77
heading
float heading
Definition: wedgebug.c:258