Paparazzi UAS v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
nav_cube.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2010 Martin Mueller
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
29#include "generated/airframe.h"
32#include "generated/flight_plan.h"
33
34#define MAX_LINES_X 8
35#define STBY_OFFSET 500
36
38
40{
41
43 int32_t bx, by, ex, ey;
49
50 /* sanity checks */
51 if (nav_cube.nsect_x <= 0) {
52 nav_cube.nsect_x = 1;
53 }
54 if (nav_cube.nsect_z <= 0) {
55 nav_cube.nsect_z = 1;
56 }
57 if ((nav_cube.sect <= 0) || (nav_cube.sect > (nav_cube.nsect_x * nav_cube.nsect_z))) {
58 nav_cube.sect = 1;
59 }
60
61 /* total number of lines/layers to fly */
62 if (nav_cube.grid_x == 0) {
64 } else {
66 }
67 if (nav_cube.grid_z == 0) {
69 } else {
71 }
72
73 /* position and number of lines in this sector */
79 }
81
82 /* do not do more than pre-set number of lines */
84
85 /* position and number of layers in this sector */
90
91 /* do the costly stuff only once */
92 alpha = ((360. - nav_cube.alpha) / 360.) * 2 * M_PI;
95
96 /* calculate lower left start begin/end x coord */
97 start_bx = WaypointX(center) - (((cube_nline_x_t - 1) * nav_cube.grid_x) / 2)
100
101 /* calculate lower left start end point y coord */
102 start_ey = WaypointY(center) - nav_cube.offset.y;
103
104 /* calculate lower left start begin point y coord */
106
107 /* calculate lower left start begin/end z coord */
108 start_bz = waypoints[center].a - (((cube_nline_z_t - 1) * nav_cube.grid_z) / 2)
111
112 /* reset all waypoints to the standby position */
113 for (j = 0; j < MAX_LINES_X; j++) {
114 waypoints[tb + j].x = WaypointX(center) + STBY_OFFSET;
115 waypoints[tb + j].y = WaypointY(center);
116 waypoints[te + j].x = WaypointX(center) + STBY_OFFSET;
117 waypoints[te + j].y = WaypointY(center);
118 }
119
120 /* set used waypoints */
121 for (j = 0; j < nav_cube.nline_x; j++) {
122 int i = cube_line_x_start + j;
123 /* set waypoints and vectorize in regard to center */
124 bx = (start_bx + i * nav_cube.grid_x) - WaypointX(center);
125 by = start_by - WaypointY(center);
126 ex = (start_ex + i * nav_cube.grid_x) - WaypointX(center);
127 ey = start_ey - WaypointY(center);
128 /* rotate clockwise with alpha and un-vectorize*/
129 waypoints[tb + j].x = bx * cos_alpha - by * sin_alpha + WaypointX(center);
130 waypoints[tb + j].y = bx * sin_alpha + by * cos_alpha + WaypointY(center);
131 waypoints[tb + j].a = start_bz;
132 waypoints[te + j].x = ex * cos_alpha - ey * sin_alpha + WaypointX(center);
133 waypoints[te + j].y = ex * sin_alpha + ey * cos_alpha + WaypointY(center);
134 waypoints[te + j].a = start_ez;
135 }
136
137 /* bug in <for from="" to=""> ? */
140}
141
145{
146
147 if (i > nav_cube.nline_x) {
148 return false;
149 }
150 if (j > nav_cube.nline_z) {
151 return false;
152 }
153
157 /* always keep at least security altitude */
160 }
161
165 /* always keep at least security altitude */
168 }
169
170 return false;
171}
float ground_alt
size == nb_waypoint, waypoint 0 is a dummy waypoint
Definition common_nav.c:46
struct point waypoints[NB_WAYPOINT]
size == nb_waypoint, waypoint 0 is a dummy waypoint
Definition common_nav.c:44
#define WaypointX(_wp)
Definition common_nav.h:45
float y
Definition common_nav.h:41
float a
Definition common_nav.h:42
float x
Definition common_nav.h:40
#define WaypointY(_wp)
Definition common_nav.h:46
uint16_t foo
Definition main_demo5.c:58
Fixedwing Navigation library.
struct NavCube nav_cube
Definition nav_cube.c:37
bool nav_cube_run(int8_t j, int8_t i, uint8_t dest_b, uint8_t dest_e, uint8_t src_b, uint8_t src_e)
Definition nav_cube.c:142
#define MAX_LINES_X
Definition nav_cube.c:34
void nav_cube_setup(uint8_t center, uint8_t tb, uint8_t te)
Definition nav_cube.c:39
#define STBY_OFFSET
Definition nav_cube.c:35
Fixedwing Navigation in a cube towards a center.
int32_t sect
sector to fly in (1..[nsect_x*nsect_z])
Definition nav_cube.h:116
struct Int32Vect3 size
size of the cube.
Definition nav_cube.h:105
int32_t nline_x
number of lines x (horizontal)
Definition nav_cube.h:119
struct Int32Vect3 offset
offset to center.
Definition nav_cube.h:112
int32_t grid_x
grid distance x (horizontal)
Definition nav_cube.h:114
int32_t nsect_x
number of sectors horizontal
Definition nav_cube.h:117
int32_t nsect_z
number of sectors vertical
Definition nav_cube.h:118
int32_t grid_z
grid distance z (vertical)
Definition nav_cube.h:115
int32_t nline_z
number of lines z (vertical)
Definition nav_cube.h:120
int32_t alpha
angle in degrees of flight direction to north, clockwise
Definition nav_cube.h:113
float alpha
Definition textons.c:133
int int32_t
Typedef defining 32 bit int type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
signed char int8_t
Typedef defining 8 bit char type.