Paparazzi UAS  v5.18.0_stable
Paparazzi is a free software Unmanned Aircraft System.
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 void nav_line_setup(void)
37 {
38  line_status = LR12;
39 }
40 
41 bool nav_line_run(uint8_t l1, uint8_t l2, float radius)
42 {
43  radius = fabs(radius);
44  float alt = waypoints[l1].a;
45  waypoints[l2].a = alt;
46 
47  float l2_l1_x = WaypointX(l1) - WaypointX(l2);
48  float l2_l1_y = WaypointY(l1) - WaypointY(l2);
49  float d = sqrt(l2_l1_x * l2_l1_x + l2_l1_y * l2_l1_y);
50 
51  /* Unit vector from l1 to l2 */
52  float u_x = l2_l1_x / d;
53  float u_y = l2_l1_y / d;
54 
55  /* The half circle centers and the other leg */
56  struct point l2_c1 = { WaypointX(l1) + radius * u_y,
57  WaypointY(l1) + radius * -u_x,
58  alt
59  };
60  struct point l2_c2 = { WaypointX(l1) + 1.732 * radius * u_x,
61  WaypointY(l1) + 1.732 * radius * u_y,
62  alt
63  };
64  struct point l2_c3 = { WaypointX(l1) + radius * -u_y,
65  WaypointY(l1) + radius * u_x,
66  alt
67  };
68 
69  struct point l1_c1 = { WaypointX(l2) + radius * -u_y,
70  WaypointY(l2) + radius * u_x,
71  alt
72  };
73  struct point l1_c2 = { WaypointX(l2) + 1.732 * radius * -u_x,
74  WaypointY(l2) + 1.732 * radius * -u_y,
75  alt
76  };
77  struct point l1_c3 = { WaypointX(l2) + radius * u_y,
78  WaypointY(l2) + radius * -u_x,
79  alt
80  };
81  float qdr_out_2_1 = M_PI / 3. - atan2(u_y, u_x);
82 
83  float qdr_out_2_2 = -M_PI / 3. - atan2(u_y, u_x);
84  float qdr_out_2_3 = M_PI - atan2(u_y, u_x);
85 
86  /* Vertical target */
87  NavVerticalAutoThrottleMode(0); /* No pitch */
89 
90  switch (line_status) {
91  case LR12: /* From wp l2 to wp l1 */
92  NavSegment(l2, l1);
93  if (NavApproachingFrom(l1, l2, CARROT)) {
96  }
97  break;
98  case LQC21:
99  nav_circle_XY(l2_c1.x, l2_c1.y, radius);
100  if (NavQdrCloseTo(DegOfRad(qdr_out_2_1) - 10)) {
101  line_status = LTC2;
102  nav_init_stage();
103  }
104  break;
105  case LTC2:
106  nav_circle_XY(l2_c2.x, l2_c2.y, -radius);
107  if (NavQdrCloseTo(DegOfRad(qdr_out_2_2) + 10)) {
108  line_status = LQC22;
109  nav_init_stage();
110  }
111  break;
112  case LQC22:
113  nav_circle_XY(l2_c3.x, l2_c3.y, radius);
114  if (NavQdrCloseTo(DegOfRad(qdr_out_2_3) - 10)) {
115  line_status = LR21;
116  nav_init_stage();
117  }
118  break;
119  case LR21: /* From wp l1 to wp l2 */
120  NavSegment(l1, l2);
121  if (NavApproachingFrom(l2, l1, CARROT)) {
122  line_status = LQC12;
123  nav_init_stage();
124  }
125  break;
126  case LQC12:
127  nav_circle_XY(l1_c1.x, l1_c1.y, radius);
128  if (NavQdrCloseTo(DegOfRad(qdr_out_2_1 + M_PI) - 10)) {
129  line_status = LTC1;
130  nav_init_stage();
131  }
132  break;
133  case LTC1:
134  nav_circle_XY(l1_c2.x, l1_c2.y, -radius);
135  if (NavQdrCloseTo(DegOfRad(qdr_out_2_2 + M_PI) + 10)) {
136  line_status = LQC11;
137  nav_init_stage();
138  }
139  break;
140  case LQC11:
141  nav_circle_XY(l1_c3.x, l1_c3.y, radius);
142  if (NavQdrCloseTo(DegOfRad(qdr_out_2_3 + M_PI) - 10)) {
143  line_status = LR12;
144  nav_init_stage();
145  }
146  break;
147  default: /* Should not occur !!! End the pattern */
148  return false;
149  }
150  return true; /* This pattern never ends */
151 }
point::a
float a
Definition: common_nav.h:42
LTC1
@ LTC1
Definition: nav_line.c:33
nav_line_setup
void nav_line_setup(void)
Definition: nav_line.c:36
WaypointY
#define WaypointY(_wp)
Definition: common_nav.h:46
WaypointX
#define WaypointX(_wp)
Definition: common_nav.h:45
nav_circle_XY
void nav_circle_XY(float x, float y, float radius)
Navigates around (x, y).
Definition: nav.c:109
NavSegment
#define NavSegment(_start, _end)
Definition: nav.h:161
NavQdrCloseTo
#define NavQdrCloseTo(x)
True if x (in degrees) is close to the current QDR (less than 10 degrees)
Definition: nav.h:155
LTC2
@ LTC2
Definition: nav_line.c:33
nav_line.h
point
Definition: common_nav.h:39
waypoints
struct point waypoints[NB_WAYPOINT]
size == nb_waypoint, waypoint 0 is a dummy waypoint
Definition: common_nav.c:38
NavVerticalAutoThrottleMode
#define NavVerticalAutoThrottleMode(_pitch)
Set the climb control to auto-throttle with the specified pitch pre-command.
Definition: nav.h:171
NavApproachingFrom
#define NavApproachingFrom(wp, from, time)
Definition: nav.h:166
CARROT
#define CARROT
default approaching_time for a wp
Definition: navigation.h:40
LQC11
@ LQC11
Definition: nav_line.c:33
LQC22
@ LQC22
Definition: nav_line.c:33
nav_init_stage
void nav_init_stage(void)
needs to be implemented by fixedwing and rotorcraft seperately
Definition: nav.c:93
uint8_t
unsigned char uint8_t
Definition: types.h:14
point::x
float x
Definition: common_nav.h:40
LQC21
@ LQC21
Definition: nav_line.c:33
nav.h
WaypointAlt
#define WaypointAlt(_wp)
waypoint altitude in m above MSL
Definition: common_nav.h:48
LR21
@ LR21
Definition: nav_line.c:33
line_status
line_status
Status along the pattern.
Definition: nav_line.c:33
point::y
float y
Definition: common_nav.h:41
LQC12
@ LQC12
Definition: nav_line.c:33
LR12
@ LR12
Definition: nav_line.c:33
NavVerticalAltitudeMode
#define NavVerticalAltitudeMode(_alt, _pre_climb)
Set the vertical mode to altitude control with the specified altitude setpoint and climb pre-command.
Definition: nav.h:185
nav_line_run
bool nav_line_run(uint8_t l1, uint8_t l2, float radius)
Definition: nav_line.c:41