40 #include "autopilot.h"
41 #include "generated/flight_plan.h"
47 #ifndef POLYSURVEY_DEFAULT_SIZE
48 #define POLYSURVEY_DEFAULT_SIZE 10
51 #ifndef POLYSURVEY_DEFAULT_DISTANCE
52 #define POLYSURVEY_DEFAULT_DISTANCE 25
56 #ifndef POLYSURVEY_ENTRY_DISTANCE
57 #define POLYSURVEY_ENTRY_DISTANCE 0
61 #ifndef POLYSURVEY_MAX_POLYGONSIZE
62 #define POLYSURVEY_MAX_POLYGONSIZE 20
73 if (dx == 0.0f) { dx = 0.000000001; }
74 float ang = atan(dy / dx);
84 struct Line {
float m;
float b;
float x;};
91 #define MaxPolygonSize POLYSURVEY_MAX_POLYGONSIZE
92 #define MaxFloat 1000000000
93 #define MinFloat -1000000000
95 #ifndef LINE_START_FUNCTION
96 #define LINE_START_FUNCTION {}
98 #ifndef LINE_STOP_FUNCTION
99 #define LINE_STOP_FUNCTION {}
141 float XIntercept1 = 0;
142 float XIntercept2 = 0;
143 float entry_distance;
147 if (PolySurveyEntryDistance == 0) {
148 entry_distance = sw / 2;
150 entry_distance = PolySurveyEntryDistance;
160 struct EnuCoor_f Corners[MaxPolygonSize];
169 if (Size <= MaxPolygonSize && Orientation >= -90 && Orientation <= 90) {
171 for (i = 0; i < Size; i++) {
177 for (i = 0; i < Size; i++) {
184 for (i = 1; i < Size; i++) {
195 for (i = 0; i < Size; i++) {
200 EntryPoint.
x = Corners[0].
x;
201 EntryPoint.
y = Corners[0].
y;
205 for (i = 1; i < Size; i++) {
206 if (Corners[i].
y >
MaxY) {
212 for (i = 0; i < Size; i++) {
214 if (Corners[Size - 1].
x == Corners[i].
x) {
217 Edges[i].
m = ((Corners[Size - 1].
y - Corners[i].
y) / (Corners[Size - 1].x - Corners[i].x));
219 else if (Corners[i].x == Corners[i - 1].x) {
222 Edges[i].
m = ((Corners[i].
y - Corners[i - 1].
y) / (Corners[i].x - Corners[i - 1].x));
233 if (LeftYInt > RightYInt) {
241 for (i = 1; i < Size - 1; i++) {
245 if (LeftYInt > RightYInt) {
257 if (LeftYInt > RightYInt) {
266 if (EntryPoint.
y >=
MaxY / 2) {
267 entry_distance = -entry_distance;
274 ys = EntryPoint.
y + entry_distance;
279 XIntercept2 = XIntercept1;
285 if (fabs(EntryPoint.
x - XIntercept2) <= fabs(EntryPoint.
x - XIntercept1)) {
304 CSurveyStatus =
Entry;
325 bool_t LastHalfSweep;
326 static bool_t HalfSweep =
FALSE;
327 float XIntercept1 = 0;
328 float XIntercept2 = 0;
350 LastHalfSweep = HalfSweep;
372 float line_length = fabsf((fabsf(FromP.
x) - fabsf(ToP.
x)));
399 ys = LastPoint.
y + (
dSweep / 2);
413 XIntercept2 = XIntercept1;
419 DInt1 = XIntercept1 - LastPoint.
x;
420 DInt2 = XIntercept2 - LastPoint.
x;
422 if (DInt1 * DInt2 >= 0) {
423 if (fabs(DInt2) <= fabs(DInt1)) {
510 p->
x = p->
x - transX;
511 p->
y = p->
y - transY;
514 p->
x = p->
x * cosf(Zrot) + p->
y * sinf(Zrot);
515 p->
y = -temp * sinf(Zrot) + p->
y * cosf(Zrot);
523 p->
x = p->
x * cosf(Zrot) - p->
y * sinf(Zrot);
524 p->
y = temp * sinf(Zrot) + p->
y * cosf(Zrot);
526 p->
x = p->
x + transX;
527 p->
y = p->
y + transY;
532 *x = ((L2.
b - L1.
b) / (L1.
m - L2.
m));
533 *y = L1.
m * (*x) + L1.
b;
539 return ((y - L.
b) / L.
m);
#define POLYSURVEY_DEFAULT_SIZE
static struct EnuCoor_f SurveyToWP
#define LINE_STOP_FUNCTION
bool_t nav_approaching_from(struct EnuCoor_i *wp, struct EnuCoor_i *from, int16_t approaching_time)
Proximity tests on approaching a wp.
bool_t nav_set_heading_deg(float deg)
Set nav_heading in degrees.
Rotorcraft navigation functions.
bool_t nav_survey_poly_run(void)
Run polygon survey.
vector in East North Up coordinates Units: meters
void nav_route(struct EnuCoor_i *wp_start, struct EnuCoor_i *wp_end)
#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)
struct EnuCoor_i navigation_target
static struct EnuCoor_f * stateGetPositionEnu_f(void)
Get position in local ENU coordinates (float).
static struct Line Edges[MaxPolygonSize]
bool_t nav_survey_poly_setup(uint8_t EntryWP, uint8_t Size, float sw, float Orientation)
Setup polygon survey.
Standard Digital Camera Control Interface.
#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...
bool_t 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 void TranslateAndRotateFromWorld(struct EnuCoor_f *p, float Zrot, float transX, float transY)
#define POLYSURVEY_DEFAULT_DISTANCE
static float EdgeMinY[MaxPolygonSize]
#define HORIZONTAL_MODE_ROUTE
void nav_init_stage(void)
needs to be implemented by fixedwing and rotorcraft seperately
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
#define ENU_BFP_OF_REAL(_o, _i)
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]
static struct EnuCoor_f SurveyFromWP