39 #include "generated/modules.h"
40 #include "generated/flight_plan.h"
48 #include "pprzlink/messages.h"
55 #ifndef DEFAULT_CIRCLE_RADIUS
56 #define DEFAULT_CIRCLE_RADIUS 5.
59 #ifndef NAV_CLIMB_VSPEED
60 #define NAV_CLIMB_VSPEED 0.5
63 #ifndef NAV_DESCEND_VSPEED
64 #define NAV_DESCEND_VSPEED -0.8
68 #ifndef ARRIVED_AT_WAYPOINT
69 #define ARRIVED_AT_WAYPOINT 3.0
73 #ifndef FAILSAFE_MODE_DISTANCE
74 #define FAILSAFE_MODE_DISTANCE (1.5*MAX_DIST_FROM_HOME)
77 #ifndef NAV_CARROT_DIST
78 #define NAV_CARROT_DIST 12
81 #define CLOSE_TO_WAYPOINT (15 << INT32_POS_FRAC)
82 #define CARROT_DIST ((int32_t) POS_BFP_OF_REAL(NAV_CARROT_DIST))
132 #if PERIODIC_TELEMETRY
146 pprz_msg_send_SEGMENT(trans,
dev, AC_ID, &sx, &sy, &ex, &ey);
154 pprz_msg_send_CIRCLE(trans,
dev, AC_ID, &cx, &cy, &r);
161 pprz_msg_send_ROTORCRAFT_NAV_STATUS(trans,
dev, AC_ID,
163 &dist_home, &dist_wp,
178 pprz_msg_send_WP_MOVED_ENU(trans,
dev, AC_ID,
222 #if PERIODIC_TELEMETRY
233 if (DL_BLOCK_ac_id(buf) != AC_ID) {
return; }
240 if (
ac_id != AC_ID) {
return; }
242 uint8_t wp_id = DL_MOVE_WP_wp_id(buf);
244 lla.
lat = DL_MOVE_WP_lat(buf);
245 lla.
lon = DL_MOVE_WP_lon(buf);
263 VECT2_STRIM(path_to_waypoint, -(1 << 15), (1 << 15));
272 VECT2_SDIV(path_to_carrot, path_to_carrot, dist_to_waypoint);
280 #if GUIDANCE_H_USE_REF
298 if (approaching_time > 0) {
302 VECT2_SMUL(estimated_progress, *speed, approaching_time);
304 VECT2_SUM(estimated_pos, *pos, estimated_progress);
329 return (diff_f.
x * from_diff_f.
x + diff_f.
y * from_diff_f.
y < 0);
340 static bool wp_reached =
false;
341 static struct EnuCoor_i wp_last = { 0, 0, 0 };
344 if ((wp_last.
x != wp->
x) || (wp_last.
y != wp->
y)) {
364 if (time_at_wp > stay_time) {
373 static int32_t last_nav_alt = 0;
487 #ifdef InGeofenceSector
573 int8_t sign_radius = radius > 0 ? 1 : -1;
575 int32_t abs_radius = abs(radius);
603 uint32_t leg_length2 = Max((wp_diff.
x * wp_diff.
x + wp_diff.
y * wp_diff.
y), 1);
614 nav_segment_start = *wp_start;
624 #ifndef LINE_START_FUNCTION
625 #define LINE_START_FUNCTION {}
627 #ifndef LINE_STOP_FUNCTION
628 #define LINE_STOP_FUNCTION {}
655 float d = sqrtf(p2_p1_x * p2_p1_x + p2_p1_y * p2_p1_y);
749 uint32_t __attribute__((unused)) height) {}
bool autopilot_set_mode(uint8_t new_autopilot_mode)
set autopilot mode
struct pprz_autopilot autopilot
Global autopilot structure.
bool autopilot_in_flight(void)
get in_flight flag
Core autopilot interface common to all firmwares.
bool ground_detected
automatic detection of landing
uint16_t flight_time
flight time in seconds
void nav_goto_block(uint8_t b)
struct point waypoints[NB_WAYPOINT]
size == nb_waypoint, waypoint 0 is a dummy waypoint
const uint8_t nb_waypoint
Common code for AP and FBW telemetry.
Device independent GPS code (interface)
static float float_vect2_norm(struct FloatVect2 *v)
#define FLOAT_VECT2_ZERO(_v)
#define VECT2_SMUL(_vo, _vi, _s)
#define VECT2_DIFF(_c, _a, _b)
#define VECT2_STRIM(_v, _min, _max)
#define VECT2_COPY(_a, _b)
#define VECT2_SUM(_c, _a, _b)
#define VECT2_SDIV(_vo, _vi, _s)
#define VECT3_COPY(_a, _b)
#define VECT2_ASSIGN(_a, _x, _y)
int32_t psi
in rad with INT32_ANGLE_FRAC
#define INT32_DEG_OF_RAD(_rad)
#define ANGLE_BFP_OF_REAL(_af)
uint32_t int32_sqrt(uint32_t in)
static uint32_t int32_vect2_norm(struct Int32Vect2 *v)
return norm of 2D vector
#define INT_VECT3_ZERO(_v)
#define POS_FLOAT_OF_BFP(_ai)
#define INT32_COURSE_NORMALIZE(_a)
#define INT32_VECT2_RSHIFT(_o, _i, _r)
#define POS_BFP_OF_REAL(_af)
#define INT32_ANGLE_NORMALIZE(_a)
int32_t lat
in degrees*1e7
int32_t hmsl
Height above mean sea level in mm.
int32_t alt
in millimeters above WGS84 reference ellipsoid
struct LlaCoor_i lla
Reference point in lla.
int32_t lon
in degrees*1e7
vector in East North Up coordinates
vector in Latitude, Longitude and Altitude
static struct Int32Eulers * stateGetNedToBodyEulers_i(void)
Get vehicle body attitude euler angles (int).
static struct EnuCoor_f * stateGetPositionEnu_f(void)
Get position in local ENU coordinates (float).
struct LtpDef_i ned_origin_i
Definition of the local (flat earth) coordinate system.
static bool stateIsLocalCoordinateValid(void)
Test if local coordinates are valid.
static struct EnuCoor_i * stateGetPositionEnu_i(void)
Get position in local ENU coordinates (int).
static struct EnuCoor_i * stateGetSpeedEnu_i(void)
Get ground speed in local ENU coordinates (int).
void WEAK ins_reset_local_origin(void)
INS local origin reset.
void WEAK ins_reset_altitude_ref(void)
INS altitude reference reset.
Integrated Navigation System interface.
void waypoints_localize_all(void)
update local ENU coordinates of global waypoints
void waypoints_init(void)
initialize global and local waypoints
void waypoint_move_lla(uint8_t wp_id, struct LlaCoor_i *lla)
#define HORIZONTAL_MODE_WAYPOINT
#define HORIZONTAL_MODE_CIRCLE
#define HORIZONTAL_MODE_ROUTE
#define NavQdrCloseTo(x)
True if x (in degrees) is close to the current QDR (less than 10 degrees)
#define NAVIGATION_FREQUENCY
Default fixedwing navigation frequency.
struct FloatVect2 pos_diff
Paparazzi fixed point algebra.
vector in East North Up coordinates Units: meters
int32_t int32_atan2(int32_t y, int32_t x)
int32_t int32_atan2_2(int32_t y, int32_t x)
#define PPRZ_ITRIG_SIN(_s, _a)
#define PPRZ_ITRIG_COS(_c, _a)
Horizontal guidance for rotorcrafts.
struct EnuCoor_i nav_last_point
void nav_home(void)
Home mode navigation.
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.
float dist2_to_wp
squared distance to next waypoint
void nav_set_heading_current(void)
Set heading to the current yaw angle.
static void send_nav_status(struct transport_tx *trans, struct link_device *dev)
void nav_init_stage(void)
needs to be implemented by fixedwing and rotorcraft seperately
#define LINE_STOP_FUNCTION
void nav_set_manual(int32_t roll, int32_t pitch, int32_t yaw)
Set manual roll, pitch and yaw without stabilization.
struct EnuCoor_i nav_circle_center
void nav_circle(struct EnuCoor_i *wp_center, int32_t radius)
struct EnuCoor_i navigation_carrot
const float max_dist_from_home
void nav_set_heading_towards_waypoint(uint8_t wp)
Set heading in the direction of a waypoint.
uint8_t nav_oval_count
Navigation along a figure O.
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 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.
#define NAV_DESCEND_VSPEED
int32_t nav_circle_radians
Status on the current circle.
struct EnuCoor_i nav_segment_start nav_segment_end
void nav_init(void)
Navigation Initialisation.
void nav_parse_MOVE_WP(uint8_t *buf)
int32_t nav_flight_altitude
void nav_follow(uint8_t _ac_id, uint32_t distance, uint32_t height)
struct FloatVect2 line_vect to_end_vect
uint32_t nav_throttle
direct throttle from 0:MAX_PPRZ, used in VERTICAL_MODE_MANUAL
float failsafe_mode_dist2
maximum squared distance to home wp before going to failsafe mode
#define DEFAULT_CIRCLE_RADIUS
default nav_circle_radius in meters
void nav_parse_BLOCK(uint8_t *buf)
struct EnuCoor_i navigation_target
static void send_circle(struct transport_tx *trans, struct link_device *dev)
#define LINE_START_FUNCTION
#define CLOSE_TO_WAYPOINT
float get_dist2_to_point(struct EnuCoor_i *p)
Returns squared horizontal distance to given point.
void nav_set_heading_towards_target(void)
Set heading in the direction of the target.
void nav_route(struct EnuCoor_i *wp_start, struct EnuCoor_i *wp_end)
int32_t nav_circle_radius
float dist2_to_home
squared distance to home waypoint
bool nav_approaching_from(struct EnuCoor_i *wp, struct EnuCoor_i *from, int16_t approaching_time)
Proximity tests on approaching a wp.
const float max_dist2_from_home
static void send_segment(struct transport_tx *trans, struct link_device *dev)
void nav_set_heading_rad(float rad)
Set nav_heading in radians.
bool nav_detect_ground(void)
void nav_set_heading_deg(float deg)
Set nav_heading in degrees.
int32_t nav_heading
with INT32_ANGLE_FRAC
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.
#define FAILSAFE_MODE_DISTANCE
Maximum distance from HOME waypoint before going into failsafe mode.
static void UNUSED nav_advance_carrot(void)
void nav_oval(uint8_t p1, uint8_t p2, float radius)
Navigation along a figure O.
static void send_wp_moved(struct transport_tx *trans, struct link_device *dev)
#define ARRIVED_AT_WAYPOINT
minimum horizontal distance to waypoint to mark as arrived
void set_exception_flag(uint8_t flag_num)
static void nav_set_altitude(void)
void nav_set_failsafe(void)
Rotorcraft navigation functions.
#define VERTICAL_MODE_ALT
#define HORIZONTAL_MODE_MANUAL
#define CARROT
default approaching_time for a wp
uint8_t last_wp
Index of last waypoint.
API to get/set the generic vehicle states.
static const struct usb_device_descriptor dev
int8_t register_periodic_telemetry(struct periodic_telemetry *_pt, uint8_t _id, telemetry_cb _cb)
Register a telemetry callback function.
Periodic telemetry system header (includes downlink utility and generated code).
#define DefaultPeriodic
Set default periodic telemetry.
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
int int32_t
Typedef defining 32 bit int type.
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
short int16_t
Typedef defining 16 bit short type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
signed char int8_t
Typedef defining 8 bit char type.