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