32 #include "generated/flight_plan.h"
38 #ifndef POLY_OSAM_DEFAULT_SIZE
39 #define POLY_OSAM_DEFAULT_SIZE 5
42 #ifndef POLY_OSAM_DEFAULT_SWEEP
43 #define POLY_OSAM_DEFAULT_SWEEP 100
47 #ifndef POLY_OSAM_ENTRY_RADIUS
48 #define POLY_OSAM_ENTRY_RADIUS 0
52 #ifndef POLY_OSAM_MIN_RADIUS
53 #define POLY_OSAM_MIN_RADIUS 30
57 #ifndef POLY_OSAM_FIRST_SWEEP_DISTANCE
58 #define POLY_OSAM_FIRST_SWEEP_DISTANCE 0
62 #ifndef POLY_OSAM_POLYGONSIZE
63 #define POLY_OSAM_POLYGONSIZE 10
66 #ifndef POLY_OSAM_USE_FULL_CIRCLE
67 #define POLY_OSAM_USE_FULL_CIRCLE TRUE
71 #ifndef POLY_OSAM_HALF_SWEEP_ENABLED
72 #define POLY_OSAM_HALF_SWEEP_ENABLED TRUE
85 if (dx == 0.0f) { dx = 0.000000001; }
86 float ang = atan(dy / dx);
94 struct Line {
float m;
float b;
float x;};
109 #define PolygonSize POLY_OSAM_POLYGONSIZE
110 #define MaxFloat 1000000000
111 #define MinFloat -1000000000
113 #ifndef LINE_START_FUNCTION
114 #define LINE_START_FUNCTION {}
116 #ifndef LINE_STOP_FUNCTION
117 #define LINE_STOP_FUNCTION {}
152 static struct Point2D EntryPoint;
156 float XIntercept1 = 0;
157 float XIntercept2 = 0;
158 float entry_distance;
163 if (PolySurveyEntryDistance == 0) {
164 entry_distance = sw / 2;
166 entry_distance = PolySurveyEntryDistance;
169 if (PolySurveyEntryRadius == 0) {
192 if (Size <= PolygonSize && Orientation >= -90 && Orientation <= 90) {
194 for (i = 0; i < Size; i++) {
200 for (i = 0; i < Size; i++) {
207 for (i = 1; i < Size; i++) {
218 for (i = 0; i < Size; i++) {
223 EntryPoint.
x = Corners[0].
x;
224 EntryPoint.
y = Corners[0].
y;
228 for (i = 1; i < Size; i++) {
229 if (Corners[i].
y >
MaxY) {
235 for (i = 0; i < Size; i++) {
237 if (Corners[Size - 1].
x == Corners[i].
x) {
240 Edges[i].
m = ((Corners[Size - 1].
y - Corners[i].
y) / (Corners[Size - 1].
x - Corners[i].
x));
242 else if (Corners[i].
x == Corners[i - 1].
x) {
245 Edges[i].
m = ((Corners[i].
y - Corners[i - 1].
y) / (Corners[i].
x - Corners[i - 1].
x));
256 if (LeftYInt > RightYInt) {
264 for (i = 1; i < Size - 1; i++) {
268 if (LeftYInt > RightYInt) {
280 if (LeftYInt > RightYInt) {
289 if (EntryPoint.
y >=
MaxY / 2) {
290 entry_distance = -entry_distance;
305 ys = EntryPoint.
y + entry_distance;
310 XIntercept2 = XIntercept1;
316 if (fabs(EntryPoint.
x - XIntercept2) <= fabs(EntryPoint.
x - XIntercept1)) {
351 #ifdef NAV_SURVEY_POLY_OSAM_DYNAMIC
359 static struct Point2D LastPoint;
362 static bool HalfSweep =
false;
363 float XIntercept1 = 0;
364 float XIntercept2 = 0;
396 LastHalfSweep = HalfSweep;
411 float dist = FromP.
x - C.
x;
442 ys = LastPoint.
y + (
dSweep / 2);
452 ys = LastPoint.
y + (
dSweep / 2);
472 XIntercept2 = XIntercept1;
478 DInt1 = XIntercept1 - LastPoint.
x;
479 DInt2 = XIntercept2 - LastPoint.
x;
481 if (DInt1 * DInt2 >= 0) {
482 if (fabs(DInt2) <= fabs(DInt1)) {
525 if (fabs(temp) < min_radius) {
526 if (temp < 0) { temp = -min_radius; }
else { temp = min_radius; }
588 p->x =
p->x - transX;
589 p->y =
p->y - transY;
592 p->x =
p->x * cosf(Zrot) +
p->y * sinf(Zrot);
593 p->y = -temp * sinf(Zrot) +
p->y * cosf(Zrot);
601 p->x =
p->x * cosf(Zrot) -
p->y * sinf(Zrot);
602 p->y = temp * sinf(Zrot) +
p->y * cosf(Zrot);
604 p->x =
p->x + transX;
605 p->y =
p->y + transY;
610 *
x = ((L2.
b - L1.
b) / (L1.
m - L2.
m));
611 *
y = L1.
m * (*x) + L1.
b;
617 return ((
y - L.
b) / L.
m);
Core autopilot interface common to all firmwares.
struct point waypoints[NB_WAYPOINT]
size == nb_waypoint, waypoint 0 is a dummy waypoint
dc_autoshoot_type dc_autoshoot
Standard Digital Camera Control Interface.
static struct EnuCoor_f * stateGetPositionEnu_f(void)
Get position in local ENU coordinates (float).
static struct UtmCoor_f * stateGetPositionUtm_f(void)
Get position in UTM coordinates (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_init_stage(void)
needs to be implemented by fixedwing and rotorcraft seperately
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 NavCircleCountNoRewind()
#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.
#define POLY_OSAM_DEFAULT_SIZE
#define POLY_OSAM_DEFAULT_SWEEP
#define LINE_STOP_FUNCTION
static struct Line Edges[PolygonSize]
#define POLY_OSAM_FIRST_SWEEP_DISTANCE
if 0 default to half sweep
static struct Point2D SurveyCircle
void nav_survey_poly_osam_setup_towards(uint8_t FirstWP, uint8_t Size, float Sweep, int SecondWP)
Setup "dynamic" polygon survey with sweep orientation towards a waypoint.
#define POLY_OSAM_USE_FULL_CIRCLE
static float EvaluateLineForX(float y, struct Line L)
static uint8_t SurveySize
uint16_t PolySurveySweepNum
static void RotateAndTranslateToWorld(struct Point2D *p, float Zrot, float transX, float transY)
Rotates point round z by -Zrot then translates so (0,0) becomes (transX,transY)
static struct Point2D SmallestCorner
static void FindInterceptOfTwoLines(float *x, float *y, struct Line L1, struct Line L2)
#define LINE_START_FUNCTION
void nav_survey_poly_osam_setup(uint8_t EntryWP, uint8_t Size, float sw, float Orientation)
Setup polygon survey.
static float SurveyCircleQdr
static uint8_t SurveyEntryWP
static float SurveyRadius
uint16_t PolySurveySweepBackNum
#define POLY_OSAM_MIN_RADIUS
if 0 never check for min radius
#define POLY_OSAM_ENTRY_RADIUS
Default entry radius, if 0 default to half sweep.
#define POLY_OSAM_HALF_SWEEP_ENABLED
void nav_survey_poly_osam_ResetSweepNumber(bool rst)
Reset sweep number.
static void TranslateAndRotateFromWorld(struct Point2D *p, float Zrot, float transX, float transY)
static struct Point2D SurveyFromWP
static struct Point2D SurveyToWP
static float EdgeMinY[PolygonSize]
static float EdgeMaxY[PolygonSize]
bool nav_survey_poly_osam_run(void)
Run polygon survey.
static enum SurveyStatus CSurveyStatus
API to get/set the generic vehicle states.
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.