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);
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 {}
151 static struct Point2D EntryPoint;
155 float XIntercept1 = 0;
156 float XIntercept2 = 0;
157 float entry_distance;
162 if (PolySurveyEntryDistance == 0) {
163 entry_distance = sw / 2;
165 entry_distance = PolySurveyEntryDistance;
168 if (PolySurveyEntryRadius == 0) {
181 struct Point2D Corners[PolygonSize];
190 if (Size <= PolygonSize && Orientation >= -90 && Orientation <= 90) {
192 for (i = 0; i < Size; i++) {
198 for (i = 0; i < Size; i++) {
205 for (i = 1; i < Size; i++) {
216 for (i = 0; i < Size; i++) {
221 EntryPoint.
x = Corners[0].
x;
222 EntryPoint.
y = Corners[0].
y;
226 for (i = 1; i < Size; i++) {
227 if (Corners[i].
y >
MaxY) {
233 for (i = 0; i < Size; i++) {
235 if (Corners[Size - 1].
x == Corners[i].
x) {
238 Edges[i].
m = ((Corners[Size - 1].
y - Corners[i].
y) / (Corners[Size - 1].x - Corners[i].x));
240 else if (Corners[i].x == Corners[i - 1].x) {
243 Edges[i].
m = ((Corners[i].
y - Corners[i - 1].
y) / (Corners[i].x - Corners[i - 1].x));
254 if (LeftYInt > RightYInt) {
262 for (i = 1; i < Size - 1; i++) {
266 if (LeftYInt > RightYInt) {
278 if (LeftYInt > RightYInt) {
287 if (EntryPoint.
y >=
MaxY / 2) {
288 entry_distance = -entry_distance;
303 ys = EntryPoint.
y + entry_distance;
308 XIntercept2 = XIntercept1;
314 if (fabs(EntryPoint.
x - XIntercept2) <= fabs(EntryPoint.
x - XIntercept1)) {
342 CSurveyStatus =
Entry;
353 static struct Point2D LastPoint;
356 static bool HalfSweep =
false;
357 float XIntercept1 = 0;
358 float XIntercept2 = 0;
390 LastHalfSweep = HalfSweep;
405 float dist = FromP.
x - C.
x;
436 ys = LastPoint.
y + (
dSweep / 2);
446 ys = LastPoint.
y + (
dSweep / 2);
466 XIntercept2 = XIntercept1;
472 DInt1 = XIntercept1 - LastPoint.
x;
473 DInt2 = XIntercept2 - LastPoint.
x;
475 if (DInt1 * DInt2 >= 0) {
476 if (fabs(DInt2) <= fabs(DInt1)) {
519 if (fabs(temp) < min_radius) {
520 if (temp < 0) { temp = -min_radius; }
else { temp = min_radius; }
582 p->
x = p->
x - transX;
583 p->
y = p->
y - transY;
586 p->
x = p->
x * cosf(Zrot) + p->
y * sinf(Zrot);
587 p->
y = -temp * sinf(Zrot) + p->
y * cosf(Zrot);
595 p->
x = p->
x * cosf(Zrot) - p->
y * sinf(Zrot);
596 p->
y = temp * sinf(Zrot) + p->
y * cosf(Zrot);
598 p->
x = p->
x + transX;
599 p->
y = p->
y + transY;
604 *x = ((L2.
b - L1.
b) / (L1.
m - L2.
m));
605 *y = L1.
m * (*x) + L1.
b;
611 return ((y - L.
b) / L.
m);
static float EdgeMaxY[PolygonSize]
#define POLY_OSAM_HALF_SWEEP_ENABLED
#define LINE_START_FUNCTION
static float EdgeMinY[PolygonSize]
void nav_circle_XY(float x, float y, float radius)
Navigates around (x, y).
static float SurveyCircleQdr
static enum SurveyStatus CSurveyStatus
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)
void nav_survey_poly_osam_ResetSweepNumber(bool rst)
Reset sweep number.
Standard Digital Camera Control Interface.
#define POLY_OSAM_DEFAULT_SWEEP
#define NavVerticalAltitudeMode(_alt, _pre_climb)
Set the vertical mode to altitude control with the specified altitude setpoint and climb pre-command...
static void TranslateAndRotateFromWorld(struct Point2D *p, float Zrot, float transX, float transY)
SurveyStatus
This routine will cover the enitre area of any Polygon defined in the flightplan which is a convex po...
dc_autoshoot_type dc_autoshoot
uint16_t PolySurveySweepBackNum
static struct Point2D SurveyToWP
static struct Point2D SmallestCorner
uint16_t PolySurveySweepNum
#define NavCircleCountNoRewind()
#define NavVerticalAutoThrottleMode(_pitch)
Set the climb control to auto-throttle with the specified pitch pre-command.
static uint8_t SurveyEntryWP
static struct Line Edges[PolygonSize]
void nav_init_stage(void)
needs to be implemented by fixedwing and rotorcraft seperately
static void FindInterceptOfTwoLines(float *x, float *y, struct Line L1, struct Line L2)
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.
#define POLY_OSAM_MIN_RADIUS
if 0 never check for min radius
static float EvaluateLineForX(float y, struct Line L)
void nav_survey_poly_osam_setup(uint8_t EntryWP, uint8_t Size, float sw, float Orientation)
Setup polygon survey.
Core autopilot interface common to all firmwares.
static struct Point2D SurveyFromWP
static struct UtmCoor_f * stateGetPositionUtm_f(void)
Get position in UTM coordinates (float).
static uint8_t SurveySize
API to get/set the generic vehicle states.
struct point waypoints[NB_WAYPOINT]
size == nb_waypoint, waypoint 0 is a dummy waypoint
#define LINE_STOP_FUNCTION
static float SurveyRadius
#define POLY_OSAM_DEFAULT_SIZE
#define POLY_OSAM_FIRST_SWEEP_DISTANCE
if 0 default to half sweep
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.
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.
#define POLY_OSAM_USE_FULL_CIRCLE
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 SurveyCircle
Fixedwing Navigation library.
#define POLY_OSAM_ENTRY_RADIUS
Default entry radius, if 0 default to half sweep.
bool nav_survey_poly_osam_run(void)
Run polygon survey.