Paparazzi UAS  v5.8.2_stable-0-g6260b7c
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
nav_vertical_raster.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2008-2013 The Paparazzi Team
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 
31 #include "state.h"
32 #include "autopilot.h"
33 #include "generated/flight_plan.h"
34 
35 /************** Vertical Raster **********************************************/
36 
42 
44 {
45  line_status = LR12;
46  return FALSE;
47 }
48 
49 bool_t nav_vertical_raster_run(uint8_t l1, uint8_t l2, float radius, float AltSweep)
50 {
51  radius = fabs(radius);
52  float alt = waypoints[l1].a;
53  waypoints[l2].a = alt;
54 
55  float l2_l1_x = WaypointX(l1) - WaypointX(l2);
56  float l2_l1_y = WaypointY(l1) - WaypointY(l2);
57  float d = sqrt(l2_l1_x * l2_l1_x + l2_l1_y * l2_l1_y);
58 
59  /* Unit vector from l1 to l2 */
60  float u_x = l2_l1_x / d;
61  float u_y = l2_l1_y / d;
62 
63  /* The half circle centers and the other leg */
64  struct point l2_c1 = { WaypointX(l1) + radius * u_y,
65  WaypointY(l1) + radius * -u_x,
66  alt
67  };
68  struct point l2_c2 = { WaypointX(l1) + 1.732 * radius * u_x,
69  WaypointY(l1) + 1.732 * radius * u_y,
70  alt
71  };
72  struct point l2_c3 = { WaypointX(l1) + radius * -u_y,
73  WaypointY(l1) + radius * u_x,
74  alt
75  };
76 
77  struct point l1_c1 = { WaypointX(l2) + radius * -u_y,
78  WaypointY(l2) + radius * u_x,
79  alt
80  };
81  struct point l1_c2 = { WaypointX(l2) + 1.732 * radius * -u_x,
82  WaypointY(l2) + 1.732 * radius * -u_y,
83  alt
84  };
85  struct point l1_c3 = { WaypointX(l2) + radius * u_y,
86  WaypointY(l2) + radius * -u_x,
87  alt
88  };
89  float qdr_out_2_1 = M_PI / 3. - atan2(u_y, u_x);
90 
91  float qdr_out_2_2 = -M_PI / 3. - atan2(u_y, u_x);
92  float qdr_out_2_3 = M_PI - atan2(u_y, u_x);
93 
94  /* Vertical target */
95  NavVerticalAutoThrottleMode(0); /* No pitch */
97 
98  switch (line_status) {
99  case LR12: /* From wp l2 to wp l1 */
100  NavSegment(l2, l1);
101  if (NavApproachingFrom(l1, l2, CARROT)) {
102  line_status = LQC21;
103  waypoints[l1].a = waypoints[l1].a + AltSweep;
104  nav_init_stage();
105  }
106  break;
107  case LQC21:
108  nav_circle_XY(l2_c1.x, l2_c1.y, radius);
109  if (NavQdrCloseTo(DegOfRad(qdr_out_2_1) - 10)) {
110  line_status = LTC2;
111  nav_init_stage();
112  }
113  break;
114  case LTC2:
115  nav_circle_XY(l2_c2.x, l2_c2.y, -radius);
116  if (NavQdrCloseTo(DegOfRad(qdr_out_2_2) + 10) && stateGetPositionUtm_f()->alt >= (waypoints[l1].a - 10)) {
117  line_status = LQC22;
118  nav_init_stage();
119  }
120  break;
121  case LQC22:
122  nav_circle_XY(l2_c3.x, l2_c3.y, radius);
123  if (NavQdrCloseTo(DegOfRad(qdr_out_2_3) - 10)) {
124  line_status = LR21;
125  nav_init_stage();
126  }
127  break;
128  case LR21: /* From wp l1 to wp l2 */
129  NavSegment(l1, l2);
130  if (NavApproachingFrom(l2, l1, CARROT)) {
131  line_status = LQC12;
132  waypoints[l1].a = waypoints[l1].a + AltSweep;
133  nav_init_stage();
134  }
135  break;
136  case LQC12:
137  nav_circle_XY(l1_c1.x, l1_c1.y, radius);
138  if (NavQdrCloseTo(DegOfRad(qdr_out_2_1 + M_PI) - 10)) {
139  line_status = LTC1;
140  nav_init_stage();
141  }
142  break;
143  case LTC1:
144  nav_circle_XY(l1_c2.x, l1_c2.y, -radius);
145  if (NavQdrCloseTo(DegOfRad(qdr_out_2_2 + M_PI) + 10) && stateGetPositionUtm_f()->alt >= (waypoints[l1].a - 5)) {
146  line_status = LQC11;
147  nav_init_stage();
148  }
149  break;
150  case LQC11:
151  nav_circle_XY(l1_c3.x, l1_c3.y, radius);
152  if (NavQdrCloseTo(DegOfRad(qdr_out_2_3 + M_PI) - 10)) {
153  line_status = LR12;
154  nav_init_stage();
155  }
156  default:
157  break;
158  }
159  return TRUE; /* This pattern never ends */
160 }
#define WaypointAlt(_wp)
Definition: common_nav.h:47
float x
Definition: common_nav.h:40
static float radius
Definition: chemotaxis.c:15
#define FALSE
Definition: std.h:5
#define TRUE
Definition: std.h:4
float y
Definition: common_nav.h:41
#define WaypointX(_wp)
Definition: common_nav.h:45
#define WaypointY(_wp)
Definition: common_nav.h:46
static struct UtmCoor_f * stateGetPositionUtm_f(void)
Get position in UTM coordinates (float).
Definition: state.h:675
unsigned char uint8_t
Definition: types.h:14
API to get/set the generic vehicle states.
struct point waypoints[NB_WAYPOINT]
size == nb_waypoint, waypoint 0 is a dummy waypoint
Definition: common_nav.c:38
float a
Definition: common_nav.h:42