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