31 #include "autopilot.h"
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
78 if (dx == 0.0f) { dx = 0.000000001; }
79 float ang = atan(dy / dx);
94 #define PolygonSize POLY_OSAM_POLYGONSIZE
95 #define MaxFloat 1000000000
96 #define MinFloat -1000000000
98 #ifndef LINE_START_FUNCTION
99 #define LINE_START_FUNCTION {}
101 #ifndef LINE_STOP_FUNCTION
102 #define LINE_STOP_FUNCTION {}
136 static struct Point2D EntryPoint;
140 float XIntercept1 = 0;
141 float XIntercept2 = 0;
142 float entry_distance;
147 if (PolySurveyEntryDistance == 0) {
148 entry_distance = sw / 2;
150 entry_distance = PolySurveyEntryDistance;
153 if (PolySurveyEntryRadius == 0) {
166 struct Point2D Corners[PolygonSize];
175 if (Size <= PolygonSize && Orientation >= -90 && Orientation <= 90) {
177 for (i = 0; i < Size; i++) {
183 for (i = 0; i < Size; i++) {
190 for (i = 1; i < Size; i++) {
201 for (i = 0; i < Size; i++) {
206 EntryPoint.
x = Corners[0].
x;
207 EntryPoint.
y = Corners[0].
y;
211 for (i = 1; i < Size; i++) {
212 if (Corners[i].
y >
MaxY) {
218 for (i = 0; i < Size; i++) {
220 if (Corners[Size - 1].
x == Corners[i].
x) {
223 Edges[i].
m = ((Corners[Size - 1].
y - Corners[i].
y) / (Corners[Size - 1].x - Corners[i].x));
225 else if (Corners[i].x == Corners[i - 1].x) {
228 Edges[i].
m = ((Corners[i].
y - Corners[i - 1].
y) / (Corners[i].x - Corners[i - 1].x));
239 if (LeftYInt > RightYInt) {
247 for (i = 1; i < Size - 1; i++) {
251 if (LeftYInt > RightYInt) {
263 if (LeftYInt > RightYInt) {
272 if (EntryPoint.
y >=
MaxY / 2) {
273 entry_distance = -entry_distance;
289 ys = EntryPoint.
y + entry_distance;
294 XIntercept2 = XIntercept1;
300 if (fabs(EntryPoint.
x - XIntercept2) <= fabs(EntryPoint.
x - XIntercept1)) {
328 CSurveyStatus =
Entry;
341 static struct Point2D LastPoint;
343 bool_t LastHalfSweep;
344 static bool_t HalfSweep =
FALSE;
345 float XIntercept1 = 0;
346 float XIntercept2 = 0;
374 LastHalfSweep = HalfSweep;
389 float dist = FromP.
x - C.
x;
419 ys = LastPoint.
y + (
dSweep / 2);
429 ys = LastPoint.
y + (
dSweep / 2);
449 XIntercept2 = XIntercept1;
455 DInt1 = XIntercept1 - LastPoint.
x;
456 DInt2 = XIntercept2 - LastPoint.
x;
458 if (DInt1 * DInt2 >= 0) {
459 if (fabs(DInt2) <= fabs(DInt1)) {
502 if (fabs(temp) < min_radius) {
503 if (temp < 0) { temp = -min_radius; }
else { temp = min_radius; }
565 p->
x = p->
x - transX;
566 p->
y = p->
y - transY;
569 p->
x = p->
x * cosf(Zrot) + p->
y * sinf(Zrot);
570 p->
y = -temp * sinf(Zrot) + p->
y * cosf(Zrot);
578 p->
x = p->
x * cosf(Zrot) - p->
y * sinf(Zrot);
579 p->
y = temp * sinf(Zrot) + p->
y * cosf(Zrot);
581 p->
x = p->
x + transX;
582 p->
y = p->
y + transY;
587 *x = ((L2.
b - L1.
b) / (L1.
m - L2.
m));
588 *y = L1.
m * (*x) + L1.
b;
594 return ((y - L.
b) / L.
m);
static float EdgeMaxY[PolygonSize]
#define LINE_START_FUNCTION
static float EdgeMinY[PolygonSize]
bool_t nav_survey_poly_osam_run(void)
Run polygon survey.
void nav_circle_XY(float x, float y, float radius)
Navigates around (x, y).
static float SurveyCircleQdr
bool_t nav_survey_poly_osam_setup(uint8_t EntryWP, uint8_t Size, float sw, float Orientation)
Setup polygon survey.
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)
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
bool_t 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.
static float EvaluateLineForX(float y, struct Line L)
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
bool_t 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.