51 #define HORIZONTAL_MODE_WAYPOINT 0
52 #define HORIZONTAL_MODE_ROUTE 1
53 #define HORIZONTAL_MODE_CIRCLE 2
54 #define HORIZONTAL_MODE_ATTITUDE 3
55 #define HORIZONTAL_MODE_MANUAL 4
71 #define VERTICAL_MODE_MANUAL 0
72 #define VERTICAL_MODE_CLIMB 1
73 #define VERTICAL_MODE_ALT 2
107 #define NavKillThrottle() ({ if (autopilot_mode == AP_MODE_NAV) { autopilot_set_motors_on(FALSE); } false; })
108 #define NavResurrect() ({ if (autopilot_mode == AP_MODE_NAV) { autopilot_set_motors_on(TRUE); } false; })
111 #define NavSetGroundReferenceHere() ({ nav_reset_reference(); false; })
112 #define NavSetAltitudeReferenceHere() ({ nav_reset_alt(); false; })
114 #define NavSetWaypointHere(_wp) ({ waypoint_set_here_2d(_wp); false; })
115 #define NavCopyWaypoint(_wp1, _wp2) ({ waypoint_copy(_wp1, _wp2); false; })
116 #define NavCopyWaypointPositionOnly(_wp1, _wp2) ({ waypoint_position_copy(_wp1, _wp2); false; })
119 #define NormCourse(x) { \
120 while (x < 0) x += 360; \
121 while (x >= 360) x -= 360; \
125 #define NavGotoWaypoint(_wp) { \
126 horizontal_mode = HORIZONTAL_MODE_WAYPOINT; \
127 VECT3_COPY(navigation_target, waypoints[_wp].enu_i); \
128 dist2_to_wp = get_dist2_to_waypoint(_wp); \
133 #define NavCircleWaypoint(_center, _radius) { \
134 horizontal_mode = HORIZONTAL_MODE_CIRCLE; \
135 nav_circle(&waypoints[_center].enu_i, POS_BFP_OF_REAL(_radius)); \
138 #define NavCircleCount() ((float)abs(nav_circle_radians) / INT32_ANGLE_2_PI)
139 #define NavCircleQdr() ({ int32_t qdr = INT32_DEG_OF_RAD(INT32_ANGLE_PI_2 - nav_circle_qdr) >> INT32_ANGLE_FRAC; NormCourse(qdr); qdr; })
141 #define CloseDegAngles(_c1, _c2) ({ int32_t _diff = _c1 - _c2; NormCourse(_diff); 350 < _diff || _diff < 10; })
143 #define NavQdrCloseTo(x) CloseDegAngles(((x) >> INT32_ANGLE_FRAC), NavCircleQdr())
144 #define NavCourseCloseTo(x) {}
151 #define Oval(a, b, c) nav_oval((b), (a), (c))
155 #define NavSegment(_start, _end) { \
156 horizontal_mode = HORIZONTAL_MODE_ROUTE; \
157 nav_route(&waypoints[_start].enu_i, &waypoints[_end].enu_i); \
161 #define NavGlide(_last_wp, _wp) { \
162 int32_t start_alt = waypoints[_last_wp].enu_i.z; \
163 int32_t diff_alt = waypoints[_wp].enu_i.z - start_alt; \
164 int32_t alt = start_alt + ((diff_alt * nav_leg_progress) / nav_leg_length); \
165 NavVerticalAltitudeMode(POS_FLOAT_OF_BFP(alt),0); \
170 #define NavApproaching(wp, time) nav_approaching_from(&waypoints[wp].enu_i, NULL, time)
171 #define NavApproachingFrom(wp, from, time) nav_approaching_from(&waypoints[wp].enu_i, &waypoints[from].enu_i, time)
175 #define NavCheckWaypointTime(wp, time) nav_check_wp_time(&waypoints[wp].enu_i, time)
179 #define NavVerticalAutoThrottleMode(_pitch) { \
180 nav_pitch = ANGLE_BFP_OF_REAL(_pitch); \
185 #define NavVerticalAutoPitchMode(_throttle) {}
189 #define NavVerticalAltitudeMode(_alt, _pre_climb) { \
190 vertical_mode = VERTICAL_MODE_ALT; \
191 nav_altitude = POS_BFP_OF_REAL(_alt); \
195 #define NavVerticalClimbMode(_climb) { \
196 vertical_mode = VERTICAL_MODE_CLIMB; \
197 nav_climb = SPEED_BFP_OF_REAL(_climb); \
201 #define NavVerticalThrottleMode(_throttle) { \
202 vertical_mode = VERTICAL_MODE_MANUAL; \
203 nav_throttle = _throttle; \
207 #define NavHeading nav_set_heading_rad
209 #define NavAttitude(_roll) { \
210 horizontal_mode = HORIZONTAL_MODE_ATTITUDE; \
211 nav_roll = ANGLE_BFP_OF_REAL(_roll); \
214 #define NavSetManual nav_set_manual
216 #define NavStartDetectGround() ({ autopilot_detect_ground_once = true; false; })
217 #define NavDetectGround() nav_detect_ground()
219 #define nav_IncreaseShift(x) {}
221 #define nav_SetNavRadius(x) {}
224 #define navigation_SetFlightAltitude(x) { \
225 flight_altitude = x; \
226 nav_flight_altitude = POS_BFP_OF_REAL(flight_altitude - state.ned_origin_f.hmsl); \
230 #define GetPosX() (stateGetPositionEnu_f()->x)
231 #define GetPosY() (stateGetPositionEnu_f()->y)
233 #define GetPosAlt() (stateGetPositionEnu_f()->z+state.ned_origin_f.hmsl)
241 #define GetAltRef() (state.ned_origin_f.hmsl)
246 #define NavFollow(_ac_id, _distance, _height) \
247 nav_follow(_ac_id, _distance, _height);
uint8_t last_wp
Index of last waypoint.
struct EnuCoor_i nav_circle_center
bool nav_is_in_flight(void)
uint32_t nav_throttle
direct throttle from 0:MAX_PPRZ, used in VERTICAL_MODE_MANUAL
void nav_oval(uint8_t, uint8_t, float)
int32_t nav_flight_altitude
void compute_dist2_to_home(void)
Computes squared distance to the HOME waypoint potentially sets too_far_from_home.
void nav_home(void)
Home mode navigation (circle around HOME)
int32_t nav_heading
with INT32_ANGLE_FRAC
uint8_t nav_oval_count
Navigation along a figure O.
void nav_init(void)
Navigation Initialisation.
float get_dist2_to_waypoint(uint8_t wp_id)
Returns squared horizontal distance to given waypoint.
bool nav_set_heading_current(void)
Set heading to the current yaw angle.
float get_dist2_to_point(struct EnuCoor_i *p)
Returns squared horizontal distance to given point.
void navigation_update_wp_from_speed(uint8_t wp, struct Int16Vect3 speed_sp, int16_t heading_rate_sp)
struct EnuCoor_i nav_segment_start nav_segment_end
unit_t nav_reset_alt(void)
Reset the altitude reference to the current GPS alt.
bool nav_check_wp_time(struct EnuCoor_i *wp, uint16_t stay_time)
Check the time spent in a radius of 'ARRIVED_AT_WAYPOINT' around a wp.
void nav_follow(uint8_t _ac_id, uint32_t distance, uint32_t height)
void nav_circle(struct EnuCoor_i *wp_center, int32_t radius)
struct EnuCoor_i navigation_carrot
bool nav_set_heading_towards_waypoint(uint8_t wp)
Set heading in the direction of a waypoint.
bool nav_set_heading_rad(float rad)
Set nav_heading in radians.
Paparazzi fixed point math for geodetic calculations.
int32_t nav_circle_radius
bool nav_set_heading_deg(float deg)
Set nav_heading in degrees.
bool nav_detect_ground(void)
void set_exception_flag(uint8_t flag_num)
int32_t nav_pitch
with INT32_ANGLE_FRAC
struct EnuCoor_i navigation_target
vector in East North Up coordinates
float dist2_to_wp
squared distance to next waypoint
float flight_altitude
Dynamically adjustable, reset to nav_altitude when it is changing.
Common flight_plan functions shared between fixedwing and rotorcraft.
bool nav_set_heading_towards(float x, float y)
Set heading to point towards x,y position in local coordinates.
unit_t nav_reset_reference(void)
Reset the geographic reference to the current GPS fix.
void nav_set_manual(int32_t roll, int32_t pitch, int32_t yaw)
Set manual roll, pitch and yaw without stabilization.
float failsafe_mode_dist2
maximum squared distance to home wp before going to failsafe mode
void nav_periodic_task(void)
Navigation main: call to the code generated from the XML flight plan.
bool nav_approaching_from(struct EnuCoor_i *wp, struct EnuCoor_i *from, int16_t approaching_time)
Proximity tests on approaching a wp.
int32_t nav_circle_radians
Status on the current circle.
void nav_route(struct EnuCoor_i *wp_start, struct EnuCoor_i *wp_end)
float dist2_to_home
squared distance to home waypoint