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
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 extern int32_t nav_roll, nav_pitch;
56 extern int32_t nav_heading;
57 extern float nav_radius;
59 
62 
63 extern bool_t nav_survey_active;
64 
65 extern uint8_t vertical_mode;
66 extern uint32_t nav_throttle;
68 extern float flight_altitude;
69 #define VERTICAL_MODE_MANUAL 0
70 #define VERTICAL_MODE_CLIMB 1
71 #define VERTICAL_MODE_ALT 2
72 
73 extern float dist2_to_home;
74 extern bool_t too_far_from_home;
75 extern float failsafe_mode_dist2;
76 
77 extern float dist2_to_wp;
78 
79 extern float get_dist2_to_waypoint(uint8_t wp_id);
80 extern float get_dist2_to_point(struct EnuCoor_i *p);
81 extern void compute_dist2_to_home(void);
82 extern void nav_home(void);
83 
84 unit_t nav_reset_reference(void) __attribute__((unused));
85 unit_t nav_reset_alt(void) __attribute__((unused));
86 void nav_periodic_task(void);
87 bool_t nav_detect_ground(void);
88 bool_t nav_is_in_flight(void);
89 
90 extern bool_t exception_flag[10];
91 extern void set_exception_flag(uint8_t flag_num);
92 
93 extern bool_t nav_set_heading_rad(float rad);
94 extern bool_t nav_set_heading_deg(float deg);
95 extern bool_t nav_set_heading_towards(float x, float y);
97 extern bool_t nav_set_heading_current(void);
98 
100 #ifndef CARROT
101 #define CARROT 0
102 #endif
103 
104 #define NavKillThrottle() ({ if (autopilot_mode == AP_MODE_NAV) { autopilot_set_motors_on(FALSE); } FALSE; })
105 #define NavResurrect() ({ if (autopilot_mode == AP_MODE_NAV) { autopilot_set_motors_on(TRUE); } FALSE; })
106 
107 
108 #define NavSetGroundReferenceHere() ({ nav_reset_reference(); FALSE; })
109 #define NavSetAltitudeReferenceHere() ({ nav_reset_alt(); FALSE; })
110 
111 #define NavSetWaypointHere(_wp) ({ waypoint_set_here_2d(_wp); FALSE; })
112 #define NavCopyWaypoint(_wp1, _wp2) ({ waypoint_copy(_wp1, _wp2); FALSE; })
113 #define NavCopyWaypointPositionOnly(_wp1, _wp2) ({ waypoint_position_copy(_wp1, _wp2); FALSE; })
114 
116 #define NormCourse(x) { \
117  while (x < 0) x += 360; \
118  while (x >= 360) x -= 360; \
119  }
120 
121 /*********** Navigation to waypoint *************************************/
122 #define NavGotoWaypoint(_wp) { \
123  horizontal_mode = HORIZONTAL_MODE_WAYPOINT; \
124  VECT3_COPY(navigation_target, waypoints[_wp].enu_i); \
125  dist2_to_wp = get_dist2_to_waypoint(_wp); \
126  }
127 
128 /*********** Navigation on a circle **************************************/
129 extern void nav_circle(struct EnuCoor_i *wp_center, int32_t radius);
130 #define NavCircleWaypoint(_center, _radius) { \
131  horizontal_mode = HORIZONTAL_MODE_CIRCLE; \
132  nav_circle(&waypoints[_center].enu_i, POS_BFP_OF_REAL(_radius)); \
133  }
134 
135 #define NavCircleCount() ((float)abs(nav_circle_radians) / INT32_ANGLE_2_PI)
136 #define NavCircleQdr() ({ int32_t qdr = INT32_DEG_OF_RAD(INT32_ANGLE_2_PI_2 - nav_circle_qdr) >> INT32_ANGLE_FRAC; NormCourse(qdr); qdr; })
137 
139 #define NavQdrCloseTo(x) {}
140 #define NavCourseCloseTo(x) {}
141 
142 /*********** Navigation along a line *************************************/
143 extern void nav_route(struct EnuCoor_i *wp_start, struct EnuCoor_i *wp_end);
144 #define NavSegment(_start, _end) { \
145  horizontal_mode = HORIZONTAL_MODE_ROUTE; \
146  nav_route(&waypoints[_start].enu_i, &waypoints[_end].enu_i); \
147  }
148 
150 #define NavGlide(_last_wp, _wp) { \
151  int32_t start_alt = waypoints[_last_wp].enu_i.z; \
152  int32_t diff_alt = waypoints[_wp].enu_i.z - start_alt; \
153  int32_t alt = start_alt + ((diff_alt * nav_leg_progress) / nav_leg_length); \
154  NavVerticalAltitudeMode(POS_FLOAT_OF_BFP(alt),0); \
155  }
156 
158 bool_t nav_approaching_from(struct EnuCoor_i *wp, struct EnuCoor_i *from, int16_t approaching_time);
159 #define NavApproaching(wp, time) nav_approaching_from(&waypoints[wp].enu_i, NULL, time)
160 #define NavApproachingFrom(wp, from, time) nav_approaching_from(&waypoints[wp].enu_i, &waypoints[from].enu_i, time)
161 
163 bool_t nav_check_wp_time(struct EnuCoor_i *wp, uint16_t stay_time);
164 #define NavCheckWaypointTime(wp, time) nav_check_wp_time(&waypoints[wp].enu_i, time)
165 
168 #define NavVerticalAutoThrottleMode(_pitch) { \
169  nav_pitch = ANGLE_BFP_OF_REAL(_pitch); \
170  }
171 
174 #define NavVerticalAutoPitchMode(_throttle) {}
175 
178 #define NavVerticalAltitudeMode(_alt, _pre_climb) { \
179  vertical_mode = VERTICAL_MODE_ALT; \
180  nav_altitude = POS_BFP_OF_REAL(_alt); \
181  }
182 
184 #define NavVerticalClimbMode(_climb) { \
185  vertical_mode = VERTICAL_MODE_CLIMB; \
186  nav_climb = SPEED_BFP_OF_REAL(_climb); \
187  }
188 
190 #define NavVerticalThrottleMode(_throttle) { \
191  vertical_mode = VERTICAL_MODE_MANUAL; \
192  nav_throttle = _throttle; \
193  }
194 
196 #define NavHeading nav_set_heading_rad
197 
198 #define NavAttitude(_roll) { \
199  horizontal_mode = HORIZONTAL_MODE_ATTITUDE; \
200  nav_roll = ANGLE_BFP_OF_REAL(_roll); \
201  }
202 
203 #define NavStartDetectGround() ({ autopilot_detect_ground_once = TRUE; FALSE; })
204 #define NavDetectGround() nav_detect_ground()
205 
206 #define nav_IncreaseShift(x) {}
207 
208 #define nav_SetNavRadius(x) {}
209 
210 
211 #define navigation_SetFlightAltitude(x) { \
212  flight_altitude = x; \
213  nav_flight_altitude = POS_BFP_OF_REAL(flight_altitude - state.ned_origin_f.hmsl); \
214  }
215 
216 
217 #define GetPosX() (stateGetPositionEnu_f()->x)
218 #define GetPosY() (stateGetPositionEnu_f()->y)
219 #define GetPosAlt() (stateGetPositionEnu_f()->z+state.ned_origin_f.hmsl)
220 #define GetAltRef() (state.ned_origin_f.hmsl)
221 
222 
223 extern void navigation_update_wp_from_speed(uint8_t wp, struct Int16Vect3 speed_sp, int16_t heading_rate_sp);
224 
225 #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]