30 #include "generated/airframe.h"
36 #define Sign(_x) ((_x) > 0 ? 1 : (-1))
37 #define Norm2Pi(x) ({ uint8_t _i=1; float _x = x; while (_i && _x < 0.) { _i++;_x += 2*M_PI; } while (_i && _x > 2*M_PI) { _i++; _x -= 2*M_PI; } _x; })
39 static struct point wp_cd, wp_td, wp_ca,
wp_ta;
52 radius = fabs(radius);
66 float desired_u_x = cos(M_PI_2 - desired_course_rad);
67 float desired_u_y = sin(M_PI_2 - desired_course_rad);
68 a_radius =
Sign(desired_u_x * da_y - desired_u_y * da_x) * radius;
76 u_x = wp_ca.x - wp_cd.x;
77 u_y = wp_ca.y - wp_cd.y;
78 float cd_ca = sqrt(u_x * u_x + u_y * u_y);
85 u_x = wp_ca.x - wp_cd.x;
86 u_y = wp_ca.y - wp_cd.y;
87 cd_ca = sqrt(u_x * u_x + u_y * u_y);
104 float alpha = atan2(u_y, u_x) + acos(
d_radius / (cd_ca / 2));
111 qdr_td = M_PI_2 - atan2(wp_td.y - wp_cd.y, wp_td.x - wp_cd.x);
151 #define ANGLE_STEP (2.*M_PI/NB_ANGLES)
169 float c = wind_north * wind_north + wind_east * wind_east - airspeed * airspeed;
172 float scal = wind_east * cos(
alpha) + wind_north * sin(
alpha);
173 float delta = 4 * (scal * scal - c);
177 Bound(
ground_speeds[i], NOMINAL_AIRSPEED / 4, 2 * NOMINAL_AIRSPEED);
185 nominal_radius = fabs(nominal_radius);
193 if (airspeed < NOMINAL_AIRSPEED / 2. ||
194 airspeed > 2.* NOMINAL_AIRSPEED) {
195 airspeed = NOMINAL_AIRSPEED;
209 float nominal_time = 0.;
220 nominal_time -= (
a - remaining_angle) * nominal_radius /
ground_speed;
223 float radius = remaining_time / nominal_time * nominal_radius;
224 if (radius > 2. * nominal_radius) {
225 radius = nominal_radius;
237 return (remaining_time > 0);
#define WaypointAlt(_wp)
waypoint altitude in m above MSL
static float ground_speed
struct GpsState gps
global GPS state
Device independent GPS code (interface)
uint32_t tow
GPS time of week in ms.
static struct EnuCoor_f * stateGetPositionEnu_f(void)
Get position in local ENU coordinates (float).
static float stateGetHorizontalSpeedDir_f(void)
Get dir of horizontal ground speed (float).
static float stateGetAirspeed_f(void)
Get airspeed (float).
static struct FloatVect2 * stateGetHorizontalWindspeed_f(void)
Get horizontal windspeed (float).
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 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.
void nav_circle_XY(float x, float y, float radius)
Navigates around (x, y).
Fixedwing Navigation library.
#define NavQdrCloseTo(x)
True if x (in degrees) is close to the current QDR (less than 10 degrees)
#define NavVerticalAltitudeMode(_alt, _pre_climb)
Set the vertical mode to altitude control with the specified altitude setpoint and climb pre-command.
#define NavVerticalAutoThrottleMode(_pitch)
Set the climb control to auto-throttle with the specified pitch pre-command.
bool snav_init(uint8_t a, float desired_course_rad, float radius)
static float ground_speeds[NB_ANGLES]
bool snav_on_time(float nominal_radius)
static struct point wp_cd wp_td wp_ca wp_ta
static uint8_t ground_speed_timer
static float ground_speed_of_course(float x)
static bool compute_ground_speed(float airspeed, float wind_east, float wind_north)
Smooth navigation to wp_a along an arc (around wp_cd), a segment (from wp_rd to wp_ta) and a second a...
#define CARROT
default approaching_time for a wp
API to get/set the generic vehicle states.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.