Paparazzi UAS  v6.1.0_stable
Paparazzi is a free software Unmanned Aircraft System.
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
42 #include "modules/nav/common_nav.h"
43 #include "autopilot.h"
44 
46 #ifndef NAVIGATION_FREQUENCY
47 #define NAVIGATION_FREQUENCY 20
48 #endif
49 
50 #define NAV_GRAVITY 9.806
51 #define Square(_x) ((_x)*(_x))
52 #define DistanceSquare(p1_x, p1_y, p2_x, p2_y) (Square(p1_x-p2_x)+Square(p1_y-p2_y))
53 
54 #define PowerVoltage() (ap_electrical.vsupply)
55 #define RcRoll(travel) (imcu_get_radio(RADIO_ROLL) * (float)travel /(float)MAX_PPRZ)
56 
57 
58 enum oval_status { OR12, OC2, OR21, OC1 };
59 extern enum oval_status oval_status;
60 extern float cur_pos_x;
61 extern float cur_pos_y;
62 extern float last_x, last_y;
63 
65 
67 extern float nav_pitch; /* Rad */
68 extern float rc_pitch;
69 extern float fp_pitch; /* Degrees */
70 extern float fp_throttle; /* [0-1] */
71 extern float fp_climb; /* m/s */
72 
73 extern float carrot_x, carrot_y;
74 
75 extern float nav_circle_radians; /* Cumulated */
76 extern float nav_circle_radians_no_rewind; /* Cumulated */
77 extern bool nav_in_circle;
78 extern bool nav_in_segment;
81 
82 extern uint8_t last_wp __attribute__((unused));
83 
84 extern int nav_mode;
85 #define NAV_MODE_ROLL 1
86 #define NAV_MODE_COURSE 2
87 
89 
90 #define HORIZONTAL_MODE_WAYPOINT 0
91 #define HORIZONTAL_MODE_ROUTE 1
92 #define HORIZONTAL_MODE_CIRCLE 2
93 
94 extern void fly_to_xy(float x, float y);
95 
96 #define NavGotoWaypoint(_wp) { \
97  horizontal_mode = HORIZONTAL_MODE_WAYPOINT; \
98  fly_to_xy(waypoints[_wp].x, waypoints[_wp].y); \
99  }
100 
101 
102 extern void nav_eight_init(void);
103 extern void nav_eight(uint8_t, uint8_t, float);
104 #define Eight(a, b, c) nav_eight((a), (b), (c))
105 
106 extern void nav_oval_init(void);
107 extern void nav_oval(uint8_t, uint8_t, float);
108 extern uint8_t nav_oval_count;
109 #define Oval(a, b, c) nav_oval((b), (a), (c))
110 
111 extern float nav_radius; /* m */
112 extern float nav_course; /* degrees, clockwise, 0.0 = N */
113 extern float nav_climb; /* m/s */
114 extern float nav_shift; /* Lateral shift along a route. In meters */
115 
117 
118 
119 extern float nav_survey_shift;
121 extern bool nav_survey_active;
122 
123 extern void nav_periodic_task(void);
124 extern void nav_home(void);
125 extern void nav_init(void);
126 extern void nav_without_gps(void);
127 
128 extern float nav_circle_trigo_qdr;
129 extern void nav_circle_XY(float x, float y, float radius);
130 
131 extern float baseleg_out_qdr;
132 extern void nav_compute_baseleg(uint8_t wp_af, uint8_t wp_td, uint8_t wp_baseleg, float radius);
133 extern void nav_compute_final_from_glide(uint8_t wp_af, uint8_t wp_td, float glide);
134 
135 #define RCLost() bit_is_set(imcu_get_status(), STATUS_RADIO_REALLY_LOST)
136 
137 extern void nav_follow(uint8_t _ac_id, float _distance, float _height);
138 #define NavFollow(_ac_id, _distance, _height) nav_follow(_ac_id, _distance, _height)
139 
140 extern void nav_glide(uint8_t start_wp, uint8_t wp);
141 #define NavGlide(_start_wp, _wp) nav_glide(_start_wp, _wp)
142 
143 #define NavCircleWaypoint(wp, radius) \
144  nav_circle_XY(waypoints[wp].x, waypoints[wp].y, radius)
145 
147 #define NormCourse(x) { \
148  uint8_t dont_loop_forever = 0; \
149  while (x < 0 && ++dont_loop_forever) x += 360; \
150  while (x >= 360 && ++dont_loop_forever) x -= 360; \
151  }
152 
153 #define NavCircleCountNoRewind() (nav_circle_radians_no_rewind / (2*M_PI))
154 #define NavCircleCount() (fabs(nav_circle_radians) / (2*M_PI))
155 #define NavCircleQdr() ({ float qdr = DegOfRad(M_PI_2 - nav_circle_trigo_qdr); NormCourse(qdr); qdr; })
156 
157 #define CloseDegAngles(_c1, _c2) ({ float _diff = _c1 - _c2; NormCourse(_diff); 350 < _diff || _diff < 10; })
158 
160 #define NavQdrCloseTo(x) CloseDegAngles(x, NavCircleQdr())
161 
162 #define NavCourseCloseTo(x) CloseDegAngles(x, DegOfRad(stateGetHorizontalSpeedDir_f()))
163 
164 /*********** Navigation along a line *************************************/
165 extern void nav_route_xy(float last_wp_x, float last_wp_y, float wp_x, float wp_y);
166 #define NavSegment(_start, _end) \
167  nav_route_xy(waypoints[_start].x, waypoints[_start].y, waypoints[_end].x, waypoints[_end].y)
168 
169 bool nav_approaching_xy(float x, float y, float from_x, float from_y, float approaching_time);
170 #define NavApproaching(wp, time) nav_approaching_xy(waypoints[wp].x, waypoints[wp].y, last_x, last_y, time)
171 #define NavApproachingFrom(wp, from, time) nav_approaching_xy(waypoints[wp].x, waypoints[wp].y, waypoints[from].x, waypoints[from].y, time)
172 
173 
176 #define NavVerticalAutoThrottleMode(_pitch) { \
177  v_ctl_climb_mode = V_CTL_CLIMB_MODE_AUTO_THROTTLE; \
178  nav_pitch = _pitch; \
179  }
180 
183 #define NavVerticalAutoPitchMode(_throttle) { \
184  v_ctl_climb_mode = V_CTL_CLIMB_MODE_AUTO_PITCH; \
185  nav_throttle_setpoint = _throttle; \
186  }
187 
190 #define NavVerticalAltitudeMode(_alt, _pre_climb) { \
191  v_ctl_mode = V_CTL_MODE_AUTO_ALT; \
192  nav_altitude = _alt; \
193  v_ctl_altitude_pre_climb = _pre_climb; \
194  }
195 
197 #define NavVerticalClimbMode(_climb) { \
198  v_ctl_mode = V_CTL_MODE_AUTO_CLIMB; \
199  v_ctl_climb_setpoint = _climb; \
200  }
201 
203 #define NavVerticalThrottleMode(_throttle) { \
204  v_ctl_mode = V_CTL_MODE_AUTO_THROTTLE; \
205  nav_throttle_setpoint = _throttle; \
206  }
207 
208 #define NavHeading(_course) { \
209  lateral_mode = LATERAL_MODE_COURSE; \
210  h_ctl_course_setpoint = _course; \
211  }
212 
213 #define NavAttitude(_roll) { \
214  lateral_mode = LATERAL_MODE_ROLL; \
215  if(autopilot_get_mode() != AP_MODE_AUTO1) \
216  {h_ctl_roll_setpoint = _roll;} \
217  }
218 
219 #define NavSetManual(_roll, _pitch, _yaw) _Pragma("GCC error \"Manual mode in flight plan for fixedwing is not available\"")
220 
221 
222 #define nav_IncreaseShift(x) { if (x==0) nav_shift = 0; else nav_shift += x; }
223 
224 #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; }
225 
226 #define NavKillThrottle() { autopilot_set_kill_throttle(true); }
227 
229 #define GetPosX() (stateGetPositionEnu_f()->x)
230 #define GetPosY() (stateGetPositionEnu_f()->y)
232 #define GetPosAlt() (stateGetPositionUtm_f()->alt)
234 #define GetPosHeight() (stateGetPositionEnu_f()->z)
236 
242 #define GetAltRef() (ground_alt)
243 
244 #if DOWNLINK
245 #define SEND_NAVIGATION(_trans, _dev) { \
246  uint8_t _circle_count = NavCircleCount(); \
247  struct EnuCoor_f* pos = stateGetPositionEnu_f(); \
248  float dist_wp = sqrtf(dist2_to_wp); \
249  float dist_home = sqrtf(dist2_to_home); \
250  uint8_t kill = (uint8_t)autopilot.kill_throttle; \
251  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); \
252  }
253 
254 extern void DownlinkSendWpNr(uint8_t _wp);
255 
256 #endif /* DOWNLINK */
257 
258 #endif /* NAV_H */
nav_segment_x_1
float nav_segment_x_1
Definition: nav.c:70
nav_survey_south
float nav_survey_south
Definition: nav.h:120
nav_survey_west
float nav_survey_west
Definition: nav.c:88
common_flight_plan.h
uint8_t
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
Definition: vl53l1_types.h:98
nav_init
void nav_init(void)
Navigation Initialisation.
Definition: nav.c:531
nav_ground_speed_setpoint
float nav_ground_speed_setpoint
Definition: nav.h:116
nav_ground_speed_pgain
float nav_ground_speed_pgain
Definition: nav.c:84
nav_oval
void nav_oval(uint8_t, uint8_t, float)
Navigation along a figure O.
Definition: nav.c:734
nav_oval_init
void nav_oval_init(void)
Definition: nav.c:728
carrot_x
float carrot_x
Definition: nav.c:51
nav_circle_radius
float nav_circle_radius
Definition: nav.h:79
nav_survey_east
float nav_survey_east
Definition: nav.h:120
nav_circle_radians
float nav_circle_radians
Status on the current circle.
Definition: nav.c:54
nav_pitch
float nav_pitch
with INT32_ANGLE_FRAC
Definition: nav.c:309
horizontal_mode
uint8_t horizontal_mode
Definition: nav.c:71
nav_in_circle
bool nav_in_circle
Definition: nav.c:67
nav_segment_y_2
float nav_segment_y_2
Definition: nav.h:80
nav_circle_x
float nav_circle_x
Definition: nav.c:69
fp_throttle
float fp_throttle
Definition: nav.c:311
cur_pos_x
float cur_pos_x
common_nav.h
nav_compute_final_from_glide
void nav_compute_final_from_glide(uint8_t wp_af, uint8_t wp_td, float glide)
Definition: nav.c:240
baseleg_out_qdr
float baseleg_out_qdr
Definition: nav.c:218
OR12
@ OR12
Definition: nav.h:58
paparazzi.h
desired_y
float desired_y
Definition: nav.h:64
flight_altitude
float flight_altitude
Dynamically adjustable, reset to nav_altitude when it is changing.
Definition: nav.h:64
nav_home
void nav_home(void)
Home mode navigation (circle around HOME)
Definition: nav.c:423
nav_oval_count
uint8_t nav_oval_count
Navigation along a figure O.
Definition: nav.c:726
nav_course
float nav_course
Definition: nav.c:57
desired_x
float desired_x
Definition: nav.c:307
std.h
OC1
@ OC1
Definition: nav.h:58
nav_eight
void nav_eight(uint8_t, uint8_t, float)
Navigation along a figure 8.
Definition: nav.c:605
pprz_t
int16_t pprz_t
Definition: paparazzi.h:6
last_x
float last_x
Definition: nav.c:45
nav_route_xy
void nav_route_xy(float last_wp_x, float last_wp_y, float wp_x, float wp_y)
Computes the carrot position along the desired segment.
Definition: nav.c:381
nav_in_segment
bool nav_in_segment
Definition: nav.c:68
OR21
@ OR21
Definition: nav.h:58
nav_throttle_setpoint
pprz_t nav_throttle_setpoint
Definition: nav.c:308
rc_pitch
float rc_pitch
Definition: nav.c:50
nav_follow
void nav_follow(uint8_t _ac_id, float _distance, float _height)
Definition: nav.c:301
point::x
float x
Definition: common_nav.h:40
nav_without_gps
void nav_without_gps(void)
Failsafe navigation without position estimation.
Definition: nav.c:569
nav_segment_x_2
float nav_segment_x_2
Definition: nav.h:80
autopilot.h
last_wp
uint8_t last_wp
Index of last waypoint.
Definition: nav.c:48
oval_status
oval_status
Definition: nav.h:58
nav_circle_trigo_qdr
float nav_circle_trigo_qdr
Definition: nav.c:56
cur_pos_y
float cur_pos_y
nav_altitude
float nav_altitude
Definition: nav.h:64
last_y
float last_y
Definition: nav.h:62
nav_approaching_xy
bool nav_approaching_xy(float x, float y, float from_x, float from_y, float approaching_time)
Decide if the UAV is approaching the current waypoint.
Definition: nav.c:324
nav_shift
float nav_shift
Definition: nav.c:57
DownlinkSendWpNr
void DownlinkSendWpNr(uint8_t _wp)
Definition: nav.c:496
nav_glide
void nav_glide(uint8_t start_wp, uint8_t wp)
Definition: nav.c:159
nav_radius
float nav_radius
Definition: nav.c:57
fp_climb
float fp_climb
Definition: nav.c:312
nav_glide_pitch_trim
float nav_glide_pitch_trim
Definition: nav.h:64
nav_periodic_task
void nav_periodic_task(void)
Navigation main: call to the code generated from the XML flight plan.
Definition: nav.c:444
nav_climb
float nav_climb
Definition: nav.c:57
point::y
float y
Definition: common_nav.h:41
nav_segment_y_1
float nav_segment_y_1
Definition: nav.h:80
nav_eight_init
void nav_eight_init(void)
Definition: nav.c:592
nav_survey_north
float nav_survey_north
Definition: nav.h:120
fp_pitch
float fp_pitch
Definition: nav.c:310
nav_circle_radians_no_rewind
float nav_circle_radians_no_rewind
Definition: nav.c:55
state.h
nav_circle_y
float nav_circle_y
Definition: nav.h:79
nav_compute_baseleg
void nav_compute_baseleg(uint8_t wp_af, uint8_t wp_td, uint8_t wp_baseleg, float radius)
Definition: nav.c:219
nav_survey_shift
float nav_survey_shift
Definition: nav.c:87
fly_to_xy
void fly_to_xy(float x, float y)
Computes desired_x, desired_y and desired_course.
Definition: nav.c:355
carrot_y
float carrot_y
Definition: nav.h:73
nav_mode
int nav_mode
Definition: nav.c:91
nav_survey_active
bool nav_survey_active
Definition: nav.c:89
nav_survey_rectangle.h
OC2
@ OC2
Definition: nav.h:58
nav_circle_XY
void nav_circle_XY(float x, float y, float radius)
Angle from center to mobile.
Definition: nav.c:109