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
nav.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2003-2009 ENAC, Pascal Brisset, Antoine Drouin
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 
31 #ifndef NAV_H
32 #define NAV_H
33 
34 #include "std.h"
35 #include "paparazzi.h"
36 #include "state.h"
37 #ifdef CTRL_TYPE_H
38 #include CTRL_TYPE_H
39 #endif
43 
44 #define NAV_GRAVITY 9.806
45 #define Square(_x) ((_x)*(_x))
46 #define DistanceSquare(p1_x, p1_y, p2_x, p2_y) (Square(p1_x-p2_x)+Square(p1_y-p2_y))
47 
48 enum oval_status { OR12, OC2, OR21, OC1 };
49 
50 extern float cur_pos_x;
51 extern float cur_pos_y;
52 extern float last_x, last_y;
53 
55 
57 extern float nav_pitch; /* Rad */
58 extern float rc_pitch;
59 extern float fp_pitch; /* Degrees */
60 extern float fp_throttle; /* [0-1] */
61 extern float fp_climb; /* m/s */
62 
63 extern float carrot_x, carrot_y;
64 
65 extern float nav_circle_radians; /* Cumulated */
66 extern float nav_circle_radians_no_rewind; /* Cumulated */
67 extern bool_t nav_in_circle;
68 extern bool_t nav_in_segment;
69 extern float nav_circle_x, nav_circle_y, nav_circle_radius; /* m */
71 
72 extern int nav_mode;
73 #define NAV_MODE_ROLL 1
74 #define NAV_MODE_COURSE 2
75 
77 
78 #define HORIZONTAL_MODE_WAYPOINT 0
79 #define HORIZONTAL_MODE_ROUTE 1
80 #define HORIZONTAL_MODE_CIRCLE 2
81 
82 extern void fly_to_xy(float x, float y);
83 
84 #define NavGotoWaypoint(_wp) { \
85  horizontal_mode = HORIZONTAL_MODE_WAYPOINT; \
86  fly_to_xy(waypoints[_wp].x, waypoints[_wp].y); \
87  }
88 
89 
90 extern void nav_eight_init(void);
91 extern void nav_eight(uint8_t, uint8_t, float);
92 #define Eight(a, b, c) nav_eight((a), (b), (c))
93 
94 extern void nav_oval_init(void);
95 extern void nav_oval(uint8_t, uint8_t, float);
96 extern uint8_t nav_oval_count;
97 #define Oval(a, b, c) nav_oval((b), (a), (c))
98 
99 extern float nav_radius; /* m */
100 extern float nav_course; /* degrees, clockwise, 0.0 = N */
101 extern float nav_climb; /* m/s */
102 extern float nav_shift; /* Lateral shift along a route. In meters */
103 
105 
106 
107 extern float nav_survey_shift;
109 extern bool_t nav_survey_active;
110 
111 void nav_periodic_task(void);
112 void nav_home(void);
113 void nav_init(void);
114 void nav_without_gps(void);
115 
116 extern float nav_circle_trigo_qdr;
117 extern void nav_circle_XY(float x, float y, float radius);
118 
119 #define NavCircleWaypoint(wp, radius) \
120  nav_circle_XY(waypoints[wp].x, waypoints[wp].y, radius)
121 
123 #define NormCourse(x) { \
124  uint8_t dont_loop_forever = 0; \
125  while (x < 0 && ++dont_loop_forever) x += 360; \
126  while (x >= 360 && ++dont_loop_forever) x -= 360; \
127  }
128 
129 #define NavCircleCountNoRewind() (nav_circle_radians_no_rewind / (2*M_PI))
130 #define NavCircleCount() (fabs(nav_circle_radians) / (2*M_PI))
131 #define NavCircleQdr() ({ float qdr = DegOfRad(M_PI_2 - nav_circle_trigo_qdr); NormCourse(qdr); qdr; })
132 
133 #define CloseDegAngles(_c1, _c2) ({ float _diff = _c1 - _c2; NormCourse(_diff); 350 < _diff || _diff < 10; })
134 
136 #define NavQdrCloseTo(x) CloseDegAngles(x, NavCircleQdr())
137 
138 #define NavCourseCloseTo(x) CloseDegAngles(x, DegOfRad(stateGetHorizontalSpeedDir_f()))
139 
140 /*********** Navigation along a line *************************************/
141 extern void nav_route_xy(float last_wp_x, float last_wp_y, float wp_x, float wp_y);
142 #define NavSegment(_start, _end) \
143  nav_route_xy(waypoints[_start].x, waypoints[_start].y, waypoints[_end].x, waypoints[_end].y)
144 
145 bool_t nav_approaching_xy(float x, float y, float from_x, float from_y, float approaching_time);
146 #define NavApproaching(wp, time) nav_approaching_xy(waypoints[wp].x, waypoints[wp].y, last_x, last_y, time)
147 #define NavApproachingFrom(wp, from, time) nav_approaching_xy(waypoints[wp].x, waypoints[wp].y, waypoints[from].x, waypoints[from].y, time)
148 
149 
152 #define NavVerticalAutoThrottleMode(_pitch) { \
153  v_ctl_climb_mode = V_CTL_CLIMB_MODE_AUTO_THROTTLE; \
154  nav_pitch = _pitch; \
155  }
156 
159 #define NavVerticalAutoPitchMode(_throttle) { \
160  v_ctl_climb_mode = V_CTL_CLIMB_MODE_AUTO_PITCH; \
161  nav_throttle_setpoint = _throttle; \
162  }
163 
166 #define NavVerticalAltitudeMode(_alt, _pre_climb) { \
167  v_ctl_mode = V_CTL_MODE_AUTO_ALT; \
168  nav_altitude = _alt; \
169  v_ctl_altitude_pre_climb = _pre_climb; \
170  }
171 
173 #define NavVerticalClimbMode(_climb) { \
174  v_ctl_mode = V_CTL_MODE_AUTO_CLIMB; \
175  v_ctl_climb_setpoint = _climb; \
176  }
177 
179 #define NavVerticalThrottleMode(_throttle) { \
180  v_ctl_mode = V_CTL_MODE_AUTO_THROTTLE; \
181  nav_throttle_setpoint = _throttle; \
182  }
183 
184 #define NavHeading(_course) { \
185  lateral_mode = LATERAL_MODE_COURSE; \
186  h_ctl_course_setpoint = _course; \
187  }
188 
189 #define NavAttitude(_roll) { \
190  lateral_mode = LATERAL_MODE_ROLL; \
191  if(pprz_mode != PPRZ_MODE_AUTO1) \
192  {h_ctl_roll_setpoint = _roll;} \
193  }
194 
195 #define nav_IncreaseShift(x) { if (x==0) nav_shift = 0; else nav_shift += x; }
196 
197 #define nav_SetNavRadius(x) { if (x==1) nav_radius = DEFAULT_CIRCLE_RADIUS; else if (x==-1) nav_radius = -DEFAULT_CIRCLE_RADIUS; else nav_radius = x; }
198 
199 #define NavKillThrottle() { kill_throttle = 1; }
200 
201 #define GetPosX() (stateGetPositionEnu_f()->x)
202 #define GetPosY() (stateGetPositionEnu_f()->y)
203 #define GetPosAlt() (stateGetPositionUtm_f()->alt)
204 #define GetAltRef() (ground_alt)
205 
206 #if DOWNLINK
207 #define SEND_NAVIGATION(_trans, _dev) { \
208  uint8_t _circle_count = NavCircleCount(); \
209  struct EnuCoor_f* pos = stateGetPositionEnu_f(); \
210  float dist_wp = sqrtf(dist2_to_wp); \
211  float dist_home = sqrtf(dist2_to_home); \
212  pprz_msg_send_NAVIGATION(_trans, _dev, AC_ID, &nav_block, &nav_stage, &(pos->x), &(pos->y), &dist_wp, &dist_home, &_circle_count, &nav_oval_count); \
213  }
214 
215 extern bool_t DownlinkSendWpNr(uint8_t _wp);
216 
217 #define DownlinkSendWp(_trans, _dev, i) { \
218  float x = nav_utm_east0 + waypoints[i].x; \
219  float y = nav_utm_north0 + waypoints[i].y; \
220  pprz_msg_send_WP_MOVED(_trans, _dev, AC_ID, &i, &x, &y, &(waypoints[i].a),&nav_utm_zone0); \
221  }
222 #endif /* DOWNLINK */
223 
224 #endif /* NAV_H */
float x
Definition: common_nav.h:40
int16_t pprz_t
Definition: paparazzi.h:6
static float radius
Definition: chemotaxis.c:15
float y
Definition: common_nav.h:41
unsigned char uint8_t
Definition: types.h:14
API to get/set the generic vehicle states.
Common flight_plan functions shared between fixedwing and rotorcraft.