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; })
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);
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));
105 wp_td.x = wp_cd.x +
d_radius * cos(alpha);
106 wp_td.y = wp_cd.y +
d_radius * sin(alpha);
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)
168 float c = wind_x * wind_x + wind_y * wind_y - airspeed * airspeed;
171 float scal = wind_x * cos(alpha) + wind_y * sin(alpha);
172 float delta = 4 * (scal * scal - c);
174 Bound(
ground_speeds[i], NOMINAL_AIRSPEED / 4, 2 * NOMINAL_AIRSPEED);
181 nominal_radius = fabs(nominal_radius);
189 if (airspeed < NOMINAL_AIRSPEED / 2. ||
190 airspeed > 2.* NOMINAL_AIRSPEED) {
191 airspeed = NOMINAL_AIRSPEED;
203 float nominal_time = 0.;
206 float ground_speed = NOMINAL_AIRSPEED;
211 nominal_time += ANGLE_STEP * nominal_radius / ground_speed;
214 nominal_time -= (a - remaining_angle) * nominal_radius / ground_speed;
217 float radius = remaining_time / nominal_time * nominal_radius;
218 if (radius > 2. * nominal_radius) {
219 radius = nominal_radius;
231 return (remaining_time > 0);
bool_t snav_on_time(float nominal_radius)
void nav_circle_XY(float x, float y, float radius)
Navigates around (x, y).
static float stateGetAirspeed_f(void)
Get airspeed (float).
bool_t snav_circle1(void)
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)
uint32_t tow
GPS time of week in ms.
#define NavVerticalAltitudeMode(_alt, _pre_climb)
Set the vertical mode to altitude control with the specified altitude setpoint and climb pre-command...
Device independent GPS code (interface)
static void compute_ground_speed(float airspeed, float wind_x, float wind_y)
static uint8_t ground_speed_timer
#define NavVerticalAutoThrottleMode(_pitch)
Set the climb control to auto-throttle with the specified pitch pre-command.
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 float stateGetHorizontalSpeedDir_f(void)
Get dir of horizontal ground speed (float).
API to get/set the generic vehicle states.
static struct FloatVect2 * stateGetHorizontalWindspeed_f(void)
Get horizontal windspeed (float).
static struct point wp_cd wp_td wp_ca wp_ta
bool_t 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.
#define CARROT
default approaching_time for a wp
Smooth navigation to wp_a along an arc (around wp_cd), a segment (from wp_rd to wp_ta) and a second a...
static float ground_speeds[NB_ANGLES]
Fixedwing Navigation library.
static float ground_speed_of_course(float x)
struct GpsState gps
global GPS state
bool_t snav_init(uint8_t a, float desired_course_rad, float radius)
bool_t snav_circle2(void)