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) {}
int32_t psi
in rad with INT32_ANGLE_FRAC
#define LINE_STOP_FUNCTION
void nav_set_heading_towards_target(void)
Set heading in the direction of the target.
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
#define VERTICAL_MODE_ALT
Rotorcraft navigation functions.
float failsafe_mode_dist2
maximum squared distance to home wp before going to failsafe mode
void nav_set_heading_towards_waypoint(uint8_t wp)
Set heading in the direction of a waypoint.
#define INT32_DEG_OF_RAD(_rad)
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
#define FAILSAFE_MODE_DISTANCE
Maximum distance from HOME waypoint before going into failsafe mode.
Periodic telemetry system header (includes downlink utility and generated code).
#define DEFAULT_CIRCLE_RADIUS
default nav_circle_radius in meters
#define CLOSE_TO_WAYPOINT
#define VECT2_SUM(_c, _a, _b)
#define VECT2_STRIM(_v, _min, _max)
vector in East North Up coordinates Units: meters
void nav_set_heading_current(void)
Set heading to the current yaw angle.
void nav_route(struct EnuCoor_i *wp_start, struct EnuCoor_i *wp_end)
#define POS_BFP_OF_REAL(_af)
float dist2_to_home
squared distance to home waypoint
#define VECT3_COPY(_a, _b)
void nav_follow(uint8_t _ac_id, uint32_t distance, uint32_t height)
uint16_t flight_time
flight time in seconds
#define VECT2_COPY(_a, _b)
#define VECT2_DIFF(_c, _a, _b)
Integrated Navigation System interface.
#define INT32_VECT3_RSHIFT(_o, _i, _r)
const float max_dist2_from_home
void nav_oval(uint8_t p1, uint8_t p2, float radius)
Navigation along a figure O.
#define VECT2_ASSIGN(_a, _x, _y)
void nav_circle(struct EnuCoor_i *wp_center, int32_t radius)
void nav_set_manual(int32_t roll, int32_t pitch, int32_t yaw)
Set manual roll, pitch and yaw without stabilization.
bool autopilot_set_mode(uint8_t new_autopilot_mode)
set autopilot mode
const float max_dist_from_home
#define HORIZONTAL_MODE_CIRCLE
struct EnuCoor_i navigation_target
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)
uint8_t last_wp
Index of last waypoint.
void ins_reset_local_origin(void)
INS local origin reset.
void nav_set_heading_towards(float x, float y)
Set heading to point towards x,y position in local coordinates.
struct EnuCoor_i navigation_carrot
struct pprz_autopilot autopilot
Global autopilot structure.
void nav_home(void)
Home mode navigation.
#define PPRZ_ITRIG_SIN(_s, _a)
int32_t nav_circle_radius
struct EnuCoor_i nav_circle_center
bool nav_detect_ground(void)
static float float_vect2_norm(struct FloatVect2 *v)
int32_t nav_pitch
with INT32_ANGLE_FRAC
static void send_wp_moved(struct transport_tx *trans, struct link_device *dev)
bool autopilot_in_flight(void)
get in_flight flag
bool nav_approaching_from(struct EnuCoor_i *wp, struct EnuCoor_i *from, int16_t approaching_time)
Proximity tests on approaching a wp.
void nav_init(void)
Navigation Initialisation.
int32_t nav_circle_radians
Status on the current circle.
Device independent GPS code (interface)
float flight_altitude
Dynamically adjustable, reset to nav_altitude when it is changing.
void compute_dist2_to_home(void)
Computes squared distance to the HOME waypoint potentially sets too_far_from_home.
#define INT32_ANGLE_NORMALIZE(_a)
float get_dist2_to_point(struct EnuCoor_i *p)
Returns squared horizontal distance to given point.
#define VECT3_SDIV(_vo, _vi, _s)
uint32_t int32_sqrt(uint32_t in)
#define DefaultPeriodic
Set default periodic telemetry.
#define HORIZONTAL_MODE_ROUTE
void nav_set_failsafe(void)
void nav_reset_reference(void)
Reset the geographic reference to the current GPS fix.
static void nav_set_altitude(void)
#define VECT2_SMUL(_vo, _vi, _s)
const uint8_t nb_waypoint
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 nav_set_heading_rad(float rad)
Set nav_heading in radians.
#define ANGLE_BFP_OF_REAL(_af)
static const struct usb_device_descriptor dev
void nav_periodic_task(void)
Navigation main: call to the code generated from the XML flight plan.
bool nav_is_in_flight(void)
Core autopilot interface common to all firmwares.
static void send_segment(struct transport_tx *trans, struct link_device *dev)
#define VECT2_SDIV(_vo, _vi, _s)
#define LINE_START_FUNCTION
#define INT_VECT3_ZERO(_v)
uint32_t nav_throttle
direct throttle from 0:MAX_PPRZ, used in VERTICAL_MODE_MANUAL
vector in East North Up coordinates
API to get/set the generic vehicle states.
int32_t int32_atan2_2(int32_t y, int32_t x)
static void send_nav_status(struct transport_tx *trans, struct link_device *dev)
#define NAV_DESCEND_VSPEED
#define ARRIVED_AT_WAYPOINT
minimum horizontal distance to waypoint to mark as arrived
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
#define INT32_COURSE_NORMALIZE(_a)
uint8_t nav_oval_count
Navigation along a figure O.
#define HORIZONTAL_MODE_MANUAL
Common code for AP and FBW telemetry.
#define CARROT
default approaching_time for a wp
#define POS_FLOAT_OF_BFP(_ai)
float get_dist2_to_waypoint(uint8_t wp_id)
Returns squared horizontal distance to given waypoint.
int32_t nav_flight_altitude
static struct EnuCoor_i * stateGetPositionEnu_i(void)
Get position in local ENU coordinates (int).
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_set_heading_deg(float deg)
Set nav_heading in degrees.
int32_t nav_heading
with INT32_ANGLE_FRAC
struct EnuCoor_i nav_last_point
void set_exception_flag(uint8_t flag_num)
void nav_init_stage(void)
needs to be implemented by fixedwing and rotorcraft seperately
static void UNUSED nav_advance_carrot(void)
void ins_reset_altitude_ref(void)
INS altitude reference reset.
static void send_circle(struct transport_tx *trans, struct link_device *dev)
float dist2_to_wp
squared distance to next waypoint
void waypoints_init(void)
initialize global and local waypoints
int8_t register_periodic_telemetry(struct periodic_telemetry *_pt, uint8_t _id, telemetry_cb _cb)
Register a telemetry callback function.
#define HORIZONTAL_MODE_WAYPOINT
#define PPRZ_ITRIG_COS(_c, _a)
int32_t int32_atan2(int32_t y, int32_t x)
Paparazzi fixed point algebra.