Paparazzi UAS  v5.10_stable-5-g83a0da5-dirty
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
nav_line.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2007 Anton Kochevar, ENAC
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 #include "generated/airframe.h"
29 #include "modules/nav/nav_line.h"
31 
35 
36 bool nav_line_setup(void)
37 {
38  line_status = LR12;
39  return false;
40 }
41 
42 bool nav_line_run(uint8_t l1, uint8_t l2, float radius)
43 {
44  radius = fabs(radius);
45  float alt = waypoints[l1].a;
46  waypoints[l2].a = alt;
47 
48  float l2_l1_x = WaypointX(l1) - WaypointX(l2);
49  float l2_l1_y = WaypointY(l1) - WaypointY(l2);
50  float d = sqrt(l2_l1_x * l2_l1_x + l2_l1_y * l2_l1_y);
51 
52  /* Unit vector from l1 to l2 */
53  float u_x = l2_l1_x / d;
54  float u_y = l2_l1_y / d;
55 
56  /* The half circle centers and the other leg */
57  struct point l2_c1 = { WaypointX(l1) + radius * u_y,
58  WaypointY(l1) + radius * -u_x,
59  alt
60  };
61  struct point l2_c2 = { WaypointX(l1) + 1.732 * radius * u_x,
62  WaypointY(l1) + 1.732 * radius * u_y,
63  alt
64  };
65  struct point l2_c3 = { WaypointX(l1) + radius * -u_y,
66  WaypointY(l1) + radius * u_x,
67  alt
68  };
69 
70  struct point l1_c1 = { WaypointX(l2) + radius * -u_y,
71  WaypointY(l2) + radius * u_x,
72  alt
73  };
74  struct point l1_c2 = { WaypointX(l2) + 1.732 * radius * -u_x,
75  WaypointY(l2) + 1.732 * radius * -u_y,
76  alt
77  };
78  struct point l1_c3 = { WaypointX(l2) + radius * u_y,
79  WaypointY(l2) + radius * -u_x,
80  alt
81  };
82  float qdr_out_2_1 = M_PI / 3. - atan2(u_y, u_x);
83 
84  float qdr_out_2_2 = -M_PI / 3. - atan2(u_y, u_x);
85  float qdr_out_2_3 = M_PI - atan2(u_y, u_x);
86 
87  /* Vertical target */
88  NavVerticalAutoThrottleMode(0); /* No pitch */
90 
91  switch (line_status) {
92  case LR12: /* From wp l2 to wp l1 */
93  NavSegment(l2, l1);
94  if (NavApproachingFrom(l1, l2, CARROT)) {
97  }
98  break;
99  case LQC21:
100  nav_circle_XY(l2_c1.x, l2_c1.y, radius);
101  if (NavQdrCloseTo(DegOfRad(qdr_out_2_1) - 10)) {
102  line_status = LTC2;
103  nav_init_stage();
104  }
105  break;
106  case LTC2:
107  nav_circle_XY(l2_c2.x, l2_c2.y, -radius);
108  if (NavQdrCloseTo(DegOfRad(qdr_out_2_2) + 10)) {
109  line_status = LQC22;
110  nav_init_stage();
111  }
112  break;
113  case LQC22:
114  nav_circle_XY(l2_c3.x, l2_c3.y, radius);
115  if (NavQdrCloseTo(DegOfRad(qdr_out_2_3) - 10)) {
116  line_status = LR21;
117  nav_init_stage();
118  }
119  break;
120  case LR21: /* From wp l1 to wp l2 */
121  NavSegment(l1, l2);
122  if (NavApproachingFrom(l2, l1, CARROT)) {
123  line_status = LQC12;
124  nav_init_stage();
125  }
126  break;
127  case LQC12:
128  nav_circle_XY(l1_c1.x, l1_c1.y, radius);
129  if (NavQdrCloseTo(DegOfRad(qdr_out_2_1 + M_PI) - 10)) {
130  line_status = LTC1;
131  nav_init_stage();
132  }
133  break;
134  case LTC1:
135  nav_circle_XY(l1_c2.x, l1_c2.y, -radius);
136  if (NavQdrCloseTo(DegOfRad(qdr_out_2_2 + M_PI) + 10)) {
137  line_status = LQC11;
138  nav_init_stage();
139  }
140  break;
141  case LQC11:
142  nav_circle_XY(l1_c3.x, l1_c3.y, radius);
143  if (NavQdrCloseTo(DegOfRad(qdr_out_2_3 + M_PI) - 10)) {
144  line_status = LR12;
145  nav_init_stage();
146  }
147  break;
148  default: /* Should not occur !!! End the pattern */
149  return false;
150  }
151  return true; /* This pattern never ends */
152 }
#define WaypointAlt(_wp)
waypoint altitude in m above MSL
Definition: common_nav.h:48
float x
Definition: common_nav.h:40
static float radius
Definition: chemotaxis.c:15
float y
Definition: common_nav.h:41
#define WaypointX(_wp)
Definition: common_nav.h:45
#define WaypointY(_wp)
Definition: common_nav.h:46
unsigned char uint8_t
Definition: types.h:14
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