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
navigation.h
Go to the documentation of this file.
1 /*
2 * Copyright (C) 2008-2011 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 
28 #ifndef NAVIGATION_H
29 #define NAVIGATION_H
30 
31 #include "std.h"
32 #include "math/pprz_geodetic_int.h"
33 
36 
37 #define NAV_FREQ 16
38 
39 extern struct EnuCoor_i navigation_target;
40 extern struct EnuCoor_i navigation_carrot;
41 
42 extern void nav_init(void);
43 extern void nav_run(void);
44 
45 extern uint8_t last_wp __attribute__((unused));
46 
48 extern struct EnuCoor_i nav_segment_start, nav_segment_end;
49 extern struct EnuCoor_i nav_circle_center;
51 #define HORIZONTAL_MODE_WAYPOINT 0
52 #define HORIZONTAL_MODE_ROUTE 1
53 #define HORIZONTAL_MODE_CIRCLE 2
54 #define HORIZONTAL_MODE_ATTITUDE 3
55 #define HORIZONTAL_MODE_MANUAL 4
56 extern int32_t nav_roll, nav_pitch;
57 extern int32_t nav_heading;
59 extern float nav_radius;
61 
64 
65 extern bool nav_survey_active;
66 
67 extern uint8_t vertical_mode;
68 extern uint32_t nav_throttle;
70 extern float flight_altitude;
71 #define VERTICAL_MODE_MANUAL 0
72 #define VERTICAL_MODE_CLIMB 1
73 #define VERTICAL_MODE_ALT 2
74 
75 extern float dist2_to_home;
76 extern bool too_far_from_home;
77 extern float failsafe_mode_dist2;
78 
79 extern float dist2_to_wp;
80 
81 extern float get_dist2_to_waypoint(uint8_t wp_id);
82 extern float get_dist2_to_point(struct EnuCoor_i *p);
83 extern void compute_dist2_to_home(void);
84 extern void nav_home(void);
85 extern void nav_set_manual(int32_t roll, int32_t pitch, int32_t yaw);
86 
87 unit_t nav_reset_reference(void) __attribute__((unused));
88 unit_t nav_reset_alt(void) __attribute__((unused));
89 void nav_periodic_task(void);
90 bool nav_detect_ground(void);
91 bool nav_is_in_flight(void);
92 
93 extern bool exception_flag[10];
94 extern void set_exception_flag(uint8_t flag_num);
95 
96 extern bool nav_set_heading_rad(float rad);
97 extern bool nav_set_heading_deg(float deg);
98 extern bool nav_set_heading_towards(float x, float y);
100 extern bool nav_set_heading_current(void);
101 
103 #ifndef CARROT
104 #define CARROT 0
105 #endif
106 
107 #define NavKillThrottle() ({ if (autopilot_mode == AP_MODE_NAV) { autopilot_set_motors_on(FALSE); } false; })
108 #define NavResurrect() ({ if (autopilot_mode == AP_MODE_NAV) { autopilot_set_motors_on(TRUE); } false; })
109 
110 
111 #define NavSetGroundReferenceHere() ({ nav_reset_reference(); false; })
112 #define NavSetAltitudeReferenceHere() ({ nav_reset_alt(); false; })
113 
114 #define NavSetWaypointHere(_wp) ({ waypoint_set_here_2d(_wp); false; })
115 #define NavCopyWaypoint(_wp1, _wp2) ({ waypoint_copy(_wp1, _wp2); false; })
116 #define NavCopyWaypointPositionOnly(_wp1, _wp2) ({ waypoint_position_copy(_wp1, _wp2); false; })
117 
119 #define NormCourse(x) { \
120  while (x < 0) x += 360; \
121  while (x >= 360) x -= 360; \
122  }
123 
124 /*********** Navigation to waypoint *************************************/
125 #define NavGotoWaypoint(_wp) { \
126  horizontal_mode = HORIZONTAL_MODE_WAYPOINT; \
127  VECT3_COPY(navigation_target, waypoints[_wp].enu_i); \
128  dist2_to_wp = get_dist2_to_waypoint(_wp); \
129  }
130 
131 /*********** Navigation on a circle **************************************/
132 extern void nav_circle(struct EnuCoor_i *wp_center, int32_t radius);
133 #define NavCircleWaypoint(_center, _radius) { \
134  horizontal_mode = HORIZONTAL_MODE_CIRCLE; \
135  nav_circle(&waypoints[_center].enu_i, POS_BFP_OF_REAL(_radius)); \
136  }
137 
138 #define NavCircleCount() ((float)abs(nav_circle_radians) / INT32_ANGLE_2_PI)
139 #define NavCircleQdr() ({ int32_t qdr = INT32_DEG_OF_RAD(INT32_ANGLE_PI_2 - nav_circle_qdr) >> INT32_ANGLE_FRAC; NormCourse(qdr); qdr; })
140 
141 #define CloseDegAngles(_c1, _c2) ({ int32_t _diff = _c1 - _c2; NormCourse(_diff); 350 < _diff || _diff < 10; })
142 
143 #define NavQdrCloseTo(x) CloseDegAngles(((x) >> INT32_ANGLE_FRAC), NavCircleQdr())
144 #define NavCourseCloseTo(x) {}
145 
147 
148 extern void nav_oval_init(void);
149 extern void nav_oval(uint8_t, uint8_t, float);
150 extern uint8_t nav_oval_count;
151 #define Oval(a, b, c) nav_oval((b), (a), (c))
152 
153 /*********** Navigation along a line *************************************/
154 extern void nav_route(struct EnuCoor_i *wp_start, struct EnuCoor_i *wp_end);
155 #define NavSegment(_start, _end) { \
156  horizontal_mode = HORIZONTAL_MODE_ROUTE; \
157  nav_route(&waypoints[_start].enu_i, &waypoints[_end].enu_i); \
158  }
159 
161 #define NavGlide(_last_wp, _wp) { \
162  int32_t start_alt = waypoints[_last_wp].enu_i.z; \
163  int32_t diff_alt = waypoints[_wp].enu_i.z - start_alt; \
164  int32_t alt = start_alt + ((diff_alt * nav_leg_progress) / nav_leg_length); \
165  NavVerticalAltitudeMode(POS_FLOAT_OF_BFP(alt),0); \
166  }
167 
169 bool nav_approaching_from(struct EnuCoor_i *wp, struct EnuCoor_i *from, int16_t approaching_time);
170 #define NavApproaching(wp, time) nav_approaching_from(&waypoints[wp].enu_i, NULL, time)
171 #define NavApproachingFrom(wp, from, time) nav_approaching_from(&waypoints[wp].enu_i, &waypoints[from].enu_i, time)
172 
174 bool nav_check_wp_time(struct EnuCoor_i *wp, uint16_t stay_time);
175 #define NavCheckWaypointTime(wp, time) nav_check_wp_time(&waypoints[wp].enu_i, time)
176 
179 #define NavVerticalAutoThrottleMode(_pitch) { \
180  nav_pitch = ANGLE_BFP_OF_REAL(_pitch); \
181  }
182 
185 #define NavVerticalAutoPitchMode(_throttle) {}
186 
189 #define NavVerticalAltitudeMode(_alt, _pre_climb) { \
190  vertical_mode = VERTICAL_MODE_ALT; \
191  nav_altitude = POS_BFP_OF_REAL(_alt); \
192  }
193 
195 #define NavVerticalClimbMode(_climb) { \
196  vertical_mode = VERTICAL_MODE_CLIMB; \
197  nav_climb = SPEED_BFP_OF_REAL(_climb); \
198  }
199 
201 #define NavVerticalThrottleMode(_throttle) { \
202  vertical_mode = VERTICAL_MODE_MANUAL; \
203  nav_throttle = _throttle; \
204  }
205 
207 #define NavHeading nav_set_heading_rad
208 
209 #define NavAttitude(_roll) { \
210  horizontal_mode = HORIZONTAL_MODE_ATTITUDE; \
211  nav_roll = ANGLE_BFP_OF_REAL(_roll); \
212  }
213 
214 #define NavSetManual nav_set_manual
215 
216 #define NavStartDetectGround() ({ autopilot_detect_ground_once = true; false; })
217 #define NavDetectGround() nav_detect_ground()
218 
219 #define nav_IncreaseShift(x) {}
220 
221 #define nav_SetNavRadius(x) {}
222 
223 
224 #define navigation_SetFlightAltitude(x) { \
225  flight_altitude = x; \
226  nav_flight_altitude = POS_BFP_OF_REAL(flight_altitude - state.ned_origin_f.hmsl); \
227  }
228 
230 #define GetPosX() (stateGetPositionEnu_f()->x)
231 #define GetPosY() (stateGetPositionEnu_f()->y)
233 #define GetPosAlt() (stateGetPositionEnu_f()->z+state.ned_origin_f.hmsl)
235 
241 #define GetAltRef() (state.ned_origin_f.hmsl)
242 
243 
244 extern void navigation_update_wp_from_speed(uint8_t wp, struct Int16Vect3 speed_sp, int16_t heading_rate_sp);
245 
246 #define NavFollow(_ac_id, _distance, _height) \
247  nav_follow(_ac_id, _distance, _height);
248 extern void nav_follow(uint8_t _ac_id, uint32_t distance, uint32_t height);
249 
250 #endif /* NAVIGATION_H */
unsigned short uint16_t
Definition: types.h:16
int32_t y
North.
int32_t x
East.
static float radius
Definition: chemotaxis.c:15
unsigned long uint32_t
Definition: types.h:18
signed short int16_t
Definition: types.h:17
Paparazzi fixed point math for geodetic calculations.
signed long int32_t
Definition: types.h:19
vector in East North Up coordinates
unsigned char uint8_t
Definition: types.h:14
Common flight_plan functions shared between fixedwing and rotorcraft.
static float p[2][2]