31 #include "generated/flight_plan.h"
37 #ifndef POLYSURVEY_DEFAULT_SIZE
38 #define POLYSURVEY_DEFAULT_SIZE 10
41 #ifndef POLYSURVEY_DEFAULT_DISTANCE
42 #define POLYSURVEY_DEFAULT_DISTANCE 25
46 #ifndef POLYSURVEY_ENTRY_DISTANCE
47 #define POLYSURVEY_ENTRY_DISTANCE 0
51 #ifndef POLYSURVEY_MAX_POLYGONSIZE
52 #define POLYSURVEY_MAX_POLYGONSIZE 20
56 #ifndef POLY_OSAM_HALF_SWEEP_ENABLED
57 #define POLY_OSAM_HALF_SWEEP_ENABLED TRUE
68 if (dx == 0.0f) { dx = 0.000000001; }
69 float ang = atan(dy / dx);
79 struct Line {
float m;
float b;
float x;};
86 #define MaxPolygonSize POLYSURVEY_MAX_POLYGONSIZE
87 #define MaxFloat 1000000000
88 #define MinFloat -1000000000
90 #ifndef LINE_START_FUNCTION
91 #define LINE_START_FUNCTION {}
93 #ifndef LINE_STOP_FUNCTION
94 #define LINE_STOP_FUNCTION {}
134 float XIntercept1 = 0;
135 float XIntercept2 = 0;
136 float entry_distance;
140 if (PolySurveyEntryDistance == 0) {
141 entry_distance = sw / 2;
143 entry_distance = PolySurveyEntryDistance;
153 struct EnuCoor_f Corners[MaxPolygonSize];
162 if (Size <= MaxPolygonSize && Orientation >= -90 && Orientation <= 90) {
164 for (i = 0; i < Size; i++) {
170 for (i = 0; i < Size; i++) {
177 for (i = 1; i < Size; i++) {
188 for (i = 0; i < Size; i++) {
193 EntryPoint.
x = Corners[0].
x;
194 EntryPoint.
y = Corners[0].
y;
198 for (i = 1; i < Size; i++) {
199 if (Corners[i].
y >
MaxY) {
205 for (i = 0; i < Size; i++) {
207 if (Corners[Size - 1].
x == Corners[i].
x) {
210 Edges[i].
m = ((Corners[Size - 1].
y - Corners[i].
y) / (Corners[Size - 1].x - Corners[i].x));
212 else if (Corners[i].x == Corners[i - 1].x) {
215 Edges[i].
m = ((Corners[i].
y - Corners[i - 1].
y) / (Corners[i].x - Corners[i - 1].x));
226 if (LeftYInt > RightYInt) {
234 for (i = 1; i < Size - 1; i++) {
238 if (LeftYInt > RightYInt) {
250 if (LeftYInt > RightYInt) {
259 if (EntryPoint.
y >=
MaxY / 2) {
260 entry_distance = -entry_distance;
267 ys = EntryPoint.
y + entry_distance;
272 XIntercept2 = XIntercept1;
278 if (fabs(EntryPoint.
x - XIntercept2) <= fabs(EntryPoint.
x - XIntercept1)) {
297 CSurveyStatus =
Entry;
317 static bool HalfSweep =
false;
318 float XIntercept1 = 0;
319 float XIntercept2 = 0;
345 LastHalfSweep = HalfSweep;
367 float line_length = fabsf((fabsf(FromP.
x) - fabsf(ToP.
x)));
388 ys = LastPoint.
y + (
dSweep / 2);
400 XIntercept2 = XIntercept1;
406 DInt1 = XIntercept1 - LastPoint.
x;
407 DInt2 = XIntercept2 - LastPoint.
x;
409 if (DInt1 *DInt2 >= 0) {
410 if (fabs(DInt2) <= fabs(DInt1)) {
497 p->
x = p->
x - transX;
498 p->
y = p->
y - transY;
501 p->
x = p->
x * cosf(Zrot) + p->
y * sinf(Zrot);
502 p->
y = -temp * sinf(Zrot) + p->
y * cosf(Zrot);
510 p->
x = p->
x * cosf(Zrot) - p->
y * sinf(Zrot);
511 p->
y = temp * sinf(Zrot) + p->
y * cosf(Zrot);
513 p->
x = p->
x + transX;
514 p->
y = p->
y + transY;
519 *x = ((L2.
b - L1.
b) / (L1.
m - L2.
m));
520 *y = L1.
m * (*x) + L1.
b;
526 return ((y - L.
b) / L.
m);
#define POLYSURVEY_DEFAULT_SIZE
struct EnuCoor_i navigation_target
static struct EnuCoor_f SurveyToWP
#define LINE_STOP_FUNCTION
void nav_survey_poly_setup_towards(uint8_t FirstWP, uint8_t Size, float Sweep, int SecondWP)
Setup "dynamic" polygon survey with sweep orientation towards a waypoint.
vector in East North Up coordinates Units: meters
#define VECT3_COPY(_a, _b)
uint16_t PolySurveySweepBackNum
static struct EnuCoor_f SurveyEntry
static void RotateAndTranslateToWorld(struct EnuCoor_f *p, float Zrot, float transX, float transY)
Rotates point round z by -Zrot then translates so (0,0) becomes (transX,transY)
static float EvaluateLineForX(float y, struct Line L)
static struct EnuCoor_f * stateGetPositionEnu_f(void)
Get position in local ENU coordinates (float).
void nav_survey_poly_setup(uint8_t EntryWP, uint8_t Size, float sw, float Orientation)
Setup polygon survey.
static struct Line Edges[MaxPolygonSize]
Standard Digital Camera Control Interface.
bool nav_survey_poly_run(void)
Run polygon survey.
#define NavVerticalAltitudeMode(_alt, _pre_climb)
Set the vertical mode to altitude control with the specified altitude setpoint and climb pre-command...
static enum SurveyStatus CSurveyStatus
SurveyStatus
This routine will cover the enitre area of any Polygon defined in the flightplan which is a convex po...
static void TranslateAndRotateFromWorld(struct EnuCoor_f *p, float Zrot, float transX, float transY)
#define POLYSURVEY_DEFAULT_DISTANCE
#define POLY_OSAM_HALF_SWEEP_ENABLED
static float EdgeMinY[MaxPolygonSize]
#define HORIZONTAL_MODE_ROUTE
void nav_init_stage(void)
needs to be implemented by fixedwing and rotorcraft seperately
Core autopilot interface common to all firmwares.
Rotorcraft navigation functions.
void dc_send_command(uint8_t cmd)
Send Command To Camera.
#define POLYSURVEY_ENTRY_DISTANCE
if 0 default to half sweep
#define LINE_START_FUNCTION
vector in East North Up coordinates
static struct EnuCoor_i survey_from_i survey_to_i
static uint8_t SurveySize
API to get/set the generic vehicle states.
static uint8_t SurveyEntryWP
struct point waypoints[NB_WAYPOINT]
size == nb_waypoint, waypoint 0 is a dummy waypoint
void nav_set_heading_deg(float deg)
Set nav_heading in degrees.
#define ENU_BFP_OF_REAL(_o, _i)
void nav_route(struct EnuCoor_i *wp_start, struct EnuCoor_i *wp_end)
uint16_t PolySurveySweepNum
static void FindInterceptOfTwoLines(float *x, float *y, struct Line L1, struct Line L2)
float dc_distance_interval
AutoShoot photos on distance to last shot in meters.
static struct Point2D SmallestCorner
static float EdgeMaxY[MaxPolygonSize]
bool nav_approaching_from(struct EnuCoor_i *wp, struct EnuCoor_i *from, int16_t approaching_time)
Proximity tests on approaching a wp.
static struct EnuCoor_f SurveyFromWP