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
67 if (dx == 0.0f) { dx = 0.000000001; }
68 float ang = atan(dy / dx);
78struct Line {
float m;
float b;
float x;};
85#define MaxPolygonSize POLYSURVEY_MAX_POLYGONSIZE
86#define MaxFloat 1000000000
87#define MinFloat -1000000000
89#ifndef LINE_START_FUNCTION
90#define LINE_START_FUNCTION {}
92#ifndef LINE_STOP_FUNCTION
93#define LINE_STOP_FUNCTION {}
133 float XIntercept1 = 0;
134 float XIntercept2 = 0;
135 float entry_distance;
139 if (PolySurveyEntryDistance == 0) {
140 entry_distance = sw / 2;
142 entry_distance = PolySurveyEntryDistance;
162 if (Size <= MaxPolygonSize && Orientation >= -90 && Orientation <= 90) {
164 for (i = 0; i < Size; i++) {
165 Corners[i].
x =
waypoints[i + EntryWP].enu_f.x;
166 Corners[i].
y =
waypoints[i + EntryWP].enu_f.y;
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));
219 Edges[i].b = (Corners[i].
y - (Corners[i].
x *
Edges[i].m));
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)) {
310 if (
nav.nav_goto == NULL ||
nav.nav_route == NULL ||
nav.nav_approaching == NULL) {
314 #ifdef NAV_SURVEY_POLY_DYNAMIC
325 static bool HalfSweep =
false;
326 float XIntercept1 = 0;
327 float XIntercept2 = 0;
352 LastHalfSweep = HalfSweep;
372 float line_length = fabsf((fabsf(FromP.
x) - fabsf(ToP.
x)));
393 ys = LastPoint.
y + (
dSweep / 2);
405 XIntercept2 = XIntercept1;
411 DInt1 = XIntercept1 - LastPoint.
x;
412 DInt2 = XIntercept2 - LastPoint.
x;
414 if (DInt1 *DInt2 >= 0) {
415 if (fabs(DInt2) <= fabs(DInt1)) {
500 p->x =
p->x - transX;
501 p->y =
p->y - transY;
504 p->x =
p->x * cosf(Zrot) +
p->y * sinf(Zrot);
505 p->y = -temp * sinf(Zrot) +
p->y * cosf(Zrot);
513 p->x =
p->x * cosf(Zrot) -
p->y * sinf(Zrot);
514 p->y = temp * sinf(Zrot) +
p->y * cosf(Zrot);
516 p->x =
p->x + transX;
517 p->y =
p->y + transY;
522 *
x = ((L2.
b - L1.
b) / (L1.
m - L2.
m));
523 *
y = L1.
m * (*x) + L1.
b;
529 return ((
y - L.
b) / L.
m);
void dc_send_command(uint8_t cmd)
Send Command To Camera.
Core autopilot interface common to all firmwares.
struct point waypoints[NB_WAYPOINT]
size == nb_waypoint, waypoint 0 is a dummy waypoint
float dc_distance_interval
AutoShoot photos on distance to last shot in meters.
Standard Digital Camera Control Interface.
#define VECT3_COPY(_a, _b)
static struct EnuCoor_f * stateGetPositionEnu_f(void)
Get position in local ENU coordinates (float).
void nav_init_stage(void)
needs to be implemented by fixedwing and rotorcraft seperately
#define LINE_STOP_FUNCTION
#define LINE_START_FUNCTION
#define NavVerticalAltitudeMode(_alt, _pre_climb)
Set the vertical mode to altitude control with the specified altitude setpoint and climb pre-command.
static struct Line Edges[PolygonSize]
static uint8_t SurveySize
uint16_t PolySurveySweepNum
static struct Point2D SmallestCorner
static uint8_t SurveyEntryWP
uint16_t PolySurveySweepBackNum
#define POLY_OSAM_HALF_SWEEP_ENABLED
static struct Point2D SurveyFromWP
static struct Point2D SurveyToWP
static float EdgeMinY[PolygonSize]
static float EdgeMaxY[PolygonSize]
static enum SurveyStatus CSurveyStatus
#define POLYSURVEY_DEFAULT_SIZE
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)
bool nav_survey_poly_run(void)
Run polygon survey.
#define POLYSURVEY_ENTRY_DISTANCE
if 0 default to half sweep
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.
static struct EnuCoor_f survey_from survey_to
static void FindInterceptOfTwoLines(float *x, float *y, struct Line L1, struct Line L2)
static void TranslateAndRotateFromWorld(struct EnuCoor_f *p, float Zrot, float transX, float transY)
#define POLYSURVEY_DEFAULT_DISTANCE
void nav_survey_poly_setup(uint8_t EntryWP, uint8_t Size, float sw, float Orientation)
Setup polygon survey.
static struct EnuCoor_f SurveyEntry
static struct point survey_from
vector in East North Up coordinates Units: meters
struct RotorcraftNavigation nav
void nav_set_heading_deg(float deg)
Set nav_heading in degrees.
Rotorcraft navigation functions.
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.