51 #define HORIZONTAL_MODE_WAYPOINT 0
52 #define HORIZONTAL_MODE_ROUTE 1
53 #define HORIZONTAL_MODE_CIRCLE 2
54 #define HORIZONTAL_MODE_ATTITUDE 3
69 #define VERTICAL_MODE_MANUAL 0
70 #define VERTICAL_MODE_CLIMB 1
71 #define VERTICAL_MODE_ALT 2
104 #define NavKillThrottle() ({ if (autopilot_mode == AP_MODE_NAV) { autopilot_set_motors_on(FALSE); } FALSE; })
105 #define NavResurrect() ({ if (autopilot_mode == AP_MODE_NAV) { autopilot_set_motors_on(TRUE); } FALSE; })
108 #define NavSetGroundReferenceHere() ({ nav_reset_reference(); FALSE; })
109 #define NavSetAltitudeReferenceHere() ({ nav_reset_alt(); FALSE; })
111 #define NavSetWaypointHere(_wp) ({ waypoint_set_here_2d(_wp); FALSE; })
112 #define NavCopyWaypoint(_wp1, _wp2) ({ waypoint_copy(_wp1, _wp2); FALSE; })
113 #define NavCopyWaypointPositionOnly(_wp1, _wp2) ({ waypoint_position_copy(_wp1, _wp2); FALSE; })
116 #define NormCourse(x) { \
117 while (x < 0) x += 360; \
118 while (x >= 360) x -= 360; \
122 #define NavGotoWaypoint(_wp) { \
123 horizontal_mode = HORIZONTAL_MODE_WAYPOINT; \
124 VECT3_COPY(navigation_target, waypoints[_wp].enu_i); \
125 dist2_to_wp = get_dist2_to_waypoint(_wp); \
130 #define NavCircleWaypoint(_center, _radius) { \
131 horizontal_mode = HORIZONTAL_MODE_CIRCLE; \
132 nav_circle(&waypoints[_center].enu_i, POS_BFP_OF_REAL(_radius)); \
135 #define NavCircleCount() ((float)abs(nav_circle_radians) / INT32_ANGLE_2_PI)
136 #define NavCircleQdr() ({ int32_t qdr = INT32_DEG_OF_RAD(INT32_ANGLE_2_PI_2 - nav_circle_qdr) >> INT32_ANGLE_FRAC; NormCourse(qdr); qdr; })
139 #define NavQdrCloseTo(x) {}
140 #define NavCourseCloseTo(x) {}
144 #define NavSegment(_start, _end) { \
145 horizontal_mode = HORIZONTAL_MODE_ROUTE; \
146 nav_route(&waypoints[_start].enu_i, &waypoints[_end].enu_i); \
150 #define NavGlide(_last_wp, _wp) { \
151 int32_t start_alt = waypoints[_last_wp].enu_i.z; \
152 int32_t diff_alt = waypoints[_wp].enu_i.z - start_alt; \
153 int32_t alt = start_alt + ((diff_alt * nav_leg_progress) / nav_leg_length); \
154 NavVerticalAltitudeMode(POS_FLOAT_OF_BFP(alt),0); \
159 #define NavApproaching(wp, time) nav_approaching_from(&waypoints[wp].enu_i, NULL, time)
160 #define NavApproachingFrom(wp, from, time) nav_approaching_from(&waypoints[wp].enu_i, &waypoints[from].enu_i, time)
164 #define NavCheckWaypointTime(wp, time) nav_check_wp_time(&waypoints[wp].enu_i, time)
168 #define NavVerticalAutoThrottleMode(_pitch) { \
169 nav_pitch = ANGLE_BFP_OF_REAL(_pitch); \
174 #define NavVerticalAutoPitchMode(_throttle) {}
178 #define NavVerticalAltitudeMode(_alt, _pre_climb) { \
179 vertical_mode = VERTICAL_MODE_ALT; \
180 nav_altitude = POS_BFP_OF_REAL(_alt); \
184 #define NavVerticalClimbMode(_climb) { \
185 vertical_mode = VERTICAL_MODE_CLIMB; \
186 nav_climb = SPEED_BFP_OF_REAL(_climb); \
190 #define NavVerticalThrottleMode(_throttle) { \
191 vertical_mode = VERTICAL_MODE_MANUAL; \
192 nav_throttle = _throttle; \
196 #define NavHeading nav_set_heading_rad
198 #define NavAttitude(_roll) { \
199 horizontal_mode = HORIZONTAL_MODE_ATTITUDE; \
200 nav_roll = ANGLE_BFP_OF_REAL(_roll); \
203 #define NavStartDetectGround() ({ autopilot_detect_ground_once = TRUE; FALSE; })
204 #define NavDetectGround() nav_detect_ground()
206 #define nav_IncreaseShift(x) {}
208 #define nav_SetNavRadius(x) {}
211 #define navigation_SetFlightAltitude(x) { \
212 flight_altitude = x; \
213 nav_flight_altitude = POS_BFP_OF_REAL(flight_altitude - state.ned_origin_f.hmsl); \
217 #define GetPosX() (stateGetPositionEnu_f()->x)
218 #define GetPosY() (stateGetPositionEnu_f()->y)
219 #define GetPosAlt() (stateGetPositionEnu_f()->z+state.ned_origin_f.hmsl)
220 #define GetAltRef() (state.ned_origin_f.hmsl)
bool_t nav_set_heading_current(void)
Set heading to the current yaw angle.
bool_t exception_flag[10]
struct EnuCoor_i nav_circle_center
uint32_t nav_throttle
direct throttle from 0:MAX_PPRZ, used in VERTICAL_MODE_MANUAL
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
void nav_init(void)
Periodic telemetry.
float get_dist2_to_waypoint(uint8_t wp_id)
Returns squared horizontal distance to given waypoint.
float get_dist2_to_point(struct EnuCoor_i *p)
Returns squared horizontal distance to given point.
bool_t nav_set_heading_deg(float deg)
Set nav_heading in degrees.
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.
void nav_circle(struct EnuCoor_i *wp_center, int32_t radius)
bool_t nav_set_heading_rad(float rad)
Set nav_heading in degrees.
struct EnuCoor_i navigation_carrot
bool_t 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.
Paparazzi fixed point math for geodetic calculations.
bool_t nav_detect_ground(void)
int32_t nav_circle_radius
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.
bool_t nav_is_in_flight(void)
Common flight_plan functions shared between fixedwing and rotorcraft.
bool_t nav_set_heading_towards(float x, float y)
Set heading to point towards x,y position in local coordinates.
bool_t nav_approaching_from(struct EnuCoor_i *wp, struct EnuCoor_i *from, int16_t approaching_time)
Proximity tests on approaching a wp.
unit_t nav_reset_reference(void)
Reset the geographic reference to the current GPS fix.
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.
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
bool_t nav_set_heading_towards_waypoint(uint8_t wp)
Set heading in the direction of a waypoint.