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))
49 #define PowerVoltage() (ap_electrical.vsupply)
50 #define RcRoll(travel) (imcu_get_radio(RADIO_ROLL) * (float)travel /(float)MAX_PPRZ)
80 #define NAV_MODE_ROLL 1
81 #define NAV_MODE_COURSE 2
85 #define HORIZONTAL_MODE_WAYPOINT 0
86 #define HORIZONTAL_MODE_ROUTE 1
87 #define HORIZONTAL_MODE_CIRCLE 2
91 #define NavGotoWaypoint(_wp) { \
92 horizontal_mode = HORIZONTAL_MODE_WAYPOINT; \
93 fly_to_xy(waypoints[_wp].x, waypoints[_wp].y); \
99 #define Eight(a, b, c) nav_eight((a), (b), (c))
104 #define Oval(a, b, c) nav_oval((b), (a), (c))
130 #define RCLost() bit_is_set(imcu_get_status(), STATUS_RADIO_REALLY_LOST)
133 #define NavFollow(_ac_id, _distance, _height) nav_follow(_ac_id, _distance, _height)
136 #define NavGlide(_start_wp, _wp) nav_glide(_start_wp, _wp)
138 #define NavCircleWaypoint(wp, radius) \
139 nav_circle_XY(waypoints[wp].x, waypoints[wp].y, radius)
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; \
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; })
152 #define CloseDegAngles(_c1, _c2) ({ float _diff = _c1 - _c2; NormCourse(_diff); 350 < _diff || _diff < 10; })
155 #define NavQdrCloseTo(x) CloseDegAngles(x, NavCircleQdr())
157 #define NavCourseCloseTo(x) CloseDegAngles(x, DegOfRad(stateGetHorizontalSpeedDir_f()))
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)
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)
171 #define NavVerticalAutoThrottleMode(_pitch) { \
172 v_ctl_climb_mode = V_CTL_CLIMB_MODE_AUTO_THROTTLE; \
173 nav_pitch = _pitch; \
178 #define NavVerticalAutoPitchMode(_throttle) { \
179 v_ctl_climb_mode = V_CTL_CLIMB_MODE_AUTO_PITCH; \
180 nav_throttle_setpoint = _throttle; \
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; \
192 #define NavVerticalClimbMode(_climb) { \
193 v_ctl_mode = V_CTL_MODE_AUTO_CLIMB; \
194 v_ctl_climb_setpoint = _climb; \
198 #define NavVerticalThrottleMode(_throttle) { \
199 v_ctl_mode = V_CTL_MODE_AUTO_THROTTLE; \
200 nav_throttle_setpoint = _throttle; \
203 #define NavHeading(_course) { \
204 lateral_mode = LATERAL_MODE_COURSE; \
205 h_ctl_course_setpoint = _course; \
208 #define NavAttitude(_roll) { \
209 lateral_mode = LATERAL_MODE_ROLL; \
210 if(autopilot_get_mode() != AP_MODE_AUTO1) \
211 {h_ctl_roll_setpoint = _roll;} \
214 #define NavSetManual(_roll, _pitch, _yaw) _Pragma("GCC error \"Manual mode in flight plan for fixedwing is not available\"")
217 #define nav_IncreaseShift(x) { if (x==0) nav_shift = 0; else nav_shift += x; }
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; }
221 #define NavKillThrottle() { autopilot_set_kill_throttle(true); }
224 #define GetPosX() (stateGetPositionEnu_f()->x)
225 #define GetPosY() (stateGetPositionEnu_f()->y)
227 #define GetPosAlt() (stateGetPositionUtm_f()->alt)
235 #define GetAltRef() (ground_alt)
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); \
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.
void nav_follow(uint8_t _ac_id, float _distance, float _height)
float nav_circle_radians
Status on the current circle.
void nav_init(void)
Navigation Initialisation.
void nav_glide(uint8_t start_wp, uint8_t wp)
pprz_t nav_throttle_setpoint
void nav_eight_init(void)
float nav_circle_radians_no_rewind
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.
uint8_t last_wp
Index of last waypoint.
void DownlinkSendWpNr(uint8_t _wp)
void nav_home(void)
Home mode navigation (circle around HOME)
float nav_ground_speed_setpoint
float nav_circle_trigo_qdr
void nav_compute_final_from_glide(uint8_t wp_af, uint8_t wp_td, float glide)
Core autopilot interface common to all firmwares.
uint8_t nav_oval_count
Navigation along a figure O.
void nav_compute_baseleg(uint8_t wp_af, uint8_t wp_td, uint8_t wp_baseleg, float radius)
API to get/set the generic vehicle states.
void nav_oval(uint8_t, uint8_t, float)
Navigation along a figure O.
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.
float nav_ground_speed_pgain
float flight_altitude
Dynamically adjustable, reset to nav_altitude when it is changing.