53 #define HORIZONTAL_MODE_WAYPOINT 0
54 #define HORIZONTAL_MODE_ROUTE 1
55 #define HORIZONTAL_MODE_CIRCLE 2
56 #define HORIZONTAL_MODE_ATTITUDE 3
57 #define HORIZONTAL_MODE_MANUAL 4
73 #define VERTICAL_MODE_MANUAL 0
74 #define VERTICAL_MODE_CLIMB 1
75 #define VERTICAL_MODE_ALT 2
91 #define GetPosX() (stateGetPositionEnu_f()->x)
92 #define GetPosY() (stateGetPositionEnu_f()->y)
94 #define GetPosAlt() (stateGetPositionEnu_f()->z+state.ned_origin_f.hmsl)
102 #define GetAltRef() (state.ned_origin_f.hmsl)
106 #define NormCourse(x) { \
107 while (x < 0) x += 360; \
108 while (x >= 360) x -= 360; \
138 #define NavStartDetectGround() ({ autopilot.detect_ground_once = true; false; })
139 #define NavDetectGround() nav_detect_ground()
152 #define NavSetManual nav_set_manual
153 #define NavSetFailsafe nav_set_failsafe
156 #define NavSetGroundReferenceHere nav_reset_reference
157 #define NavSetAltitudeReferenceHere nav_reset_alt
159 #define NavSetWaypointHere waypoint_set_here_2d
160 #define NavCopyWaypoint waypoint_copy
161 #define NavCopyWaypointPositionOnly waypoint_position_copy
166 #define NavApproaching(wp, time) nav_approaching_from(&waypoints[wp].enu_i, NULL, time)
167 #define NavApproachingFrom(wp, from, time) nav_approaching_from(&waypoints[wp].enu_i, &waypoints[from].enu_i, time)
171 #define NavCheckWaypointTime(wp, time) nav_check_wp_time(&waypoints[wp].enu_i, time)
197 #define NavVerticalAutoThrottleMode(_pitch) { \
198 nav_pitch = ANGLE_BFP_OF_REAL(_pitch); \
203 #define NavVerticalAutoPitchMode(_throttle) {}
207 #define NavVerticalAltitudeMode(_alt, _pre_climb) { \
208 vertical_mode = VERTICAL_MODE_ALT; \
209 nav_altitude = POS_BFP_OF_REAL(_alt); \
213 #define NavVerticalClimbMode(_climb) { \
214 vertical_mode = VERTICAL_MODE_CLIMB; \
215 nav_climb = SPEED_BFP_OF_REAL(_climb); \
219 #define NavVerticalThrottleMode(_throttle) { \
220 vertical_mode = VERTICAL_MODE_MANUAL; \
221 nav_throttle = _throttle; \
225 #define NavHeading nav_set_heading_rad
227 #define NavAttitude(_roll) { \
228 horizontal_mode = HORIZONTAL_MODE_ATTITUDE; \
229 nav_roll = ANGLE_BFP_OF_REAL(_roll); \
254 #define NavCircleCount() ((float)abs(nav_circle_radians) / INT32_ANGLE_2_PI)
255 #define NavCircleQdr() ({ int32_t qdr = INT32_DEG_OF_RAD(INT32_ANGLE_PI_2 - nav_circle_qdr) >> INT32_ANGLE_FRAC; NormCourse(qdr); qdr; })
257 #define CloseDegAngles(_c1, _c2) ({ int32_t _diff = _c1 - _c2; NormCourse(_diff); 350 < _diff || _diff < 10; })
258 #define CloseRadAngles(_c1, _c2) ({ float _diff = _c1 - _c2; NormRadAngle(_diff); fabsf(_diff) < 0.0177; })
260 #define NavQdrCloseTo(x) CloseDegAngles(((x) >> INT32_ANGLE_FRAC), NavCircleQdr())
261 #define NavCourseCloseTo(x) {}
267 #define Oval(a, b, c) nav_oval((b), (a), (c))
287 #define NavFollow nav_follow
295 #define nav_IncreaseShift(x) {}
296 #define nav_SetNavRadius(x) {}
297 #define navigation_SetFlightAltitude(x) { \
298 flight_altitude = x; \
299 nav_flight_altitude = POS_BFP_OF_REAL(flight_altitude - state.ned_origin_f.hmsl); \
void nav_set_heading_rad(float rad)
Set nav_heading in radians.
bool nav_detect_ground(void)
uint8_t last_wp
Index of last waypoint.
uint32_t nav_throttle
direct throttle from 0:MAX_PPRZ, used in VERTICAL_MODE_MANUAL
#define POS_BFP_OF_REAL(_af)
#define VECT3_COPY(_a, _b)
static void NavSegment(uint8_t wp_start, uint8_t wp_end)
int32_t nav_circle_radius
void nav_reset_reference(void)
Reset the geographic reference to the current GPS fix.
#define HORIZONTAL_MODE_CIRCLE
void nav_reset_alt(void)
Reset the altitude reference to the current GPS alt.
float dist2_to_wp
squared distance to next waypoint
void nav_circle(struct EnuCoor_i *wp_center, int32_t radius)
int32_t nav_flight_altitude
bool nav_approaching_from(struct EnuCoor_i *wp, struct EnuCoor_i *from, int16_t approaching_time)
Proximity tests on approaching a wp.
float flight_altitude
Dynamically adjustable, reset to nav_altitude when it is changing.
static void NavGlide(uint8_t start_wp, uint8_t wp)
Nav glide routine.
void compute_dist2_to_home(void)
Computes squared distance to the HOME waypoint potentially sets too_far_from_home.
void nav_route(struct EnuCoor_i *wp_start, struct EnuCoor_i *wp_end)
void nav_periodic_task(void)
Navigation main: call to the code generated from the XML flight plan.
bool nav_is_in_flight(void)
void nav_set_heading_current(void)
Set heading to the current yaw angle.
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.
#define HORIZONTAL_MODE_ROUTE
static void NavGotoWaypointHeading(uint8_t wp)
void nav_follow(uint8_t _ac_id, uint32_t distance, uint32_t height)
float get_dist2_to_point(struct EnuCoor_i *p)
Returns squared horizontal distance to given point.
static void NavKillThrottle(void)
static void NavResurrect(void)
void nav_oval(uint8_t, uint8_t, float)
Navigation along a figure O.
Paparazzi fixed point math for geodetic calculations.
uint8_t nav_oval_count
Navigation along a figure O.
void nav_set_heading_towards(float x, float y)
Set heading to point towards x,y position in local coordinates.
#define NavVerticalAltitudeMode(_alt, _pre_climb)
Set the vertical mode to altitude control with the specified altitude setpoint and climb pre-command...
void set_exception_flag(uint8_t flag_num)
Core autopilot interface common to all firmwares.
struct EnuCoor_i navigation_carrot
void nav_set_manual(int32_t roll, int32_t pitch, int32_t yaw)
Set manual roll, pitch and yaw without stabilization.
int32_t nav_circle_radians
Status on the current circle.
vector in East North Up coordinates
struct point waypoints[NB_WAYPOINT]
size == nb_waypoint, waypoint 0 is a dummy waypoint
void nav_home(void)
Home mode navigation (circle around HOME)
static void NavGotoWaypoint(uint8_t wp)
void autopilot_set_motors_on(bool motors_on)
turn motors on/off, eventually depending of the current mode set kill_throttle accordingly FIXME is i...
#define VERTICAL_MODE_ALT
Common flight_plan functions shared between fixedwing and rotorcraft.
void navigation_update_wp_from_speed(uint8_t wp, struct Int16Vect3 speed_sp, int16_t heading_rate_sp)
static void NavCircleWaypoint(uint8_t wp_center, float radius)
void nav_set_heading_deg(float deg)
Set nav_heading in degrees.
float dist2_to_home
squared distance to home waypoint
float failsafe_mode_dist2
maximum squared distance to home wp before going to failsafe mode
#define POS_FLOAT_OF_BFP(_ai)
#define HORIZONTAL_MODE_WAYPOINT
void nav_init(void)
Navigation Initialisation.
void nav_set_failsafe(void)
struct EnuCoor_i navigation_target
float get_dist2_to_waypoint(uint8_t wp_id)
Returns squared horizontal distance to given waypoint.
void nav_set_heading_towards_target(void)
Set heading in the direction of the target.
void nav_set_heading_towards_waypoint(uint8_t wp)
Set heading in the direction of a waypoint.
int32_t nav_heading
with INT32_ANGLE_FRAC
uint8_t autopilot_get_mode(void)
get autopilot mode
int32_t nav_pitch
with INT32_ANGLE_FRAC