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))
73 #define NAV_MODE_ROLL 1
74 #define NAV_MODE_COURSE 2
78 #define HORIZONTAL_MODE_WAYPOINT 0
79 #define HORIZONTAL_MODE_ROUTE 1
80 #define HORIZONTAL_MODE_CIRCLE 2
84 #define NavGotoWaypoint(_wp) { \
85 horizontal_mode = HORIZONTAL_MODE_WAYPOINT; \
86 fly_to_xy(waypoints[_wp].x, waypoints[_wp].y); \
92 #define Eight(a, b, c) nav_eight((a), (b), (c))
97 #define Oval(a, b, c) nav_oval((b), (a), (c))
119 #define NavCircleWaypoint(wp, radius) \
120 nav_circle_XY(waypoints[wp].x, waypoints[wp].y, radius)
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; \
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; })
133 #define CloseDegAngles(_c1, _c2) ({ float _diff = _c1 - _c2; NormCourse(_diff); 350 < _diff || _diff < 10; })
136 #define NavQdrCloseTo(x) CloseDegAngles(x, NavCircleQdr())
138 #define NavCourseCloseTo(x) CloseDegAngles(x, DegOfRad(stateGetHorizontalSpeedDir_f()))
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)
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)
152 #define NavVerticalAutoThrottleMode(_pitch) { \
153 v_ctl_climb_mode = V_CTL_CLIMB_MODE_AUTO_THROTTLE; \
154 nav_pitch = _pitch; \
159 #define NavVerticalAutoPitchMode(_throttle) { \
160 v_ctl_climb_mode = V_CTL_CLIMB_MODE_AUTO_PITCH; \
161 nav_throttle_setpoint = _throttle; \
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; \
173 #define NavVerticalClimbMode(_climb) { \
174 v_ctl_mode = V_CTL_MODE_AUTO_CLIMB; \
175 v_ctl_climb_setpoint = _climb; \
179 #define NavVerticalThrottleMode(_throttle) { \
180 v_ctl_mode = V_CTL_MODE_AUTO_THROTTLE; \
181 nav_throttle_setpoint = _throttle; \
184 #define NavHeading(_course) { \
185 lateral_mode = LATERAL_MODE_COURSE; \
186 h_ctl_course_setpoint = _course; \
189 #define NavAttitude(_roll) { \
190 lateral_mode = LATERAL_MODE_ROLL; \
191 if(pprz_mode != PPRZ_MODE_AUTO1) \
192 {h_ctl_roll_setpoint = _roll;} \
195 #define nav_IncreaseShift(x) { if (x==0) nav_shift = 0; else nav_shift += x; }
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; }
199 #define NavKillThrottle() { kill_throttle = 1; }
201 #define GetPosX() (stateGetPositionEnu_f()->x)
202 #define GetPosY() (stateGetPositionEnu_f()->y)
203 #define GetPosAlt() (stateGetPositionUtm_f()->alt)
204 #define GetAltRef() (ground_alt)
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); \
215 extern bool_t DownlinkSendWpNr(
uint8_t _wp);
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); \
float nav_glide_pitch_trim
void nav_periodic_task(void)
Navigation main: call to the code generated from the XML flight plan.
void nav_circle_XY(float x, float y, float radius)
Angle from center to mobile.
void nav_eight(uint8_t, uint8_t, float)
Navigation along a figure 8.
float nav_circle_radians
Status on the current circle.
void nav_init(void)
Periodic telemetry.
pprz_t nav_throttle_setpoint
void nav_eight_init(void)
float nav_circle_radians_no_rewind
void nav_home(void)
Home mode navigation (circle around HOME)
float nav_ground_speed_setpoint
float nav_circle_trigo_qdr
uint8_t nav_oval_count
Navigation along a figure O.
API to get/set the generic vehicle states.
void nav_oval(uint8_t, uint8_t, float)
Common flight_plan functions shared between fixedwing and rotorcraft.
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.
void nav_without_gps(void)
Failsafe navigation without position estimation.
void fly_to_xy(float x, float y)
Computes desired_x, desired_y and desired_course.
bool_t 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.
float nav_ground_speed_pgain
float flight_altitude
Dynamically adjustable, reset to nav_altitude when it is changing.