39 #include "generated/modules.h"
40 #include "generated/flight_plan.h"
48 #include "pprzlink/messages.h"
54 #ifndef DEFAULT_CIRCLE_RADIUS
55 #define DEFAULT_CIRCLE_RADIUS 5.
58 #ifndef NAV_CLIMB_VSPEED
59 #define NAV_CLIMB_VSPEED 0.5
62 #ifndef NAV_DESCEND_VSPEED
63 #define NAV_DESCEND_VSPEED -0.8
67 #ifndef ARRIVED_AT_WAYPOINT
68 #define ARRIVED_AT_WAYPOINT 3.0
72 #ifndef FAILSAFE_MODE_DISTANCE
73 #define FAILSAFE_MODE_DISTANCE (1.5*MAX_DIST_FROM_HOME)
76 #define CLOSE_TO_WAYPOINT (15 << INT32_POS_FRAC)
77 #define CARROT_DIST (12 << INT32_POS_FRAC)
125 #if PERIODIC_TELEMETRY
139 pprz_msg_send_SEGMENT(trans, dev, AC_ID, &sx, &sy, &ex, &ey);
147 pprz_msg_send_CIRCLE(trans, dev, AC_ID, &cx, &cy, &r);
154 pprz_msg_send_ROTORCRAFT_NAV_STATUS(trans, dev, AC_ID,
156 &dist_home, &dist_wp,
171 pprz_msg_send_WP_MOVED_ENU(trans, dev, AC_ID,
212 #if PERIODIC_TELEMETRY
229 VECT2_STRIM(path_to_waypoint, -(1 << 15), (1 << 15));
238 VECT2_SDIV(path_to_carrot, path_to_carrot, dist_to_waypoint);
246 #if GUIDANCE_H_USE_REF
264 if (approaching_time > 0) {
268 VECT2_SMUL(estimated_progress, *speed, approaching_time);
270 VECT2_SUM(estimated_pos, *pos, estimated_progress);
295 return (diff_f.
x * from_diff_f.
x + diff_f.
y * from_diff_f.
y < 0);
306 static bool wp_reached =
false;
307 static struct EnuCoor_i wp_last = { 0, 0, 0 };
310 if ((wp_last.
x != wp->
x) || (wp_last.
y != wp->
y)) {
330 if (time_at_wp > stay_time) {
339 static int32_t last_nav_alt = 0;
461 return pos_diff.
x * pos_diff.
x + pos_diff.
y * pos_diff.
y;
477 #ifdef InGeofenceSector
504 float heading_f = atan2f(pos_diff.
x, pos_diff.
y);
563 int8_t sign_radius = radius > 0 ? 1 : -1;
565 int32_t abs_radius = abs(radius);
574 VECT2_ASSIGN(pos_diff, abs_radius * c_carrot, abs_radius * s_carrot);
586 struct Int32Vect2 wp_diff, pos_diff, wp_diff_prec;
593 uint32_t leg_length2 =
Max((wp_diff.
x * wp_diff.
x + wp_diff.
y * wp_diff.
y), 1);
604 nav_segment_start = *wp_start;
614 #ifndef LINE_START_FUNCTION
615 #define LINE_START_FUNCTION {}
617 #ifndef LINE_STOP_FUNCTION
618 #define LINE_STOP_FUNCTION {}
645 float d = sqrtf(p2_p1_x * p2_p1_x + p2_p1_y * p2_p1_y);
739 uint32_t __attribute__((unused)) height) {}
void nav_set_manual(int32_t roll, int32_t pitch, int32_t yaw)
Set manual roll, pitch and yaw without stabilization.
const float max_dist2_from_home
int32_t psi
in rad with INT32_ANGLE_FRAC
struct EnuCoor_i navigation_target
struct EnuCoor_i nav_last_point
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
void nav_reset_reference(void)
Reset the geographic reference to the current GPS fix.
#define FAILSAFE_MODE_DISTANCE
Maximum distance from HOME waypoint before going into failsafe mode.
#define INT32_DEG_OF_RAD(_rad)
Periodic telemetry system header (includes downlink utility and generated code).
void ins_reset_local_origin(void)
local implemetation of the ins_reset functions
void set_exception_flag(uint8_t flag_num)
#define VECT2_SUM(_c, _a, _b)
#define HORIZONTAL_MODE_MANUAL
#define VECT2_STRIM(_v, _min, _max)
vector in East North Up coordinates Units: meters
#define POS_BFP_OF_REAL(_af)
#define VECT3_COPY(_a, _b)
int32_t nav_flight_altitude
float flight_altitude
Dynamically adjustable, reset to nav_altitude when it is changing.
uint16_t flight_time
flight time in seconds
#define VECT2_COPY(_a, _b)
static void send_circle(struct transport_tx *trans, struct link_device *dev)
void nav_set_heading_towards_target(void)
Set heading in the direction of the target.
#define VECT2_DIFF(_c, _a, _b)
Integrated Navigation System interface.
void nav_home(void)
Home mode navigation.
#define INT32_VECT3_RSHIFT(_o, _i, _r)
#define DEFAULT_CIRCLE_RADIUS
default nav_circle_radius in meters
#define VECT2_ASSIGN(_a, _x, _y)
#define CLOSE_TO_WAYPOINT
uint8_t nav_oval_count
Navigation along a figure O.
void nav_set_heading_current(void)
Set heading to the current yaw angle.
bool autopilot_set_mode(uint8_t new_autopilot_mode)
set autopilot mode
#define HORIZONTAL_MODE_CIRCLE
float dist2_to_wp
squared distance to next waypoint
static uint32_t int32_vect2_norm(struct Int32Vect2 *v)
return norm of 2D vector
static struct EnuCoor_f * stateGetPositionEnu_f(void)
Get position in local ENU coordinates (float).
#define NavQdrCloseTo(x)
True if x (in degrees) is close to the current QDR (less than 10 degrees)
const float max_dist_from_home
struct EnuCoor_i nav_segment_start nav_segment_end
float dist2_to_home
squared distance to home waypoint
void nav_periodic_task(void)
Navigation main: call to the code generated from the XML flight plan.
struct pprz_autopilot autopilot
Global autopilot structure.
#define PPRZ_ITRIG_SIN(_s, _a)
static void nav_set_altitude(void)
static float float_vect2_norm(struct FloatVect2 *v)
bool autopilot_in_flight(void)
get in_flight flag
int32_t nav_heading
with INT32_ANGLE_FRAC
uint8_t last_wp
Index of last waypoint.
int32_t nav_pitch
with INT32_ANGLE_FRAC
Device independent GPS code (interface)
struct EnuCoor_i nav_circle_center
#define INT32_ANGLE_NORMALIZE(_a)
float get_dist2_to_point(struct EnuCoor_i *p)
Returns squared horizontal distance to given point.
bool nav_is_in_flight(void)
#define VECT3_SDIV(_vo, _vi, _s)
uint32_t int32_sqrt(uint32_t in)
#define DefaultPeriodic
Set default periodic telemetry.
void nav_set_heading_rad(float rad)
Set nav_heading in radians.
#define HORIZONTAL_MODE_ROUTE
bool nav_detect_ground(void)
float get_dist2_to_waypoint(uint8_t wp_id)
Returns squared horizontal distance to given waypoint.
static void send_segment(struct transport_tx *trans, struct link_device *dev)
void compute_dist2_to_home(void)
Computes squared distance to the HOME waypoint potentially sets too_far_from_home.
#define VECT2_SMUL(_vo, _vi, _s)
const uint8_t nb_waypoint
struct EnuCoor_i navigation_carrot
static void send_wp_moved(struct transport_tx *trans, struct link_device *dev)
#define ANGLE_BFP_OF_REAL(_af)
static const struct usb_device_descriptor dev
Core autopilot interface common to all firmwares.
#define VECT2_SDIV(_vo, _vi, _s)
Rotorcraft navigation functions.
static void UNUSED nav_advance_carrot(void)
#define INT_VECT3_ZERO(_v)
#define ARRIVED_AT_WAYPOINT
minimum horizontal distance to waypoint to mark as arrived
vector in East North Up coordinates
void nav_oval(uint8_t p1, uint8_t p2, float radius)
Navigation along a figure O.
API to get/set the generic vehicle states.
int32_t nav_circle_radius
int32_t int32_atan2_2(int32_t y, int32_t x)
#define LINE_STOP_FUNCTION
#define NAV_DESCEND_VSPEED
static struct EnuCoor_i * stateGetSpeedEnu_i(void)
Get ground speed in local ENU coordinates (int).
struct point waypoints[NB_WAYPOINT]
size == nb_waypoint, waypoint 0 is a dummy waypoint
void navigation_update_wp_from_speed(uint8_t wp, struct Int16Vect3 speed_sp, int16_t heading_rate_sp)
#define INT32_COURSE_NORMALIZE(_a)
void nav_circle(struct EnuCoor_i *wp_center, int32_t radius)
void nav_set_heading_deg(float deg)
Set nav_heading in degrees.
#define VERTICAL_MODE_ALT
Common code for AP and FBW telemetry.
void nav_set_heading_towards_waypoint(uint8_t wp)
Set heading in the direction of a waypoint.
uint32_t nav_throttle
direct throttle from 0:MAX_PPRZ, used in VERTICAL_MODE_MANUAL
int32_t nav_circle_radians
Status on the current circle.
#define POS_FLOAT_OF_BFP(_ai)
void nav_route(struct EnuCoor_i *wp_start, struct EnuCoor_i *wp_end)
float failsafe_mode_dist2
maximum squared distance to home wp before going to failsafe mode
static struct EnuCoor_i * stateGetPositionEnu_i(void)
Get position in local ENU coordinates (int).
#define LINE_START_FUNCTION
Horizontal guidance for rotorcrafts.
#define INT32_VECT2_RSHIFT(_o, _i, _r)
void waypoints_localize_all(void)
update local ENU coordinates of global waypoints
bool ground_detected
automatic detection of landing
static struct Int32Eulers * stateGetNedToBodyEulers_i(void)
Get vehicle body attitude euler angles (int).
void nav_init(void)
Navigation Initialisation.
void nav_set_failsafe(void)
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 ins_reset_altitude_ref(void)
INS altitude reference reset.
void nav_set_heading_towards(float x, float y)
Set heading to point towards x,y position in local coordinates.
bool nav_approaching_from(struct EnuCoor_i *wp, struct EnuCoor_i *from, int16_t approaching_time)
Proximity tests on approaching a wp.
void waypoints_init(void)
initialize global and local waypoints
static void send_nav_status(struct transport_tx *trans, struct link_device *dev)
int8_t register_periodic_telemetry(struct periodic_telemetry *_pt, uint8_t _id, telemetry_cb _cb)
Register a telemetry callback function.
void nav_follow(uint8_t _ac_id, uint32_t distance, uint32_t height)
#define HORIZONTAL_MODE_WAYPOINT
#define PPRZ_ITRIG_COS(_c, _a)
int32_t int32_atan2(int32_t y, int32_t x)
Paparazzi fixed point algebra.
#define CARROT
default approaching_time for a wp
void nav_init_stage(void)
needs to be implemented by fixedwing and rotorcraft seperately