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
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 #define PowerVoltage() (vsupply/10.)
49 #define RcRoll(travel) (imcu_get_radio(RADIO_ROLL) * (float)travel /(float)MAX_PPRZ)
50 
51 
52 enum oval_status { OR12, OC2, OR21, OC1 };
53 
54 extern float cur_pos_x;
55 extern float cur_pos_y;
56 extern float last_x, last_y;
57 
59 
61 extern float nav_pitch; /* Rad */
62 extern float rc_pitch;
63 extern float fp_pitch; /* Degrees */
64 extern float fp_throttle; /* [0-1] */
65 extern float fp_climb; /* m/s */
66 
67 extern float carrot_x, carrot_y;
68 
69 extern float nav_circle_radians; /* Cumulated */
70 extern float nav_circle_radians_no_rewind; /* Cumulated */
71 extern bool nav_in_circle;
72 extern bool nav_in_segment;
73 extern float nav_circle_x, nav_circle_y, nav_circle_radius; /* m */
75 
76 extern uint8_t last_wp __attribute__((unused));
77 
78 extern int nav_mode;
79 #define NAV_MODE_ROLL 1
80 #define NAV_MODE_COURSE 2
81 
83 
84 #define HORIZONTAL_MODE_WAYPOINT 0
85 #define HORIZONTAL_MODE_ROUTE 1
86 #define HORIZONTAL_MODE_CIRCLE 2
87 
88 extern void fly_to_xy(float x, float y);
89 
90 #define NavGotoWaypoint(_wp) { \
91  horizontal_mode = HORIZONTAL_MODE_WAYPOINT; \
92  fly_to_xy(waypoints[_wp].x, waypoints[_wp].y); \
93  }
94 
95 
96 extern void nav_eight_init(void);
97 extern void nav_eight(uint8_t, uint8_t, float);
98 #define Eight(a, b, c) nav_eight((a), (b), (c))
99 
100 extern void nav_oval_init(void);
101 extern void nav_oval(uint8_t, uint8_t, float);
102 extern uint8_t nav_oval_count;
103 #define Oval(a, b, c) nav_oval((b), (a), (c))
104 
105 extern float nav_radius; /* m */
106 extern float nav_course; /* degrees, clockwise, 0.0 = N */
107 extern float nav_climb; /* m/s */
108 extern float nav_shift; /* Lateral shift along a route. In meters */
109 
111 
112 
113 extern float nav_survey_shift;
115 extern bool nav_survey_active;
116 
117 extern void nav_periodic_task(void);
118 extern void nav_home(void);
119 extern void nav_init(void);
120 extern void nav_without_gps(void);
121 
122 extern float nav_circle_trigo_qdr;
123 extern void nav_circle_XY(float x, float y, float radius);
124 
125 extern float baseleg_out_qdr;
126 extern bool nav_compute_baseleg(uint8_t wp_af, uint8_t wp_td, uint8_t wp_baseleg, float radius);
127 extern bool nav_compute_final_from_glide(uint8_t wp_af, uint8_t wp_td, float glide);
128 
129 #define RCLost() bit_is_set(imcu_get_status(), STATUS_RADIO_REALLY_LOST)
130 
131 extern void nav_follow(uint8_t _ac_id, float _distance, float _height);
132 #define NavFollow(_ac_id, _distance, _height) nav_follow(_ac_id, _distance, _height)
133 
134 extern void nav_glide(uint8_t start_wp, uint8_t wp);
135 #define NavGlide(_start_wp, _wp) nav_glide(_start_wp, _wp)
136 
137 #define NavCircleWaypoint(wp, radius) \
138  nav_circle_XY(waypoints[wp].x, waypoints[wp].y, radius)
139 
141 #define NormCourse(x) { \
142  uint8_t dont_loop_forever = 0; \
143  while (x < 0 && ++dont_loop_forever) x += 360; \
144  while (x >= 360 && ++dont_loop_forever) x -= 360; \
145  }
146 
147 #define NavCircleCountNoRewind() (nav_circle_radians_no_rewind / (2*M_PI))
148 #define NavCircleCount() (fabs(nav_circle_radians) / (2*M_PI))
149 #define NavCircleQdr() ({ float qdr = DegOfRad(M_PI_2 - nav_circle_trigo_qdr); NormCourse(qdr); qdr; })
150 
151 #define CloseDegAngles(_c1, _c2) ({ float _diff = _c1 - _c2; NormCourse(_diff); 350 < _diff || _diff < 10; })
152 
154 #define NavQdrCloseTo(x) CloseDegAngles(x, NavCircleQdr())
155 
156 #define NavCourseCloseTo(x) CloseDegAngles(x, DegOfRad(stateGetHorizontalSpeedDir_f()))
157 
158 /*********** Navigation along a line *************************************/
159 extern void nav_route_xy(float last_wp_x, float last_wp_y, float wp_x, float wp_y);
160 #define NavSegment(_start, _end) \
161  nav_route_xy(waypoints[_start].x, waypoints[_start].y, waypoints[_end].x, waypoints[_end].y)
162 
163 bool nav_approaching_xy(float x, float y, float from_x, float from_y, float approaching_time);
164 #define NavApproaching(wp, time) nav_approaching_xy(waypoints[wp].x, waypoints[wp].y, last_x, last_y, time)
165 #define NavApproachingFrom(wp, from, time) nav_approaching_xy(waypoints[wp].x, waypoints[wp].y, waypoints[from].x, waypoints[from].y, time)
166 
167 
170 #define NavVerticalAutoThrottleMode(_pitch) { \
171  v_ctl_climb_mode = V_CTL_CLIMB_MODE_AUTO_THROTTLE; \
172  nav_pitch = _pitch; \
173  }
174 
177 #define NavVerticalAutoPitchMode(_throttle) { \
178  v_ctl_climb_mode = V_CTL_CLIMB_MODE_AUTO_PITCH; \
179  nav_throttle_setpoint = _throttle; \
180  }
181 
184 #define NavVerticalAltitudeMode(_alt, _pre_climb) { \
185  v_ctl_mode = V_CTL_MODE_AUTO_ALT; \
186  nav_altitude = _alt; \
187  v_ctl_altitude_pre_climb = _pre_climb; \
188  }
189 
191 #define NavVerticalClimbMode(_climb) { \
192  v_ctl_mode = V_CTL_MODE_AUTO_CLIMB; \
193  v_ctl_climb_setpoint = _climb; \
194  }
195 
197 #define NavVerticalThrottleMode(_throttle) { \
198  v_ctl_mode = V_CTL_MODE_AUTO_THROTTLE; \
199  nav_throttle_setpoint = _throttle; \
200  }
201 
202 #define NavHeading(_course) { \
203  lateral_mode = LATERAL_MODE_COURSE; \
204  h_ctl_course_setpoint = _course; \
205  }
206 
207 #define NavAttitude(_roll) { \
208  lateral_mode = LATERAL_MODE_ROLL; \
209  if(pprz_mode != PPRZ_MODE_AUTO1) \
210  {h_ctl_roll_setpoint = _roll;} \
211  }
212 
213 #define NavSetManual(_roll, _pitch, _yaw) _Pragma("GCC error \"Manual mode in flight plan for fixedwing is not available\"")
214 
215 
216 #define nav_IncreaseShift(x) { if (x==0) nav_shift = 0; else nav_shift += x; }
217 
218 #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; }
219 
220 #define NavKillThrottle() { kill_throttle = 1; }
221 
223 #define GetPosX() (stateGetPositionEnu_f()->x)
224 #define GetPosY() (stateGetPositionEnu_f()->y)
226 #define GetPosAlt() (stateGetPositionUtm_f()->alt)
228 
234 #define GetAltRef() (ground_alt)
235 
236 #if DOWNLINK
237 #define SEND_NAVIGATION(_trans, _dev) { \
238  uint8_t _circle_count = NavCircleCount(); \
239  struct EnuCoor_f* pos = stateGetPositionEnu_f(); \
240  float dist_wp = sqrtf(dist2_to_wp); \
241  float dist_home = sqrtf(dist2_to_home); \
242  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); \
243  }
244 
245 extern bool DownlinkSendWpNr(uint8_t _wp);
246 
247 #define DownlinkSendWp(_trans, _dev, i) { \
248  float x = nav_utm_east0 + waypoints[i].x; \
249  float y = nav_utm_north0 + waypoints[i].y; \
250  pprz_msg_send_WP_MOVED(_trans, _dev, AC_ID, &i, &x, &y, &(waypoints[i].a),&nav_utm_zone0); \
251  }
252 #endif /* DOWNLINK */
253 
254 #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.