Paparazzi UAS  v5.10_stable-5-g83a0da5-dirty
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
cartography.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2011 Vandeportaele Bertrand
3  *
4  * This file is part of paparazzi.
5  *
6  * paparazzi is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2, or (at your option)
9  * any later version.
10  *
11  * paparazzi is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with paparazzi; see the file COPYING. If not, write to
18  * the Free Software Foundation, 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  *
21  */
30 #include "state.h"
31 #include "stdio.h"
32 
34 #include "generated/flight_plan.h"
35 
36 #include "std.h" //macros pas mal dans sw/include
37 
39 //for fast debbuging, the simulation can be accelerated using the gaia software from an xterm console
40 // /home/bvdp/paparazzi3/sw/simulator/gaia
42 // for explanations about debugging macros:
43 //http://gcc.gnu.org/onlinedocs/cpp/Stringification.html#Stringification
44 
45 // Be carefull not to use printf function in ap compilation, only use it in sim compilation
46 // the DEBUG_PRINTF should be defined only in the sim part of the makefile airframe file
47 #ifdef DEBUG_PRINTF
48 int CPTDEBUG = 0;
49 #define PRTDEB(TYPE,EXP) \
50  printf("%5d: " #EXP ": %"#TYPE"\n",CPTDEBUG,EXP);fflush(stdout);CPTDEBUG++;
51 #define PRTDEBSTR(EXP) \
52  printf("%5d: STR: "#EXP"\n",CPTDEBUG);fflush(stdout);CPTDEBUG++;
53 #else
54 #define PRTDEB(TYPE,EXP) \
55  ;
56 
57 #define PRTDEBSTR(EXP) \
58  ;
59 #endif
60 
61 /*
62  exemple of use for theese macros
63  PRTDEBSTR(Init polysurvey)
64  PRTDEB(u,SurveySize)
65 
66  PRTDEB(lf,PolygonCenter.x)
67  PRTDEB(lf,PolygonCenter.y)
68  */
70 
71 #define DISTXY(P1X,P1Y,P2X,P2Y)\
72  (sqrt( ( (P2X-P1X) * (P2X-P1X) ) + ( (P2Y-P1Y) * (P2Y-P1Y) ) ) )
73 
74 #define NORMXY(P1X,P1Y)\
75  (sqrt( ( (P1X) * (P1X) ) + ( (P1Y) * (P1Y) ) ) )
76 
77 
78 //max distance between the estimator position and an objective points to consider that the objective points is atteined
79 
80 #define DISTLIMIT 30
81 
83 
85  1; //used to count the number of rails the plane has achieved since the boot, to number the sequences of saved images
86 //the number 1 is reserved for snapshot fonctions that take only one image, the 2-65535 numbers are used to number the following sequences
87 
89 #define USE_ONBOARD_CAMERA 1
90 
91 #if USE_ONBOARD_CAMERA
93 #endif
94 
95 
96 
97 
99 bool survey_losange_uturn;//this flag indicates if the aircraft is turning between 2 rails (1) or if it is flying straight forward in the rail direction (0)
100 
101 int railnumber; //indicate the number of the rail being acquired
103 
104 float distrail; //distance between adjacent rails in meters, the value is set in the init function
105 float distplus; //distance that the aircraft should travel before and after a rail before turning to the next rails in meters, the value is set in the init function
106 
108  60; //a cheangable value that can be set interactively in the GCS, not used at that time, it can be used to choose the right value while the aircraft is flying
109 
110 
111 static struct point point1, point2, point3; // 3 2D points used for navigation
112 static struct point pointA, pointB, pointC; // 3 2D points used for navigation
113 static struct point vec12, vec13;
114 float norm12, norm13; // norms of 12 & 13 vectors
115 
116 
117 
118 
119 float tempx, tempy; //temporary points for exchanges
120 float angle1213; //angle between 12 & 13 vectors
121 float signforturn; //can be +1 or -1, it is used to compute the direction of the UTURN between rails
122 
123 float tempcircleradius;// used to compute the radius of the UTURN after a rail
124 float circleradiusmin = 40;
125 
128 
129 
132 
134 
135 
136 
137 
139 #include "generated/modules.h"
140 
142 #include "mcu_periph/uart.h"
143 #include "std.h"
144 
145 
147 
148 void init_carto(void)
149 {
150 }
151 
153 {
154  DOWNLINK_SEND_CAMERA_SNAPSHOT(DefaultChannel, DefaultDevice, &camera_snapshot_image_number);
155 }
156 
157 void start_carto(void)
158 {
159 }
160 
161 void stop_carto(void)
162 {
163 }
164 
165 
166 
169 {
171  return false;
172 }
175 {
177  PRTDEBSTR(SNAPSHOT)
178  cartography_periodic_downlink_carto_status = MODULES_START;
179  return false;
180 
181 }
184 {
186  PRTDEBSTR(SNAPSHOT)
187  cartography_periodic_downlink_carto_status = MODULES_START;
188  return true;
189 
190 }
193 {
195  PRTDEBSTR(STOP SNAPSHOT)
196  cartography_periodic_downlink_carto_status = MODULES_START;
197  return false;
198 
199 }
201 
203 {
204  waypoints[wp4].x = waypoints[wp2].x + waypoints[wp3].x - waypoints[wp1].x;
205  waypoints[wp4].y = waypoints[wp2].y + waypoints[wp3].y - waypoints[wp1].y;
206 
208  PRTDEB(f, waypoints[wp4].x)
209  PRTDEB(f, waypoints[wp4].y)
210  return false;
211 }
212 
214 bool nav_survey_ComputeProjectionOnLine(struct point pointAf, struct point pointBf, float pos_xf, float pos_yf,
215  float *normAMf, float *normBMf, float *distancefromrailf);
216 
217 
218 bool nav_survey_ComputeProjectionOnLine(struct point pointAf, struct point pointBf, float pos_xf, float pos_yf,
219  float *normAMf, float *normBMf, float *distancefromrailf)
220 //return if the projection of the estimator on the AB line is located inside the AB interval
221 {
222  float a, b, c, xa, xb, xc, ya, yb, yc;
223  float f;
224  float AA1;
225  float BB1;
226  float YP;
227  float XP;
228 
229  float AMx, AMy, BMx, BMy;
230  //+++++++++++++++++++++++++ATTENTION AUX DIVISIONS PAR 0!!!!!!!!!!!!!!!
231 
232 
233 
234  xb = pointAf.x;
235  yb = pointAf.y;
236 
237  xc = pointBf.x;
238  yc = pointBf.y;
239 
240  xa = pos_xf;
241  ya = pos_yf;
242 
243  //calcul des parametres de la droite pointAf pointBf
244  a = yc - yb;
245  b = xb - xc;
246  c = (yb - yc) * xb + (xc - xb) * yb ;
247 
248  //calcul de la distance de la droite à l'avion
249 
250 
251  if (fabs(a) > 1e-10) {
252  *distancefromrailf = fabs((a * xa + b * ya + c) / sqrt(a * a + b *
253  b)); //denominateur =0 iniquement si a=b=0 //peut arriver si 2 waypoints sont confondus
254  } else {
255  return 0;
256  }
257 
258  PRTDEB(f, a)
259  PRTDEB(f, b)
260  PRTDEB(f, c)
261  PRTDEB(f, *distancefromrailf)
262 
263 
264  // calcul des coordonnées du projeté orthogonal M(xx,y) de A sur (BC)
265  AA1 = (xc - xb);
266  BB1 = (yc - yb);
267  if (fabs(AA1) > 1e-10) {
268  f = (b - (a * BB1 / AA1));
269  if (fabs(f) > 1e-10) {
270  YP = (-(a * xa) - (a * BB1 * ya / AA1) - c) / f;
271  } else {
272  return 0;
273  }
274  } else {
275  return 0;
276  }
277 
278 
279 
280 
281  XP = (-c - b * YP) / a ; //a !=0 deja testé avant
282  //+++++++++++++++++++++++++ATTENTION AUX DIVISIONS PAR 0!!!!!!!!!!!!!!!
283  //+++++++++++++++++++++++++ATTENTION AUX DIVISIONS PAR 0!!!!!!!!!!!!!!!
284  //+++++++++++++++++++++++++ATTENTION AUX DIVISIONS PAR 0!!!!!!!!!!!!!!!
285 
286  PRTDEB(f, AA1)
287  PRTDEB(f, BB1)
288  PRTDEB(f, YP)
289  PRTDEB(f, XP)
290 
291  AMx = XP - pointAf.x;
292  AMy = YP - pointAf.y;
293  BMx = XP - pointBf.x;
294  BMy = YP - pointBf.y;
295 
296  *normAMf = NORMXY(AMx, AMy);
297  *normBMf = NORMXY(BMx, BMy);
298 
299  PRTDEB(f, *normAMf)
300  PRTDEB(f, *normBMf)
301 
302  if (((*normAMf) + (*normBMf)) > 1.05 * DISTXY(pointBf.x, pointBf.y, pointAf.x, pointAf.y)) {
303  PRTDEBSTR(NOT INSIDE)
304  return 0;
305  } else {
306  PRTDEBSTR(INSIDE)
307  return 1;
308  }
309 }
311 //if distrailinit = 0, the aircraft travel from wp1 -> wp2 then do the inverse travel passing through the wp3,
312 //This mode could be use to register bands of images aquired in a first nav_survey_losange_carto, done perpendicularly
313 bool nav_survey_losange_carto_init(uint8_t wp1, uint8_t wp2, uint8_t wp3, float distrailinit, float distplusinit)
314 {
315  //PRTDEBSTR(nav_survey_losange_carto_init)
316  survey_losange_uturn = false;
317 
318 
319  point1.x = waypoints[wp1].x; //the coordinates are in meter units, taken from the flight plan, in float type
320  point1.y = waypoints[wp1].y;
321  point2.x = waypoints[wp2].x;
322  point2.y = waypoints[wp2].y;
323  point3.x = waypoints[wp3].x;
324  point3.y = waypoints[wp3].y;
325 
326  PRTDEB(u, wp1)
327  PRTDEB(f, point1.x)
328  PRTDEB(f, point1.y)
329 
330  PRTDEB(u, wp2)
331  PRTDEB(f, point2.x)
332  PRTDEB(f, point2.y)
333 
334  PRTDEB(u, wp3)
335  PRTDEB(f, point3.x)
336  PRTDEB(f, point3.y)
337 
338 
339 
340  vec12.x = point2.x - point1.x;
341  vec12.y = point2.y - point1.y;
342  PRTDEB(f, vec12.x)
343  PRTDEB(f, vec12.y)
344 
345  //TODO gerer le cas ou un golio met les points à la meme position -> norm=0 > /0
346  norm12 = NORMXY(vec12.x, vec12.y);
347 
348  PRTDEB(f, norm12)
349 
350 
351  vec13.x = point3.x - point1.x;
352  vec13.y = point3.y - point1.y;
353  PRTDEB(f, vec13.x)
354  PRTDEB(f, vec13.y)
355 
356  norm13 = NORMXY(vec13.x, vec13.y);
357  PRTDEB(f, norm13)
358 
359  //if (distrail<1e-15) //inutile distrail=0 pour recollage et dans ce cas, il prend la valeur norm13
360  // return false;
361 
362 
363  if (fabs(distrailinit) <= 1) {
364  //is distrailinit==0, then the aircraft should do 2 passes to register the bands
365  distrail = norm13;
366  numberofrailtodo = 1;
367  } else {
368  //no, so normal trajectory
369  distrail = fabs(distrailinit);
370  numberofrailtodo = ceil(norm13 / distrail); //round to the upper integer
371  }
372 
373  distplus = fabs(distplusinit);
374 
375 
376  PRTDEB(f, distrail)
377  PRTDEB(f, distplus)
379  PRTDEB(d, railnumber)
381 
382  railnumber = -1; // the state is before the first rail, which is numbered 0
383 
384  if (norm12 < 1e-15) {
385  return false;
386  }
387  if (norm13 < 1e-15) {
388  return false;
389  }
390 
391 
392  angle1213 = (180 / 3.14159) * acos((((vec12.x * vec13.x) + (vec12.y * vec13.y))) / (norm12 *
393  norm13)); //oriented angle between 12 and 13 vectors
394 
395  angle1213 = atan2f(vec13.y, vec13.x) - atan2f(vec12.y, vec12.x);
396  while (angle1213 >= M_PI) { angle1213 -= 2 * M_PI; }
397  while (angle1213 <= -M_PI) { angle1213 += 2 * M_PI; }
398 
399  PRTDEB(f, angle1213)
400 
401  if (angle1213 > 0) {
402  signforturn = -1;
403  } else {
404  signforturn = 1;
405  }
406 
407 
408  return false; //Init function must return false, so that the next function in the flight plan is automatically executed
409  //dans le flight_plan.h
410  // if (! (nav_survey_losange_carto()))
411  // NextStageAndBreak();
412 }
415 {
416  //test pour modifier en vol la valeur distrail
417 
418  //distrail=distrailinteractif;
419 
420 
421  //by default, a 0 is sent in the message DOWNLINK_SEND_CAMERA_SNAPSHOT,
422  //if the aircraft is inside the region to map, camera_snapshot_image_number will be equal to the number of rail since the last boot (not since the nav_survey_losange_carto_init, in order to get different values for differents calls to the cartography function (this number is used to name the images on the hard drive
424 
425 
426  PRTDEB(f, distrail)
427 
428 
429 
431  PRTDEB(d, railnumber)
432 
434 
435  //PRTDEB(f,stateGetPositionEnu_f()->x)
436  //PRTDEB(f,stateGetPositionEnu_f()->y)
437 
438  //sortir du bloc si données abhérantes
439  if (norm13 < 1e-15) {
440  PRTDEBSTR(norm13 < 1e-15)
441  return false;
442  }
443  if (norm12 < 1e-15) {
444  PRTDEBSTR(norm13 < 1e-15)
445  return false;
446  }
447  if (distrail < 1e-15) {
448  PRTDEBSTR(distrail < 1e-15)
449  return false;
450  }
451 
452  if (survey_losange_uturn == FALSE) {
453 
454  if (railnumber == -1) {
455  //se diriger vers le début du 1°rail
456  PRTDEBSTR(approche debut rail 0)
457  pointA.x = point1.x - (vec12.x / norm12) * distplus * 1.2; //on prend une marge plus grande pour arriver en ce point
458  pointA.y = point1.y - (vec12.y / norm12) * distplus * 1.2; //car le virage n'est pas tres bien géré
459 
460 
461  pointB.x = point2.x + (vec12.x / norm12) * distplus * 1.2; //on prend une marge plus grande pour arriver en ce point
462  pointB.y = point2.y + (vec12.y / norm12) * distplus * 1.2; //car le virage n'est pas tres bien géré
463 
464  //PRTDEB(f,pointA.x)
465  //PRTDEB(f,pointA.y)
466 
467 
468  //the following test can cause problem when the aircraft is quite close to the entry point, as it can turn around for infinte time
469  //if ( DISTXY(stateGetPositionEnu_f()->x,stateGetPositionEnu_f()->y,pointA.x,pointA.y) >DISTLIMIT)
470  //if ( DISTXY(stateGetPositionEnu_f()->x,stateGetPositionEnu_f()->y,pointA.x,pointA.y) >DISTLIMIT)
471 
472 
475 
476  if ((DISTXY(stateGetPositionEnu_f()->x, stateGetPositionEnu_f()->y, pointA.x, pointA.y) > 2 * DISTLIMIT)
477  || (normBM < (DISTXY(pointB.x, pointB.y, pointA.x, pointA.y)))) {
478  nav_route_xy(stateGetPositionEnu_f()->x, stateGetPositionEnu_f()->y, pointA.x, pointA.y);
479  //nav_route_xy(pointB.x, pointB.y,pointA.x,pointA.y);
480  } else {
481  PRTDEBSTR(debut rail 0)
482  //un fois arrivé, on commence le 1° rail;
483  railnumber = 0;
485 
486  }
487  }
488 
489 
490  if (railnumber >= 0) {
491  pointA.x = (point1.x - ((vec12.x / norm12) * distplus)) + ((railnumber) * (vec13.x / norm13) * distrail);
492  pointA.y = (point1.y - ((vec12.y / norm12) * distplus)) + ((railnumber) * (vec13.y / norm13) * distrail);
493 
494  pointB.x = (point2.x + ((vec12.x / norm12) * distplus)) + ((railnumber) * (vec13.x / norm13) * distrail);
495  pointB.y = (point2.y + ((vec12.y / norm12) * distplus)) + ((railnumber) * (vec13.y / norm13) * distrail);
496 
497 
498 
499 
500 
501  if ((railnumber % 2) == 0) { //rail n0, 2, 4, donc premiere direction, de wp1 vers wp2
502  //rien a faire
503  } else { //if ((railnumber %2)==1) //rail n1, 3, 5, donc seconde direction, de wp2 vers wp1
504  //echange pointA et B
505  tempx = pointA.x;
506  tempy = pointA.y;
507  pointA.x = pointB.x;
508  pointA.y = pointB.y;
509  pointB.x = tempx;
510  pointB.y = tempy;
511 
512  }
513 
514  // PRTDEB(f,pointA.x)
515  // PRTDEB(f,pointA.y)
516  // PRTDEB(f,pointB.x)
517  // PRTDEB(f,pointB.y)
520 
521 
522 
523  // if ( ( DISTXY(stateGetPositionEnu_f()->x,stateGetPositionEnu_f()->y,pointB.x,pointB.y) >DISTLIMIT) &&
524  // (normBM>(DISTXY(pointB.x,pointB.y,pointA.x,pointA.y))))
525 
526 
527  if (!((DISTXY(stateGetPositionEnu_f()->x, stateGetPositionEnu_f()->y, pointB.x, pointB.y) < DISTLIMIT)
528  || (ProjectionInsideLimitOfRail && (normAM > (DISTXY(pointB.x, pointB.y, pointA.x, pointA.y))))))
529  // (normBM>(DISTXY(pointB.x,pointB.y,pointA.x,pointA.y))))
530  {
531  nav_route_xy(pointA.x, pointA.y, pointB.x, pointB.y);
532  PRTDEBSTR(NAVROUTE)
533 
534 
535  //est ce que l'avion est dans la zone ou il doit prendre des images?
536  //DEJA APPELE AVANT LE IF
537  // nav_survey_ComputeProjectionOnLine(pointA,pointB,stateGetPositionEnu_f()->x,stateGetPositionEnu_f()->y,&normAM,&normBM,&distancefromrail);
538 
539  if ((normAM > distplus) && (normBM > distplus) && (distancefromrail < distrail / 2)) {
540  //CAMERA_SNAPSHOT_REQUIERED=true;
541  //camera_snapshot_image_number++;
543  PRTDEBSTR(SNAPSHOT)
544  }
545 
546  }
547 
548  else { // virage
549  //PRTDEBSTR(debut rail suivant)
550  railnumber++;
552 
553  PRTDEB(d, railnumber)
555  //CAMERA_SNAPSHOT_REQUIERED=true;
556  //camera_snapshot_image_number++;
557 
559  survey_losange_uturn = true;
560 
561  }
562 
565  return false; //apparament, l'avion va au bloc suivant lorsque la fonction renvoie false
566  }
567 
568  }
569  } else { // (survey_losange_uturn==TRUE)
570 
571 
572  if (distrail < 200) {
573  //tourne autour d'un point à mi chemin entre les 2 rails
574 
575  //attention railnumber a été incrémenté en fin du rail précédent
576 
577  if ((railnumber % 2) == 1) { //rail précédent n0, 2, 4, donc premiere direction, de wp1 vers wp2
578  PRTDEBSTR(UTURN - IMPAIR)
579  //fin du rail précédent
580  pointA.x = (point2.x + ((vec12.x / norm12) * distplus)) + ((railnumber - 1) * (vec13.x / norm13) * distrail);
581  pointA.y = (point2.y + ((vec12.y / norm12) * distplus)) + ((railnumber - 1) * (vec13.y / norm13) * distrail);
582  //début du rail suivant
583  pointB.x = (point2.x + ((vec12.x / norm12) * distplus)) + ((railnumber) * (vec13.x / norm13) * distrail);
584  pointB.y = (point2.y + ((vec12.y / norm12) * distplus)) + ((railnumber) * (vec13.y / norm13) * distrail);
585  //milieu
586  waypoints[0].x = (pointA.x + pointB.x) / 2;
587  waypoints[0].y = (pointA.y + pointB.y) / 2;
588 
589  tempcircleradius = distrail / 2;
592  }
593 
594 
595  //fin du rail suivant
596  pointC.x = (point1.x + ((vec12.x / norm12) * distplus)) + ((railnumber) * (vec13.x / norm13) * distrail);
597  pointC.y = (point1.y + ((vec12.y / norm12) * distplus)) + ((railnumber) * (vec13.y / norm13) * distrail);
598 
599 
600  course_next_rail = atan2(pointC.x - pointB.x, pointC.y - pointB.y);
603 
605  while (angle_between > M_PI) { angle_between -= 2 * M_PI; }
606  while (angle_between < -M_PI) { angle_between += 2 * M_PI; }
607 
608  angle_between = DegOfRad(angle_between);
610  //if (angle_between> -10 && angle_between< 10) PRTDEBSTR(ON SE CASSE)
611 
613  if ((DISTXY(stateGetPositionEnu_f()->x, stateGetPositionEnu_f()->y, pointB.x, pointB.y) < DISTLIMIT)
614  || (angle_between > -10 && angle_between < 10)) {
615  //l'avion fait le rail suivant
616  survey_losange_uturn = false;
617  PRTDEBSTR(FIN UTURN - IMPAIR)
618  }
619  } else { //if ((railnumber %2)==0) //rail précédent n1, 3, 5, donc seconde direction, de wp2 vers wp1
620  PRTDEBSTR(UTURN - PAIR)
621  //fin du rail précédent
622  pointA.x = (point1.x - ((vec12.x / norm12) * distplus)) + ((railnumber - 1) * (vec13.x / norm13) * distrail);
623  pointA.y = (point1.y - ((vec12.y / norm12) * distplus)) + ((railnumber - 1) * (vec13.y / norm13) * distrail);
624  //début du rail suivant
625  pointB.x = (point1.x - ((vec12.x / norm12) * distplus)) + ((railnumber) * (vec13.x / norm13) * distrail);
626  pointB.y = (point1.y - ((vec12.y / norm12) * distplus)) + ((railnumber) * (vec13.y / norm13) * distrail);
627  //milieu
628  waypoints[0].x = (pointA.x + pointB.x) / 2;
629  waypoints[0].y = (pointA.y + pointB.y) / 2;
630 
631  tempcircleradius = distrail / 2;
634  }
635 
636 
637 
638 
639  //fin du rail suivant
640  pointC.x = (point2.x + ((vec12.x / norm12) * distplus)) + ((railnumber) * (vec13.x / norm13) * distrail);
641  pointC.y = (point2.y + ((vec12.y / norm12) * distplus)) + ((railnumber) * (vec13.y / norm13) * distrail);
642 
643 
644  course_next_rail = atan2(pointC.x - pointB.x, pointC.y - pointB.y);
647 
649  while (angle_between > M_PI) { angle_between -= 2 * M_PI; }
650  while (angle_between < -M_PI) { angle_between += 2 * M_PI; }
651 
652  angle_between = DegOfRad(angle_between);
654  //if (angle_between> -10 && angle_between< 10) PRTDEBSTR(ON SE CASSE)
655 
657  if ((DISTXY(stateGetPositionEnu_f()->x, stateGetPositionEnu_f()->y, pointB.x, pointB.y) < DISTLIMIT)
658  || (angle_between > -10 && angle_between < 10)) {
659  //l'avion fait le rail suivant
660  survey_losange_uturn = false;
661  PRTDEBSTR(FIN UTURN - PAIR)
662  }
663  }
664  } else {
665  //Le virage serait trop grand, on va en ligne droite pour ne pas trop éloigner l'avion
666 
667  if ((railnumber % 2) == 1) { //rail précédent n0, 2, 4, donc premiere direction, de wp1 vers wp2
668  PRTDEBSTR(TRANSIT - IMPAIR)
669  //fin du rail précédent
670  pointA.x = (point2.x + ((vec12.x / norm12) * distplus)) + ((railnumber - 1) * (vec13.x / norm13) * distrail);
671  pointA.y = (point2.y + ((vec12.y / norm12) * distplus)) + ((railnumber - 1) * (vec13.y / norm13) * distrail);
672  //début du rail suivant
673  pointB.x = (point2.x + ((vec12.x / norm12) * distplus)) + ((railnumber) * (vec13.x / norm13) * distrail);
674  pointB.y = (point2.y + ((vec12.y / norm12) * distplus)) + ((railnumber) * (vec13.y / norm13) * distrail);
675  nav_route_xy(pointA.x, pointA.y, pointB.x, pointB.y);
676  if (DISTXY(stateGetPositionEnu_f()->x, stateGetPositionEnu_f()->y, pointB.x, pointB.y) < DISTLIMIT) {
677  //l'avion fait le rail suivant
678  survey_losange_uturn = false;
679  PRTDEBSTR(FIN TRANSIT - IMPAIR)
680  }
681  } else { //if ((railnumber %2)==0) //rail précédent n1, 3, 5, donc seconde direction, de wp2 vers wp1
682  PRTDEBSTR(TRANSIT - PAIR)
683  //fin du rail précédent
684  pointA.x = (point1.x - ((vec12.x / norm12) * distplus)) + ((railnumber - 1) * (vec13.x / norm13) * distrail);
685  pointA.y = (point1.y - ((vec12.y / norm12) * distplus)) + ((railnumber - 1) * (vec13.y / norm13) * distrail);
686  //début du rail suivant
687  pointB.x = (point1.x - ((vec12.x / norm12) * distplus)) + ((railnumber) * (vec13.x / norm13) * distrail);
688  pointB.y = (point1.y - ((vec12.y / norm12) * distplus)) + ((railnumber) * (vec13.y / norm13) * distrail);
689  nav_route_xy(pointA.x, pointA.y, pointB.x, pointB.y);
690  if (DISTXY(stateGetPositionEnu_f()->x, stateGetPositionEnu_f()->y, pointB.x, pointB.y) < DISTLIMIT) {
691  //l'avion fait le rail suivant
692  survey_losange_uturn = false;
693  PRTDEBSTR(FIN TRANSIT - PAIR)
694  }
695 
696  }
697 
698  }
699  }
700 
701 
703  //NavVerticalAutoThrottleMode(0.); /* No pitch */
704  //NavVerticalAltitudeMode(WaypointAlt(wp1), 0.); /* No preclimb */
705 
706 
707 
708  cartography_periodic_downlink_carto_status = MODULES_START;
709 
710  return true; //apparament pour les fonctions de tache=> true
711 }
713 
714 
unsigned short uint16_t
Definition: types.h:16
float norm13
Definition: cartography.c:114
float distancefromrail
Definition: cartography.c:127
#define PRTDEB(TYPE, EXP)
Definition: cartography.c:54
Definition: sdio_arch.c:43
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
#define PRTDEBSTR(EXP)
Definition: cartography.c:57
float x
Definition: common_nav.h:40
float normAM
Definition: cartography.c:127
#define DISTXY(P1X, P1Y, P2X, P2Y)
Definition: cartography.c:71
float distrail
Definition: cartography.c:104
float tempcircleradius
Definition: cartography.c:123
float norm12
Definition: cartography.c:114
static struct point point1 point2 point3
Definition: cartography.c:111
static struct point vec12 vec13
Definition: cartography.c:113
float signforturn
Definition: cartography.c:121
float tempx
Definition: cartography.c:119
bool nav_survey_Snapshoot(void)
Definition: cartography.c:174
void start_carto(void)
Definition: cartography.c:157
static struct EnuCoor_f * stateGetPositionEnu_f(void)
Get position in local ENU coordinates (float).
Definition: state.h:713
uint16_t railnumberSinceBoot
Definition: cartography.c:84
#define FALSE
Definition: std.h:5
float circleradiusmin
Definition: cartography.c:124
bool nav_survey_Inc_railnumberSinceBoot(void)
Definition: cartography.c:168
float y
Definition: common_nav.h:41
float normBM
Definition: cartography.c:127
bool nav_survey_StopSnapshoot(void)
Definition: cartography.c:192
bool nav_survey_losange_carto(void)
Definition: cartography.c:414
float angle1213
Definition: cartography.c:120
void stop_carto(void)
Definition: cartography.c:161
float distrailinteractif
Definition: cartography.c:107
bool survey_losange_uturn
Definition: cartography.c:99
void init_carto(void)
Automatic survey of an oriented rectangle (defined by three points)
Definition: cartography.c:148
int railnumber
Definition: cartography.c:101
static float stateGetHorizontalSpeedDir_f(void)
Get dir of horizontal ground speed (float).
Definition: state.h:932
static struct point pointA pointB pointC
Definition: cartography.c:112
unsigned char uint8_t
Definition: types.h:14
int numberofrailtodo
Definition: cartography.c:102
API to get/set the generic vehicle states.
struct point waypoints[NB_WAYPOINT]
size == nb_waypoint, waypoint 0 is a dummy waypoint
Definition: common_nav.c:38
float angle_between
Definition: cartography.c:131
#define NORMXY(P1X, P1Y)
Definition: cartography.c:74
bool ProjectionInsideLimitOfRail
Definition: cartography.c:133
void periodic_downlink_carto(void)
Definition: cartography.c:152
float a
Definition: common_nav.h:42
#define DISTLIMIT
Definition: cartography.c:80
bool nav_survey_losange_carto_init(uint8_t wp1, uint8_t wp2, uint8_t wp3, float distrailinit, float distplusinit)
Definition: cartography.c:313
bool nav_survey_computefourth_corner(uint8_t wp1, uint8_t wp2, uint8_t wp3, uint8_t wp4)
Definition: cartography.c:202
bool nav_survey_ComputeProjectionOnLine(struct point pointAf, struct point pointBf, float pos_xf, float pos_yf, float *normAMf, float *normBMf, float *distancefromrailf)
Definition: cartography.c:218
bool nav_survey_Snapshoot_Continu(void)
Definition: cartography.c:183
uint16_t camera_snapshot_image_number
Definition: cartography.c:92
float tempy
Definition: cartography.c:119
float distplus
Definition: cartography.c:105
float course_next_rail
Definition: cartography.c:130