38 #include "generated/airframe.h"
41 #ifndef DEFAULT_CIRCLE_RADIUS
42 #define DEFAULT_CIRCLE_RADIUS 5.f
45 #ifndef NAV_CLIMB_VSPEED
46 #define NAV_CLIMB_VSPEED 0.5f
49 #ifndef NAV_DESCEND_VSPEED
50 #define NAV_DESCEND_VSPEED -0.8f
54 #ifndef ARRIVED_AT_WAYPOINT
55 #define ARRIVED_AT_WAYPOINT 3.0f
59 #ifndef FAILSAFE_MODE_DISTANCE
60 #define FAILSAFE_MODE_DISTANCE (1.2*MAX_DIST_FROM_HOME)
64 #ifndef NAV_CARROT_DIST
65 #define NAV_CARROT_DIST 12
74 #ifndef NAVIGATION_FREQUENCY
75 #if PERIODIC_FREQUENCY == 512
76 #define NAVIGATION_FREQUENCY 16
78 #define NAVIGATION_FREQUENCY 20
85 #define NAV_HORIZONTAL_MODE_WAYPOINT 0
86 #define NAV_HORIZONTAL_MODE_ROUTE 1
87 #define NAV_HORIZONTAL_MODE_CIRCLE 2
88 #define NAV_HORIZONTAL_MODE_ATTITUDE 3
89 #define NAV_HORIZONTAL_MODE_NONE 4
90 #define NAV_HORIZONTAL_MODE_GUIDED 5
92 #define NAV_VERTICAL_MODE_MANUAL 0
93 #define NAV_VERTICAL_MODE_CLIMB 1
94 #define NAV_VERTICAL_MODE_ALT 2
95 #define NAV_VERTICAL_MODE_GUIDED 3
100 #define NAV_SETPOINT_MODE_POS 0
101 #define NAV_SETPOINT_MODE_SPEED 1
102 #define NAV_SETPOINT_MODE_ACCEL 2
103 #define NAV_SETPOINT_MODE_ATTITUDE 3
104 #define NAV_SETPOINT_MODE_QUAT 4
105 #define NAV_SETPOINT_MODE_RATE 5
106 #define NAV_SETPOINT_MODE_MANUAL 6
179 #define GetPosX() (stateGetPositionEnu_f()->x)
181 #define GetPosY() (stateGetPositionEnu_f()->y)
183 #define GetPosAlt() (stateGetPositionEnu_f()->z+state.ned_origin_f.hmsl)
185 #define GetPosHeight() (stateGetPositionEnu_f()->z)
192 #define GetAltRef() (state.ned_origin_f.hmsl)
225 #define NavStartDetectGround() ({ autopilot.detect_ground_once = true; false; })
226 #define NavDetectGround() nav_detect_ground()
239 #define NavSetFailsafe nav_set_failsafe
241 #define NavSetGroundReferenceHere nav_reset_reference
242 #define NavSetAltitudeReferenceHere nav_reset_alt
244 #define NavSetWaypointHere waypoint_set_here_2d
245 #define NavCopyWaypoint waypoint_copy
246 #define NavCopyWaypointPositionOnly waypoint_position_copy
250 #define NavCheckWaypointTime(wp, time) nav_check_wp_time(&waypoints[wp].enu_f, time)
257 #define NavAttitude(_roll) { \
258 nav.horizontal_mode = NAV_HORIZONTAL_MODE_ATTITUDE; \
259 nav.setpoint_mode = NAV_SETPOINT_MODE_ATTITUDE; \
265 #define NavVerticalAutoThrottleMode(_pitch) { \
266 nav.pitch = _pitch; \
271 #define NavVerticalAltitudeMode(_alt, _pre_climb) { \
272 nav.vertical_mode = NAV_VERTICAL_MODE_ALT; \
273 nav.fp_altitude = _alt; \
277 #define NavVerticalClimbMode(_climb) { \
278 nav.vertical_mode = NAV_VERTICAL_MODE_CLIMB; \
279 nav.climb = _climb; \
280 nav.speed.z = _climb; \
284 #define NavVerticalThrottleMode(_throttle) { \
285 nav.vertical_mode = NAV_VERTICAL_MODE_MANUAL; \
286 nav.throttle = _throttle; \
290 #define NavHeading nav_set_heading_rad
293 #define NavSetMaxSpeed(_speed) { \
294 nav.fp_max_speed = _speed; \
315 if (_wp_start != NULL && _wp_end != NULL) {
333 if (_to != NULL && _from != NULL) {
343 if (_wp_center != NULL) {
359 if (_wp1 != NULL && _wp2 != NULL) {
371 if (_wp_start != NULL && _wp_end != NULL) {
380 #define nav_IncreaseShift(x) {}
381 #define nav_SetNavRadius(x) {}
382 #define navigation_SetFlightAltitude(x) { \
383 flight_altitude = x; \
384 nav.nav_altitude = flight_altitude - state.ned_origin_f.hmsl; \
390 #define NavVerticalAutoPitchMode(_throttle) {}
395 #define NavFollow(_i, _d, _h) {}
uint8_t autopilot_get_mode(void)
get autopilot mode
bool autopilot_set_motors_on(bool motors_on)
turn motors on/off, eventually depending of the current mode set kill_throttle accordingly FIXME is i...
Core autopilot interface common to all firmwares.
Common flight_plan functions shared between fixedwing and rotorcraft.
struct EnuCoor_f * waypoint_get_enu_f(uint8_t wp_id)
Get ENU coordinates (float)
void nav_oval(uint8_t p1, uint8_t p2, float radius)
static void nav_goto(struct EnuCoor_f *wp)
static void _nav_oval_init(void)
static void nav_route(struct EnuCoor_f *wp_start, struct EnuCoor_f *wp_end)
static void nav_circle(struct EnuCoor_f *wp_center, float radius)
static bool nav_approaching(struct EnuCoor_f *wp, struct EnuCoor_f *from, float approaching_time)
static void nav_stage_init(void)
Implement basic nav function.
Paparazzi floating point math for geodetic calculations.
vector in East North Up coordinates Units: meters
Paparazzi fixed point math for geodetic calculations.
struct EnuCoor_f speed
speed setpoint (in m/s)
static void NavGlide(uint8_t wp_start, uint8_t wp_end)
Nav glide routine.
void nav_home(void)
Home mode navigation (circle around HOME)
static void NavGotoWaypoint(uint8_t wp)
float flight_altitude
Dynamically adjustable, reset to nav_altitude when it is changing.
void nav_reset_reference(void)
Reset the geographic reference to the current GPS fix.
void nav_register_oval(navigation_oval_init _nav_oval_init, navigation_oval nav_oval)
struct FloatRates rates
rates setpoint (in rad/s)
void nav_set_heading_current(void)
Set heading to the current yaw angle.
float fp_max_speed
maximum speed setpoint from flight plan (in m/s), negative value means unset or invalid,...
uint32_t throttle
throttle command (in pprz_t)
void nav_reset_alt(void)
Reset the altitude reference to the current GPS alt.
float climb
climb setpoint (in m/s)
void nav_set_heading_towards_waypoint(uint8_t wp)
Set heading in the direction of a waypoint.
static void Oval(uint8_t wp1, uint8_t wp2, float radius)
void compute_dist2_to_home(void)
Computes squared distance to the HOME waypoint potentially sets too_far_from_home.
bool nav_is_in_flight(void)
void nav_set_heading_towards(float x, float y)
Set heading to point towards x,y position in local coordinates.
struct RotorcraftNavigation nav
float dist2_to_home
squared distance to home waypoint
void(* navigation_goto)(struct EnuCoor_f *wp)
bool(* navigation_approaching)(struct EnuCoor_f *wp_to, struct EnuCoor_f *wp_from, float approaching_time)
float failsafe_mode_dist2
maximum squared distance to home wp before going to failsafe mode
void(* navigation_oval)(struct EnuCoor_f *wp1, struct EnuCoor_f *wp2, float radius)
void nav_init(void)
Navigation Initialisation.
static bool NavApproachingFrom(uint8_t to, uint8_t from, float approaching_time)
void nav_parse_MOVE_WP(uint8_t *buf)
navigation_stage_init nav_stage_init
void nav_register_circle(navigation_circle nav_circle)
void nav_register_goto_wp(navigation_goto nav_goto, navigation_route nav_route, navigation_approaching nav_approaching)
Register functions.
navigation_approaching nav_approaching
struct FloatQuat quat
quaternion setpoint
void nav_parse_BLOCK(uint8_t *buf)
navigation_circle nav_circle
static void NavSegment(uint8_t wp_start, uint8_t wp_end)
void(* navigation_oval_init)(void)
struct EnuCoor_f accel
accel setpoint (in m/s)
void nav_set_heading_towards_target(void)
Set heading in the direction of the target.
static void nav_oval_init(void)
float nav_altitude
current altitude setpoint (in meters): might differ from fp_altitude depending on altitude shift from...
float radius
radius setpoint (in meters)
float descend_vspeed
descend speed setting, mostly used in flight plans
float get_dist2_to_point(struct EnuCoor_f *p)
Returns squared horizontal distance to given point.
navigation_oval_init nav_oval_init
void nav_register_stage_init(navigation_stage_init nav_stage_init)
Registering functions.
void(* navigation_route)(struct EnuCoor_f *wp_start, struct EnuCoor_f *wp_end)
float pitch
pitch angle (in radians)
void nav_glide_points(struct EnuCoor_f *start_point, struct EnuCoor_f *end_point)
void(* navigation_circle)(struct EnuCoor_f *wp_center, float radius)
float heading
heading setpoint (in radians)
struct EnuCoor_f carrot
carrot position (also used for GCS display)
static void NavKillThrottle(void)
void nav_set_heading_rad(float rad)
heading utility functions
static void NavResurrect(void)
bool nav_detect_ground(void)
void nav_set_heading_deg(float deg)
Set nav_heading in degrees.
navigation_route nav_route
static void NavCircleWaypoint(uint8_t wp_center, float radius)
bool nav_check_wp_time(struct EnuCoor_f *wp, uint16_t stay_time)
Check the time spent in a radius of 'ARRIVED_AT_WAYPOINT' around a wp
void nav_periodic_task(void)
Navigation main: call to the code generated from the XML flight plan.
float get_dist2_to_waypoint(uint8_t wp_id)
Returns squared horizontal distance to given waypoint.
float fp_altitude
altitude setpoint from flight plan (in meters)
void(* navigation_stage_init)(void)
struct EnuCoor_f target
final target position (in meters)
static bool NavApproaching(uint8_t wp, float approaching_time)
bool too_far_from_home
too_far flag
float climb_vspeed
climb speed setting, mostly used in flight plans
float roll
roll angle (in radians)
void nav_set_failsafe(void)
General Navigation structure.
API to get/set the generic vehicle states.
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.