Paparazzi UAS  v5.0.5_stable-7-g4b8bbb7
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures 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"
34 
36 
37 #define NAV_FREQ 16
38 // FIXME use periodic FREQ
39 #define NAV_PRESCALER (512/NAV_FREQ)
40 
41 extern struct EnuCoor_i navigation_target;
42 extern struct EnuCoor_i navigation_carrot;
43 
44 extern struct EnuCoor_i waypoints[];
45 extern const uint8_t nb_waypoint;
46 
47 extern void nav_init(void);
48 extern void nav_run(void);
49 
50 extern uint8_t last_wp __attribute__ ((unused));
51 
52 extern int32_t ground_alt;
53 
58 #define HORIZONTAL_MODE_WAYPOINT 0
59 #define HORIZONTAL_MODE_ROUTE 1
60 #define HORIZONTAL_MODE_CIRCLE 2
61 #define HORIZONTAL_MODE_ATTITUDE 3
62 extern int32_t nav_roll, nav_pitch;
64 extern float nav_radius;
65 
67 extern int32_t nav_leg_length;
68 
69 extern uint8_t vertical_mode;
70 extern uint32_t nav_throttle;
72 extern float flight_altitude;
73 #define VERTICAL_MODE_MANUAL 0
74 #define VERTICAL_MODE_CLIMB 1
75 #define VERTICAL_MODE_ALT 2
76 
77 
78 void compute_dist2_to_home(void);
79 unit_t nav_reset_reference( void ) __attribute__ ((unused));
80 unit_t nav_reset_alt( void ) __attribute__ ((unused));
81 void nav_periodic_task(void);
82 void nav_move_waypoint(uint8_t wp_id, struct EnuCoor_i * new_pos);
83 bool_t nav_detect_ground(void);
84 
85 void nav_home(void);
86 
87 #define NavKillThrottle() ({ if (autopilot_mode == AP_MODE_NAV) { autopilot_set_motors_on(FALSE); } FALSE; })
88 #define NavResurrect() ({ if (autopilot_mode == AP_MODE_NAV) { autopilot_set_motors_on(TRUE); } FALSE; })
89 
90 
91 #define NavSetGroundReferenceHere() ({ nav_reset_reference(); FALSE; })
92 #define NavSetAltitudeReferenceHere() ({ nav_reset_alt(); FALSE; })
93 
94 #define NavSetWaypointHere(_wp) ({ VECT2_COPY(waypoints[_wp], *stateGetPositionEnu_i()); FALSE; })
95 #define NavCopyWaypoint(_wp1, _wp2) ({ VECT2_COPY(waypoints[_wp1], waypoints[_wp2]); FALSE; })
96 
97 #define WaypointX(_wp) POS_FLOAT_OF_BFP(waypoints[_wp].x)
98 #define WaypointY(_wp) POS_FLOAT_OF_BFP(waypoints[_wp].y)
99 #define WaypointAlt(_wp) POS_FLOAT_OF_BFP(waypoints[_wp].z)
100 #define Height(_h) (_h)
101 
103 #define NormCourse(x) { \
104  while (x < 0) x += 360; \
105  while (x >= 360) x -= 360; \
106 }
107 
108 /*********** Navigation to waypoint *************************************/
109 #define NavGotoWaypoint(_wp) { \
110  horizontal_mode = HORIZONTAL_MODE_WAYPOINT; \
111  INT32_VECT3_COPY( navigation_target, waypoints[_wp]); \
112 }
113 
114 /*********** Navigation on a circle **************************************/
115 extern void nav_circle(uint8_t wp_center, int32_t radius);
116 #define NavCircleWaypoint(_center, _radius) { \
117  horizontal_mode = HORIZONTAL_MODE_CIRCLE; \
118  nav_circle(_center, POS_BFP_OF_REAL(_radius)); \
119 }
120 
121 #define NavCircleCount() (abs(nav_circle_radians) / INT32_ANGLE_2_PI)
122 #define NavCircleQdr() ({ int32_t qdr = INT32_DEG_OF_RAD(INT32_ANGLE_2_PI_2 - nav_circle_qdr) >> INT32_ANGLE_FRAC; NormCourse(qdr); qdr; })
123 
125 #define NavQdrCloseTo(x) {}
126 #define NavCourseCloseTo(x) {}
127 
128 /*********** Navigation along a line *************************************/
129 extern void nav_route(uint8_t wp_start, uint8_t wp_end);
130 #define NavSegment(_start, _end) { \
131  horizontal_mode = HORIZONTAL_MODE_ROUTE; \
132  nav_route(_start, _end); \
133 }
134 
136 #define NavGlide(_last_wp, _wp) { \
137  int32_t start_alt = waypoints[_last_wp].z; \
138  int32_t diff_alt = waypoints[_wp].z - start_alt; \
139  int32_t alt = start_alt + ((diff_alt * nav_leg_progress) / nav_leg_length); \
140  NavVerticalAltitudeMode(POS_FLOAT_OF_BFP(alt),0); \
141 }
142 
143 bool_t nav_approaching_from(uint8_t wp_idx, uint8_t from_idx);
144 #define NavApproaching(wp, time) nav_approaching_from(wp, 0)
145 #define NavApproachingFrom(wp, from, time) nav_approaching_from(wp, from)
146 
149 #define NavVerticalAutoThrottleMode(_pitch) { \
150  nav_pitch = ANGLE_BFP_OF_REAL(_pitch); \
151 }
152 
155 #define NavVerticalAutoPitchMode(_throttle) {}
156 
159 #define NavVerticalAltitudeMode(_alt, _pre_climb) { \
160  vertical_mode = VERTICAL_MODE_ALT; \
161  nav_altitude = POS_BFP_OF_REAL(_alt); \
162 }
163 
165 #define NavVerticalClimbMode(_climb) { \
166  vertical_mode = VERTICAL_MODE_CLIMB; \
167  nav_climb = SPEED_BFP_OF_REAL(_climb); \
168 }
169 
171 #define NavVerticalThrottleMode(_throttle) { \
172  vertical_mode = VERTICAL_MODE_MANUAL; \
173  nav_throttle = _throttle; \
174 }
175 
176 #define NavHeading(_course) {}
177 
178 #define NavAttitude(_roll) { \
179  horizontal_mode = HORIZONTAL_MODE_ATTITUDE; \
180  nav_roll = ANGLE_BFP_OF_REAL(_roll); \
181 }
182 
183 #define NavStartDetectGround() ({ autopilot_detect_ground_once = TRUE; FALSE; })
184 #define NavDetectGround() nav_detect_ground()
185 
186 #define nav_IncreaseShift(x) {}
187 
188 #define nav_SetNavRadius(x) {}
189 
190 #define navigation_SetNavHeading(x) { \
191  nav_heading = ANGLE_BFP_OF_REAL(x); \
192 }
193 
194 #define navigation_SetFlightAltitude(x) { \
195  flight_altitude = x; \
196  nav_flight_altitude = POS_BFP_OF_REAL(flight_altitude) - ground_alt; \
197 }
198 
199 
200 #define GetPosX() (stateGetPositionEnu_f()->x)
201 #define GetPosY() (stateGetPositionEnu_f()->y)
202 #define GetPosAlt() (stateGetPositionEnu_f()->z+ground_alt)
203 #define GetAltRef() (ground_alt)
204 
205 
206 extern void navigation_update_wp_from_speed(uint8_t wp, struct Int16Vect3 speed_sp, int16_t heading_rate_sp );
207 
208 #endif /* NAVIGATION_H */
static float radius
Definition: chemotaxis.c:15
Paparazzi floating point math for geodetic calculations.
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
unsigned char uint8_t
Definition: types.h:14
vector in East North Up coordinates