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))
48 #define PowerVoltage() (vsupply/10.)
49 #define RcRoll(travel) (imcu_get_radio(RADIO_ROLL) * (float)travel /(float)MAX_PPRZ)
79 #define NAV_MODE_ROLL 1
80 #define NAV_MODE_COURSE 2
84 #define HORIZONTAL_MODE_WAYPOINT 0
85 #define HORIZONTAL_MODE_ROUTE 1
86 #define HORIZONTAL_MODE_CIRCLE 2
90 #define NavGotoWaypoint(_wp) { \
91 horizontal_mode = HORIZONTAL_MODE_WAYPOINT; \
92 fly_to_xy(waypoints[_wp].x, waypoints[_wp].y); \
98 #define Eight(a, b, c) nav_eight((a), (b), (c))
103 #define Oval(a, b, c) nav_oval((b), (a), (c))
129 #define RCLost() bit_is_set(imcu_get_status(), STATUS_RADIO_REALLY_LOST)
132 #define NavFollow(_ac_id, _distance, _height) nav_follow(_ac_id, _distance, _height)
135 #define NavGlide(_start_wp, _wp) nav_glide(_start_wp, _wp)
137 #define NavCircleWaypoint(wp, radius) \
138 nav_circle_XY(waypoints[wp].x, waypoints[wp].y, radius)
141 #define NormCourse(x) { \
142 uint8_t dont_loop_forever = 0; \
143 while (x < 0 && ++dont_loop_forever) x += 360; \
144 while (x >= 360 && ++dont_loop_forever) x -= 360; \
147 #define NavCircleCountNoRewind() (nav_circle_radians_no_rewind / (2*M_PI))
148 #define NavCircleCount() (fabs(nav_circle_radians) / (2*M_PI))
149 #define NavCircleQdr() ({ float qdr = DegOfRad(M_PI_2 - nav_circle_trigo_qdr); NormCourse(qdr); qdr; })
151 #define CloseDegAngles(_c1, _c2) ({ float _diff = _c1 - _c2; NormCourse(_diff); 350 < _diff || _diff < 10; })
154 #define NavQdrCloseTo(x) CloseDegAngles(x, NavCircleQdr())
156 #define NavCourseCloseTo(x) CloseDegAngles(x, DegOfRad(stateGetHorizontalSpeedDir_f()))
159 extern void nav_route_xy(
float last_wp_x,
float last_wp_y,
float wp_x,
float wp_y);
160 #define NavSegment(_start, _end) \
161 nav_route_xy(waypoints[_start].x, waypoints[_start].y, waypoints[_end].x, waypoints[_end].y)
164 #define NavApproaching(wp, time) nav_approaching_xy(waypoints[wp].x, waypoints[wp].y, last_x, last_y, time)
165 #define NavApproachingFrom(wp, from, time) nav_approaching_xy(waypoints[wp].x, waypoints[wp].y, waypoints[from].x, waypoints[from].y, time)
170 #define NavVerticalAutoThrottleMode(_pitch) { \
171 v_ctl_climb_mode = V_CTL_CLIMB_MODE_AUTO_THROTTLE; \
172 nav_pitch = _pitch; \
177 #define NavVerticalAutoPitchMode(_throttle) { \
178 v_ctl_climb_mode = V_CTL_CLIMB_MODE_AUTO_PITCH; \
179 nav_throttle_setpoint = _throttle; \
184 #define NavVerticalAltitudeMode(_alt, _pre_climb) { \
185 v_ctl_mode = V_CTL_MODE_AUTO_ALT; \
186 nav_altitude = _alt; \
187 v_ctl_altitude_pre_climb = _pre_climb; \
191 #define NavVerticalClimbMode(_climb) { \
192 v_ctl_mode = V_CTL_MODE_AUTO_CLIMB; \
193 v_ctl_climb_setpoint = _climb; \
197 #define NavVerticalThrottleMode(_throttle) { \
198 v_ctl_mode = V_CTL_MODE_AUTO_THROTTLE; \
199 nav_throttle_setpoint = _throttle; \
202 #define NavHeading(_course) { \
203 lateral_mode = LATERAL_MODE_COURSE; \
204 h_ctl_course_setpoint = _course; \
207 #define NavAttitude(_roll) { \
208 lateral_mode = LATERAL_MODE_ROLL; \
209 if(autopilot_get_mode() != AP_MODE_AUTO1) \
210 {h_ctl_roll_setpoint = _roll;} \
213 #define NavSetManual(_roll, _pitch, _yaw) _Pragma("GCC error \"Manual mode in flight plan for fixedwing is not available\"")
216 #define nav_IncreaseShift(x) { if (x==0) nav_shift = 0; else nav_shift += x; }
218 #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 #define NavKillThrottle() { autopilot_set_kill_throttle(true); }
223 #define GetPosX() (stateGetPositionEnu_f()->x)
224 #define GetPosY() (stateGetPositionEnu_f()->y)
226 #define GetPosAlt() (stateGetPositionUtm_f()->alt)
234 #define GetAltRef() (ground_alt)
237 #define SEND_NAVIGATION(_trans, _dev) { \
238 uint8_t _circle_count = NavCircleCount(); \
239 struct EnuCoor_f* pos = stateGetPositionEnu_f(); \
240 float dist_wp = sqrtf(dist2_to_wp); \
241 float dist_home = sqrtf(dist2_to_home); \
242 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); \
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)
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.