Paparazzi UAS v7.1_unstable
Paparazzi is a free software Unmanned Aircraft System.
Loading...
Searching...
No Matches
nav.c File Reference

Fixedwing functions to compute navigation. More...

#include <math.h>
#include "std.h"
#include "firmwares/fixedwing/nav.h"
#include "firmwares/fixedwing/stabilization/stabilization_attitude.h"
#include "autopilot.h"
#include "modules/gps/gps.h"
#include "generated/flight_plan.h"
#include "modules/nav/common_nav.c"
#include "modules/datalink/telemetry.h"
Include dependency graph for nav.c:

Go to the source code of this file.

Macros

#define NAV_C
#define NAV_GLIDE_PITCH_TRIM   0.
#define MIN_DX   ((int16_t)(MAX_PPRZ * 0.05))
#define MAX_DIST_CARROT   250.
#define MIN_HEIGHT_CARROT   50.
#define MAX_HEIGHT_CARROT   150.
#define Goto3D(radius)
#define LINE_START_FUNCTION   {}
#define LINE_STOP_FUNCTION   {}
#define FAILSAFE_HOME_RADIUS   DEFAULT_CIRCLE_RADIUS

Enumerations

enum  eight_status {
  R1T , RT2 , C2 , R2T ,
  RT1 , C1
}

Functions

void nav_init_stage (void)
 needs to be implemented by fixedwing and rotorcraft seperately
void nav_circle_XY (float x, float y, float radius)
 Navigates around (x, y).
void nav_glide (uint8_t start_wp, uint8_t wp)
void nav_glide_alt (float start_alt, float final_alt)
void nav_compute_baseleg (uint8_t wp_af, uint8_t wp_td, uint8_t wp_baseleg, float radius)
void nav_compute_final_from_glide (uint8_t wp_af, uint8_t wp_td, float glide)
static void compute_TOD (uint8_t _af, uint8_t _td, uint8_t _tod, float glide_airspeed, float glide_vspeed)
void nav_follow (uint8_t _ac_id, float distance, float height)
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.
void fly_to_xy (float x, float y)
 Computes desired_x, desired_y and desired_course.
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.
static void nav_set_altitude (void)
void nav_home (void)
 Home mode navigation (circle around HOME).
void nav_periodic_task (void)
 Navigation main: call to the code generated from the XML flight plan.
static void send_nav_ref (struct transport_tx *trans, struct link_device *dev)
 Periodic telemetry.
static void send_nav (struct transport_tx *trans, struct link_device *dev)
static void DownlinkSendWp (struct transport_tx *trans, struct link_device *dev, uint8_t _wp)
static void send_wp_moved (struct transport_tx *trans, struct link_device *dev)
void DownlinkSendWpNr (uint8_t _wp)
static void send_circle (struct transport_tx *trans, struct link_device *dev)
static void send_segment (struct transport_tx *trans, struct link_device *dev)
static void send_survey (struct transport_tx *trans, struct link_device *dev)
void nav_init (void)
 Navigation Initialisation.
void nav_without_gps (void)
 Failsafe navigation without position estimation.
void nav_parse_BLOCK (struct link_device *dev, struct transport_tx *trans, uint8_t *buf)
void nav_parse_MOVE_WP (struct link_device *dev, struct transport_tx *trans, uint8_t *buf)
void nav_eight_init (void)
void nav_eight (uint8_t target, uint8_t c1, float radius)
 Navigation along a figure 8.
void nav_oval_init (void)
void nav_oval (uint8_t p1, uint8_t p2, float radius)

Variables

static unit_t unit
enum oval_status oval_status
float last_x
float last_y
float rc_pitch
float carrot_x
float carrot_y
float nav_circle_radians
 Status on the current circle.
float nav_circle_radians_no_rewind
float nav_circle_trigo_qdr
float nav_radius
float nav_course
float nav_climb
float nav_shift
static float nav_leg_progress
 Status on the current leg (percentage, 0.
static float nav_carrot_leg_progress
static float nav_leg_length
 length of the current leg (m)
bool nav_in_circle = false
bool nav_in_segment = false
float nav_circle_x
float nav_circle_y
float nav_circle_radius
float nav_segment_x_1
float nav_segment_y_1
float nav_segment_x_2
float nav_segment_y_2
uint8_t horizontal_mode
float circle_bank = 0
float flight_altitude
 Dynamically adjustable, reset to nav_altitude when it is changing.
float nav_glide_pitch_trim
float nav_ground_speed_setpoint
float nav_ground_speed_pgain
float nav_survey_shift
float nav_survey_west
float nav_survey_east
float nav_survey_north
float nav_survey_south
bool nav_survey_active
int nav_mode
float baseleg_out_qdr
float nav_altitude = GROUND_ALT + MIN_HEIGHT_CARROT
float desired_x
float desired_y
pprz_t nav_throttle_setpoint
float nav_pitch
float fp_pitch
float fp_throttle
float fp_climb
static enum eight_status eight_status
uint8_t nav_oval_count
 Navigation along a figure O.

Detailed Description

Fixedwing functions to compute navigation.

Definition in file nav.c.

Macro Definition Documentation

◆ FAILSAFE_HOME_RADIUS

#define FAILSAFE_HOME_RADIUS   DEFAULT_CIRCLE_RADIUS

Definition at line 410 of file nav.c.

Referenced by nav_home().

◆ Goto3D

#define Goto3D ( radius)
Value:
{ \
if (yaw > MIN_DX || yaw < -MIN_DX) { \
carrot_x += FLOAT_OF_PPRZ(yaw, 0, -20.); \
} \
if (pitch > MIN_DX || pitch < -MIN_DX) { \
carrot_y += FLOAT_OF_PPRZ(pitch, 0, -20.); \
} \
if (roll > MIN_DX || roll < -MIN_DX) { \
nav_altitude += FLOAT_OF_PPRZ(roll, 0, -1.0); \
} \
} \
nav_circle_XY(carrot_x, carrot_y, radius); \
}
uint8_t autopilot_get_mode(void)
get autopilot mode
Definition autopilot.c:229
float ground_alt
size == nb_waypoint, waypoint 0 is a dummy waypoint
Definition common_nav.c:46
uint8_t v_ctl_mode
Definition energy_ctrl.c:74
#define Min(x, y)
Definition esc_dshot.c:110
#define AP_MODE_AUTO2
#define FLOAT_OF_PPRZ(pprz, center, travel)
pprz_t to float with saturation
#define V_CTL_MODE_AUTO_ALT
#define MIN_DX
Definition nav.c:104
float carrot_x
Definition nav.c:50
#define MAX_HEIGHT_CARROT
Definition nav.c:172
float carrot_y
Definition nav.c:50
float nav_altitude
Definition nav.c:307
#define MIN_HEIGHT_CARROT
Definition nav.c:171
#define MAX_DIST_CARROT
Definition nav.c:170
static pprz_t radio_control_get(uint8_t idx)
Get a radio control channel value.
short int16_t
Typedef defining 16 bit short type.

Definition at line 174 of file nav.c.

◆ LINE_START_FUNCTION

◆ LINE_STOP_FUNCTION

◆ MAX_DIST_CARROT

#define MAX_DIST_CARROT   250.

Definition at line 170 of file nav.c.

◆ MAX_HEIGHT_CARROT

#define MAX_HEIGHT_CARROT   150.

Definition at line 172 of file nav.c.

◆ MIN_DX

#define MIN_DX   ((int16_t)(MAX_PPRZ * 0.05))

Definition at line 104 of file nav.c.

◆ MIN_HEIGHT_CARROT

#define MIN_HEIGHT_CARROT   50.

Definition at line 171 of file nav.c.

◆ NAV_C

#define NAV_C

Definition at line 33 of file nav.c.

◆ NAV_GLIDE_PITCH_TRIM

#define NAV_GLIDE_PITCH_TRIM   0.

Definition at line 78 of file nav.c.

Referenced by nav_init().

Enumeration Type Documentation

◆ eight_status

Enumerator
R1T 
RT2 
C2 
R2T 
RT1 
C1 

Definition at line 617 of file nav.c.

Function Documentation

◆ compute_TOD()

void compute_TOD ( uint8_t _af,
uint8_t _td,
uint8_t _tod,
float glide_airspeed,
float glide_vspeed )
inlinestatic

Definition at line 261 of file nav.c.

References stateGetHorizontalWindspeed_f(), WaypointAlt, WaypointX, WaypointY, FloatVect2::x, and FloatVect2::y.

Here is the call graph for this function:

◆ DownlinkSendWp()

void DownlinkSendWp ( struct transport_tx * trans,
struct link_device * dev,
uint8_t _wp )
static

Definition at line 482 of file nav.c.

References dev, nav_utm_east0, nav_utm_north0, nav_utm_zone0, waypoints, EnuCoor_f::x, and EnuCoor_f::y.

Referenced by DownlinkSendWpNr(), and send_wp_moved().

Here is the caller graph for this function:

◆ DownlinkSendWpNr()

void DownlinkSendWpNr ( uint8_t _wp)

Definition at line 497 of file nav.c.

References DefaultChannel, DefaultDevice, DownlinkSendWp(), and nb_waypoint.

Referenced by nav_catapult_run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fly_to_xy()

void fly_to_xy ( float x,
float y )

◆ nav_approaching_xy()

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.

Computes dist2_to_wp and compare it to square carrot. Return true if it is smaller. Else computes by scalar products if uav has not gone past waypoint. approaching_time can be negative and in this case, the UAV will fly after the waypoint for the given number of seconds.

Returns
true if the position (x, y) is reached

distance to waypoint in x

distance to waypoint in y

Definition at line 325 of file nav.c.

References dist2_to_wp, stateGetHorizontalSpeedNorm_f(), stateGetPositionEnu_f(), EnuCoor_f::x, and EnuCoor_f::y.

Referenced by gvf_nav_approaching(), mission_nav_path(), mission_nav_segment(), mission_nav_wp(), nav_catapult_run(), nav_eight(), nav_gvf_survey_polygon_run(), nav_land_run(), nav_line_osam_run(), nav_oval(), nav_spiral_run(), nav_survey_disc_run(), nav_survey_poly_osam_run(), nav_survey_polygon_run(), nav_survey_zamboni_run(), nav_takeoff_run(), and snav_route().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ nav_circle_XY()

◆ nav_compute_baseleg()

void nav_compute_baseleg ( uint8_t wp_af,
uint8_t wp_td,
uint8_t wp_baseleg,
float radius )

Definition at line 220 of file nav.c.

References baseleg_out_qdr, nav_radius, and waypoints.

◆ nav_compute_final_from_glide()

void nav_compute_final_from_glide ( uint8_t wp_af,
uint8_t wp_td,
float glide )

Definition at line 241 of file nav.c.

References waypoints.

◆ nav_eight()

void nav_eight ( uint8_t target,
uint8_t c1,
float radius )

Navigation along a figure 8.

The cross center is defined by the waypoint [target], the center of one of the circles is defined by [c1]. Altitude is given by [target]. The navigation goes through 6 states: C1 (circle around [c1]), R1T, RT2 (route from circle 1 to circle 2 over [target]), C2 and R2T, RT1. If necessary, the [c1] waypoint is moved in the direction of [target] to be not far than [2*radius].

Definition at line 633 of file nav.c.

References UtmCoor_f::alt, C1, c1, C2, c2, CARROT, InitStage, nav_approaching_xy(), nav_circle_XY(), nav_route_xy(), NavCircleWaypoint, NavQdrCloseTo, R1T, R2T, RT1, RT2, target, waypoints, point::x, and point::y.

Here is the call graph for this function:

◆ nav_eight_init()

void nav_eight_init ( void )

Definition at line 620 of file nav.c.

References C1.

◆ nav_follow()

void nav_follow ( uint8_t _ac_id,
float distance,
float height )

Definition at line 302 of file nav.c.

◆ nav_glide()

void nav_glide ( uint8_t start_wp,
uint8_t wp )

Definition at line 158 of file nav.c.

References nav_glide_alt(), and waypoints.

Here is the call graph for this function:

◆ nav_glide_alt()

void nav_glide_alt ( float start_alt,
float final_alt )

Definition at line 163 of file nav.c.

References nav_leg_length, nav_leg_progress, NavVerticalAltitudeMode, and stateGetHorizontalSpeedNorm_f().

Referenced by nav_glide(), and nav_land_run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ nav_home()

void nav_home ( void )

Home mode navigation (circle around HOME).

Nominal speed

Definition at line 424 of file nav.c.

References autopilot, compute_dist2_to_home(), dist2_to_home, dist2_to_wp, FAILSAFE_HOME_RADIUS, ground_alt, nav_altitude, nav_pitch, nav_set_altitude(), NavCircleWaypoint, v_ctl_mode, V_CTL_MODE_AUTO_ALT, V_CTL_MODE_AUTO_THROTTLE, and v_ctl_throttle_setpoint.

Referenced by autopilot_static_periodic(), and navigation_task().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ nav_init()

◆ nav_init_stage()

◆ nav_oval()

void nav_oval ( uint8_t p1,
uint8_t p2,
float radius )

Definition at line 762 of file nav.c.

References CARROT, InitStage, LINE_START_FUNCTION, LINE_STOP_FUNCTION, nav_approaching_xy(), nav_circle_XY(), nav_oval_count, nav_route_xy(), NavQdrCloseTo, OC1, OC2, OR12, OR21, waypoints, point::x, and point::y.

Referenced by nav_register_oval(), nav_register_oval(), nav_rotorcraft_init(), and nav_rover_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ nav_oval_init()

void nav_oval_init ( void )

Definition at line 756 of file nav.c.

References nav_oval_count, and OC2.

Referenced by nav_register_oval().

Here is the caller graph for this function:

◆ nav_parse_BLOCK()

void nav_parse_BLOCK ( struct link_device * dev,
struct transport_tx * trans,
uint8_t * buf )

Definition at line 585 of file nav.c.

References dev, nav_goto_block(), and SEND_NAVIGATION.

Here is the call graph for this function:

◆ nav_parse_MOVE_WP()

void nav_parse_MOVE_WP ( struct link_device * dev,
struct transport_tx * trans,
uint8_t * buf )

◆ nav_periodic_task()

void nav_periodic_task ( void )

Navigation main: call to the code generated from the XML flight plan.

Definition at line 445 of file nav.c.

References circle_bank, compute_dist2_to_home(), dist2_to_wp, h_ctl_course_pre_bank, nav_in_circle, nav_set_altitude(), nav_survey_active, V_CTL_AUTO_THROTTLE_STANDARD, v_ctl_auto_throttle_submode, v_ctl_mode, and V_CTL_MODE_AUTO_CLIMB.

Referenced by autopilot_static_periodic(), and navigation_task().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ nav_route_xy()

◆ nav_set_altitude()

void nav_set_altitude ( void )
static

Definition at line 413 of file nav.c.

References flight_altitude, nav_altitude, and v_ctl_altitude_setpoint.

Referenced by nav_home(), and nav_periodic_task().

Here is the caller graph for this function:

◆ nav_without_gps()

void nav_without_gps ( void )

Failsafe navigation without position estimation.

Just set attitude and throttle to FAILSAFE values to prevent the plane from crashing.

Definition at line 569 of file nav.c.

References h_ctl_roll_setpoint, lateral_mode, LATERAL_MODE_ROLL, MAX_PPRZ, nav_pitch, nav_throttle_setpoint, TRIM_UPPRZ, v_ctl_mode, and V_CTL_MODE_AUTO_THROTTLE.

Referenced by navigation_task().

Here is the caller graph for this function:

◆ send_circle()

void send_circle ( struct transport_tx * trans,
struct link_device * dev )
static

Definition at line 504 of file nav.c.

References dev, nav_circle_radius, nav_circle_x, nav_circle_y, and nav_in_circle.

Referenced by nav_init(), send_nav_status(), and send_nav_status().

Here is the caller graph for this function:

◆ send_nav()

void send_nav ( struct transport_tx * trans,
struct link_device * dev )
static

Definition at line 477 of file nav.c.

References dev, and SEND_NAVIGATION.

Referenced by nav_init().

Here is the caller graph for this function:

◆ send_nav_ref()

void send_nav_ref ( struct transport_tx * trans,
struct link_device * dev )
static

Periodic telemetry.

Definition at line 471 of file nav.c.

References dev, ground_alt, nav_utm_east0, nav_utm_north0, and nav_utm_zone0.

Referenced by nav_init().

Here is the caller graph for this function:

◆ send_segment()

void send_segment ( struct transport_tx * trans,
struct link_device * dev )
static

Definition at line 512 of file nav.c.

References dev, nav_in_segment, nav_segment_x_1, nav_segment_x_2, nav_segment_y_1, and nav_segment_y_2.

Referenced by nav_init(), send_nav_status(), and send_nav_status().

Here is the caller graph for this function:

◆ send_survey()

void send_survey ( struct transport_tx * trans,
struct link_device * dev )
static

Definition at line 520 of file nav.c.

References dev, nav_survey_active, nav_survey_east, nav_survey_north, nav_survey_south, and nav_survey_west.

Referenced by nav_init(), and nav_survey_rectangle_rotorcraft_init().

Here is the caller graph for this function:

◆ send_wp_moved()

void send_wp_moved ( struct transport_tx * trans,
struct link_device * dev )
static

Definition at line 489 of file nav.c.

References dev, DownlinkSendWp(), and nb_waypoint.

Referenced by nav_init(), and waypoints_init().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ baseleg_out_qdr

float baseleg_out_qdr

Definition at line 219 of file nav.c.

Referenced by nav_compute_baseleg().

◆ carrot_x

float carrot_x

Definition at line 50 of file nav.c.

◆ carrot_y

float carrot_y

Definition at line 50 of file nav.c.

◆ circle_bank

float circle_bank = 0

Definition at line 71 of file nav.c.

Referenced by nav_circle_XY(), and nav_periodic_task().

◆ desired_x

float desired_x

◆ desired_y

float desired_y

◆ eight_status

Definition at line 619 of file nav.c.

◆ flight_altitude

float flight_altitude

Dynamically adjustable, reset to nav_altitude when it is changing.

Definition at line 74 of file nav.c.

Referenced by formation_flight(), nav_init(), nav_set_altitude(), and nav_set_altitude().

◆ fp_climb

float fp_climb

Definition at line 313 of file nav.c.

Referenced by nav_init().

◆ fp_pitch

float fp_pitch

Definition at line 311 of file nav.c.

Referenced by nav_init().

◆ fp_throttle

float fp_throttle

Definition at line 312 of file nav.c.

Referenced by nav_init().

◆ horizontal_mode

uint8_t horizontal_mode

Definition at line 70 of file nav.c.

Referenced by nav_circle_XY(), nav_route_xy(), and send_mode().

◆ last_x

float last_x

Definition at line 47 of file nav.c.

Referenced by nav_gvf_survey_polygon_run(), nav_init_stage(), and nav_survey_polygon_run().

◆ last_y

float last_y

Definition at line 47 of file nav.c.

Referenced by nav_gvf_survey_polygon_run(), nav_init_stage(), and nav_survey_polygon_run().

◆ nav_altitude

◆ nav_carrot_leg_progress

float nav_carrot_leg_progress
static

Definition at line 61 of file nav.c.

Referenced by nav_route_xy().

◆ nav_circle_radians

float nav_circle_radians

Status on the current circle.

Definition at line 53 of file nav.c.

Referenced by nav_circle_XY(), and nav_init_stage().

◆ nav_circle_radians_no_rewind

float nav_circle_radians_no_rewind

Definition at line 54 of file nav.c.

Referenced by nav_circle_XY(), and nav_init_stage().

◆ nav_circle_radius

float nav_circle_radius

Definition at line 68 of file nav.c.

Referenced by flight_benchmark_periodic(), nav_circle_XY(), and send_circle().

◆ nav_circle_trigo_qdr

float nav_circle_trigo_qdr

Definition at line 55 of file nav.c.

Referenced by nav_circle_XY(), and nav_land_run().

◆ nav_circle_x

float nav_circle_x

Definition at line 68 of file nav.c.

Referenced by flight_benchmark_periodic(), nav_circle_XY(), and send_circle().

◆ nav_circle_y

float nav_circle_y

Definition at line 68 of file nav.c.

Referenced by flight_benchmark_periodic(), nav_circle_XY(), and send_circle().

◆ nav_climb

float nav_climb

Definition at line 56 of file nav.c.

◆ nav_course

float nav_course

Definition at line 56 of file nav.c.

◆ nav_glide_pitch_trim

float nav_glide_pitch_trim

Definition at line 76 of file nav.c.

Referenced by nav_init().

◆ nav_ground_speed_pgain

float nav_ground_speed_pgain

Definition at line 83 of file nav.c.

Referenced by nav_init().

◆ nav_ground_speed_setpoint

float nav_ground_speed_setpoint

Definition at line 83 of file nav.c.

Referenced by nav_init().

◆ nav_in_circle

◆ nav_in_segment

◆ nav_leg_length

float nav_leg_length
static

length of the current leg (m)

Definition at line 64 of file nav.c.

Referenced by nav_glide_alt(), and nav_route_xy().

◆ nav_leg_progress

float nav_leg_progress
static

Status on the current leg (percentage, 0.

< < 1.) in route mode

Definition at line 60 of file nav.c.

Referenced by nav_glide_alt(), and nav_route_xy().

◆ nav_mode

int nav_mode

Definition at line 90 of file nav.c.

Referenced by fly_to_xy(), nav_circle_XY(), and nav_init().

◆ nav_oval_count

uint8_t nav_oval_count

Navigation along a figure O.

One side leg is defined by waypoints [p1] and [p2]. The navigation goes through 4 states: OC1 (half circle next to [p1]), OR21 (route [p2] to [p1], OC2 (half circle next to [p2]) and OR12 (opposite leg).

Initial state is the route along the desired segment (OC2).

Definition at line 754 of file nav.c.

Referenced by nav_oval(), and nav_oval_init().

◆ nav_pitch

◆ nav_radius

float nav_radius

Definition at line 56 of file nav.c.

Referenced by nav_compute_baseleg(), nav_flower_run(), nav_init(), and parachute_compute_approach().

◆ nav_segment_x_1

float nav_segment_x_1

Definition at line 69 of file nav.c.

Referenced by flight_benchmark_periodic(), nav_route_xy(), and send_segment().

◆ nav_segment_x_2

float nav_segment_x_2

Definition at line 69 of file nav.c.

Referenced by flight_benchmark_periodic(), nav_route_xy(), and send_segment().

◆ nav_segment_y_1

float nav_segment_y_1

Definition at line 69 of file nav.c.

Referenced by flight_benchmark_periodic(), nav_route_xy(), and send_segment().

◆ nav_segment_y_2

float nav_segment_y_2

Definition at line 69 of file nav.c.

Referenced by flight_benchmark_periodic(), nav_route_xy(), and send_segment().

◆ nav_shift

float nav_shift

Definition at line 56 of file nav.c.

Referenced by nav_circle_XY(), nav_init_stage(), and nav_route_xy().

◆ nav_survey_active

bool nav_survey_active

Definition at line 88 of file nav.c.

Referenced by nav_periodic_task(), nav_survey_rectangle(), and send_survey().

◆ nav_survey_east

◆ nav_survey_north

◆ nav_survey_shift

◆ nav_survey_south

◆ nav_survey_west

◆ nav_throttle_setpoint

pprz_t nav_throttle_setpoint

Definition at line 309 of file nav.c.

Referenced by attitude_loop(), nav_without_gps(), and v_ctl_guidance_loop().

◆ oval_status

Definition at line 45 of file nav.c.

◆ rc_pitch

float rc_pitch

Definition at line 49 of file nav.c.

◆ unit

unit_t unit
static

Definition at line 31 of file nav.c.