Paparazzi UAS  v5.18.0_stable
Paparazzi is a free software Unmanned Aircraft System.
nav_survey_rectangle_rotorcraft.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2007-2009 ENAC, Pascal Brisset, Antoine Drouin
3  * 2015 NAC-VA, Eduardo Lavratti
4  *
5  * This file is part of paparazzi.
6  *
7  * paparazzi is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2, or (at your option)
10  * any later version.
11  *
12  * paparazzi is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with paparazzi; see the file COPYING. If not, write to
19  * the Free Software Foundation, 59 Temple Place - Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */
22 
31 #ifndef RECTANGLE_SURVEY_DEFAULT_SWEEP
32 #define RECTANGLE_SURVEY_DEFAULT_SWEEP 25
33 #endif
34 
35 #ifdef RECTANGLE_SURVEY_USE_INTERLEAVE
36 #define USE_INTERLEAVE TRUE
37 #else
38 #define USE_INTERLEAVE FALSE
39 #endif
40 
41 #include "mcu_periph/uart.h"
42 #include "pprzlink/messages.h"
44 
45 #if PERIODIC_TELEMETRY
47 #endif
48 
50 
52 #include "state.h"
53 
54 #ifndef RECTANGLE_SURVEY_HEADING_NS
55 #define RECTANGLE_SURVEY_HEADING_NS 0.f
56 #endif
57 
58 #ifndef RECTANGLE_SURVEY_HEADING_WE
59 #define RECTANGLE_SURVEY_HEADING_WE 90.f
60 #endif
61 
63 static bool nav_survey_rectangle_active = false;
65 bool nav_in_segment = false;
66 bool nav_in_circle = false;
68 
70 static struct EnuCoor_i survey_from_i, survey_to_i;
71 
72 static bool survey_uturn __attribute__((unused)) = false;
74 
77 
78 #define SurveyGoingNorth() ((survey_orientation == NS) && (survey_to.y > survey_from.y))
79 #define SurveyGoingSouth() ((survey_orientation == NS) && (survey_to.y < survey_from.y))
80 #define SurveyGoingEast() ((survey_orientation == WE) && (survey_to.x > survey_from.x))
81 #define SurveyGoingWest() ((survey_orientation == WE) && (survey_to.x < survey_from.x))
82 
83 #include "generated/flight_plan.h"
84 
85 #ifndef LINE_START_FUNCTION
86 #define LINE_START_FUNCTION {}
87 #endif
88 #ifndef LINE_STOP_FUNCTION
89 #define LINE_STOP_FUNCTION {}
90 #endif
91 
92 static void send_survey(struct transport_tx *trans, struct link_device *dev)
93 {
94  if (nav_survey_active) {
95  pprz_msg_send_SURVEY(trans, dev, AC_ID,
97  }
98 }
99 
101 {
102 #if PERIODIC_TELEMETRY
104 #endif
105 }
106 
108 {
110  nav_survey_west = Min(WaypointX(wp1), WaypointX(wp2));
111  nav_survey_east = Max(WaypointX(wp1), WaypointX(wp2));
112  nav_survey_south = Min(WaypointY(wp1), WaypointY(wp2));
113  nav_survey_north = Max(WaypointY(wp1), WaypointY(wp2));
114  survey_orientation = so;
115 
116  if (survey_orientation == NS) {
118  survey_from.x = survey_to.x = nav_survey_west + grid / 4.;
119  } else {
120  survey_from.x = survey_to.x = nav_survey_east - grid / 4.;
121  grid = -grid;
122  }
123 
127  } else {
130  }
131  } else { /* survey_orientation == WE */
133  survey_from.y = survey_to.y = nav_survey_south + grid / 4.;
134  } else {
135  survey_from.y = survey_to.y = nav_survey_north - grid / 4.;
136  grid = -grid;
137  }
138 
142  } else {
145  }
146  }
147  nav_survey_shift = grid;
148  sweep = grid;
149  survey_uturn = false;
151 
152  //go to start position
153  ENU_BFP_OF_REAL(survey_from_i, survey_from);
155  VECT3_COPY(navigation_target, survey_from_i);
157  NavVerticalAltitudeMode(waypoints[wp1].enu_f.z, 0.);
158  if (survey_orientation == NS) {
160  } else {
162  }
163 }
164 
166 {
167  #ifdef NAV_SURVEY_RECTANGLE_DYNAMIC
169  #endif
170 
171  static bool is_last_half = false;
172  static float survey_radius;
173  nav_survey_active = true;
174 
175  /* entry scan */ // wait for start position and altitude be reached
176  if (!nav_survey_rectangle_active && ((!nav_approaching_from(&survey_from_i, NULL, 0))
177  || (fabsf(stateGetPositionEnu_f()->z - waypoints[wp1].enu_f.z)) > 1.)) {
178  } else {
182  }
183 
184  nav_survey_west = Min(WaypointX(wp1), WaypointX(wp2));
185  nav_survey_east = Max(WaypointX(wp1), WaypointX(wp2));
186  nav_survey_south = Min(WaypointY(wp1), WaypointY(wp2));
187  nav_survey_north = Max(WaypointY(wp1), WaypointY(wp2));
188 
189  /* Update the current segment from corners' coordinates*/
190  if (SurveyGoingNorth()) {
193  } else if (SurveyGoingSouth()) {
196  } else if (SurveyGoingEast()) {
199  } else if (SurveyGoingWest()) {
202  }
203 
204  if (!survey_uturn) { /* S-N, N-S, W-E or E-W straight route */
205  /* if you like to use position croos instead of approaching uncoment this line
206  if ((stateGetPositionEnu_f()->y < nav_survey_north && SurveyGoingNorth()) ||
207  (stateGetPositionEnu_f()->y > nav_survey_south && SurveyGoingSouth()) ||
208  (stateGetPositionEnu_f()->x < nav_survey_east && SurveyGoingEast()) ||
209  (stateGetPositionEnu_f()->x > nav_survey_west && SurveyGoingWest())) {
210  */
211  /* Continue ... */
213 
214  if (!nav_approaching_from(&survey_to_i, NULL, 0)) {
215  ENU_BFP_OF_REAL(survey_from_i, survey_from);
216 
218  nav_route(&survey_from_i, &survey_to_i);
219 
220  } else {
221  if (survey_orientation == NS) {
222  /* North or South limit reached, prepare turn and next leg */
223  float x0 = survey_from.x; /* Current longitude */
224  if ((x0 + nav_survey_shift < nav_survey_west)
225  || (x0 + nav_survey_shift > nav_survey_east)) { // not room for full sweep
226  if (((x0 + (nav_survey_shift / 2)) < nav_survey_west)
227  || ((x0 + (nav_survey_shift / 2)) > nav_survey_east)) { //not room for half sweep
228  if (is_last_half) {// was last sweep half?
230  if (interleave) {
231  survey_radius = nav_survey_shift;
232  }else {
233  survey_radius = nav_survey_shift /2.;
234  }
235  is_last_half = false;
236  } else { // last sweep not half
238  if (interleave) {
239  survey_radius = nav_survey_shift /2.;
240  }else{
241  survey_radius = nav_survey_shift ;
242  }
243  }
245  } else { //room for half sweep after
246  survey_radius = nav_survey_shift / 2.;
247  is_last_half = true;
248  }
249  } else {// room for full sweep after
250  survey_radius = nav_survey_shift;
251  }
252 
253  x0 = x0 + survey_radius; /* Longitude of next leg */
254  survey_from.x = survey_to.x = x0;
255 
256  /* Swap South and North extremities */
257  float tmp = survey_from.y;
259  survey_to.y = tmp;
260 
262  waypoints[0].enu_f.x = x0;
263  waypoints[0].enu_f.y = survey_from.y;
264 
265  /* Computes the right direction */
266  if (SurveyGoingEast()) {
267  survey_radius = -survey_radius;
268  }
269  } else { /* (survey_orientation == WE) */
270  /* East or West limit reached, prepare turn and next leg */
271  /* There is a y0 declared in math.h (for ARM) !!! */
272  float my_y0 = survey_from.y; /* Current latitude */
273  if (my_y0 + nav_survey_shift < nav_survey_south
274  || my_y0 + nav_survey_shift > nav_survey_north) { // not room for full sweep
275  if (((my_y0 + (nav_survey_shift / 2)) < nav_survey_south)
276  || ((my_y0 + (nav_survey_shift / 2)) > nav_survey_north)) { //not room for half sweep
277  if (is_last_half) {// was last sweep half?
279  if (interleave) {
280  survey_radius = nav_survey_shift;
281  }else {
282  survey_radius = nav_survey_shift /2.;
283  }
284  is_last_half = false;
285  } else { // last sweep not half
287  if (interleave) {
288  survey_radius = nav_survey_shift /2.;
289  }else{
290  survey_radius = nav_survey_shift ;
291  }
292  }
294  } else { //room for half sweep after
295  survey_radius = nav_survey_shift / 2.;
296  is_last_half = true;
297  }
298  } else {// room for full sweep after
299  survey_radius = nav_survey_shift;
300  }
301 
302  my_y0 = my_y0 + survey_radius; /* latitude of next leg */
303  survey_from.y = survey_to.y = my_y0;
304 
305  /* Swap West and East extremities */
306  float tmp = survey_from.x;
308  survey_to.x = tmp;
309 
311  waypoints[0].enu_f.x = survey_from.x;
312  waypoints[0].enu_f.y = my_y0;
313 
314  /* Computes the right direction */
315  if (SurveyGoingNorth()) {
316  survey_radius = -survey_radius;
317  }
318  }
319 
320  nav_in_segment = false;
321  survey_uturn = true;
323 #ifdef DIGITAL_CAM
324  float temp;
325  if (survey_orientation == NS) {
327  } else{
329  }
330  double inteiro;
331  double fract = modf (temp , &inteiro);
332  if (fract > .5) {
333  dc_send_command(DC_SHOOT); //if last shot is more than shot_distance/2 from the corner take a picture in the corner before go to the next sweep
334  }
335 #endif
336  }
337  } else { /* START turn */
338 
339  static struct EnuCoor_f temp_f;
340  if (survey_orientation == WE) {
341  temp_f.x = waypoints[0].enu_f.x;
342  temp_f.y = waypoints[0].enu_f.y - survey_radius;
343  } else {
344  temp_f.y = waypoints[0].enu_f.y;
345  temp_f.x = waypoints[0].enu_f.x - survey_radius;
346  }
347 
348  //detect when segment has done
349  /* if you like to use position croos instead of approaching uncoment this line
350  if ( (stateGetPositionEnu_f()->y > waypoints[0].enu_f.y && ((survey_orientation == WE) && (temp_f.y < waypoints[0].enu_f.y)) )||
351  (stateGetPositionEnu_f()->y < waypoints[0].enu_f.y && ((survey_orientation == WE) && (temp_f.y > waypoints[0].enu_f.y)) )||
352  (stateGetPositionEnu_f()->x < waypoints[0].enu_f.x && ((survey_orientation == NS) && (temp_f.x > waypoints[0].enu_f.x)) )||
353  (stateGetPositionEnu_f()->x > waypoints[0].enu_f.x && ((survey_orientation == NS) && (temp_f.x < waypoints[0].enu_f.x)) ) ) {
354  */
355 
356  if (survey_orientation == WE) {
357  ENU_BFP_OF_REAL(survey_from_i, temp_f);
359  } else {
360  ENU_BFP_OF_REAL(survey_from_i, temp_f);
362  }
363  if (nav_approaching_from(&survey_to_i, NULL, 0)) {
364  survey_uturn = false;
365  nav_in_circle = false;
367  } else {
368 
369  if (survey_orientation == WE) {
370  ENU_BFP_OF_REAL(survey_from_i, temp_f);
372  } else {
373  ENU_BFP_OF_REAL(survey_from_i, temp_f);
375  }
376 
378  nav_route(&survey_from_i, &survey_to_i);
379  }
380  } /* END turn */
381 
382  } /* END entry scan */
383  return true;
384 
385 }// /* END survey_retangle */
uint16_t
unsigned short uint16_t
Definition: types.h:16
nav_in_circle
bool nav_in_circle
Definition: nav_survey_rectangle_rotorcraft.c:66
RECTANGLE_SURVEY_HEADING_NS
#define RECTANGLE_SURVEY_HEADING_NS
Definition: nav_survey_rectangle_rotorcraft.c:55
EnuCoor_i::y
int32_t y
North.
Definition: pprz_geodetic_int.h:79
survey_orientation_t
survey_orientation_t
Definition: nav_survey_rectangle_rotorcraft.h:36
EnuCoor_i::x
int32_t x
East.
Definition: pprz_geodetic_int.h:78
nav_survey_rectangle_rotorcraft_run
bool nav_survey_rectangle_rotorcraft_run(uint8_t wp1, uint8_t wp2)
Definition: nav_survey_rectangle_rotorcraft.c:165
WaypointY
#define WaypointY(_wp)
Definition: common_nav.h:46
stateGetPositionEnu_f
static struct EnuCoor_f * stateGetPositionEnu_f(void)
Get position in local ENU coordinates (float).
Definition: state.h:719
nav_approaching_from
bool nav_approaching_from(struct EnuCoor_i *wp, struct EnuCoor_i *from, int16_t approaching_time)
Proximity tests on approaching a wp.
Definition: navigation.c:262
WaypointX
#define WaypointX(_wp)
Definition: common_nav.h:45
navigation_target
struct EnuCoor_i navigation_target
Definition: navigation.c:91
survey_to
static struct EnuCoor_f survey_from survey_to
Definition: nav_survey_rectangle_rotorcraft.c:69
SurveyGoingEast
#define SurveyGoingEast()
Definition: nav_survey_rectangle_rotorcraft.c:80
waypoints
struct point waypoints[NB_WAYPOINT]
size == nb_waypoint, waypoint 0 is a dummy waypoint
Definition: common_nav.c:38
dc_distance_interval
float dc_distance_interval
AutoShoot photos on distance to last shot in meters.
Definition: dc.c:83
EnuCoor_f::y
float y
in meters
Definition: pprz_geodetic_float.h:74
SurveyGoingWest
#define SurveyGoingWest()
Definition: nav_survey_rectangle_rotorcraft.c:81
telemetry.h
uart.h
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
sweep
float sweep
Definition: nav_survey_rectangle_rotorcraft.c:62
nav_in_segment
bool nav_in_segment
Definition: nav_survey_rectangle_rotorcraft.c:65
rectangle_survey_sweep_num
uint16_t rectangle_survey_sweep_num
Definition: nav_survey_rectangle_rotorcraft.c:64
dc_send_command
void dc_send_command(uint8_t cmd)
Send Command To Camera.
Definition: atmega_i2c_cam_ctrl.c:41
survey_orientation
static survey_orientation_t survey_orientation
Definition: nav_survey_rectangle_rotorcraft.c:73
dev
static const struct usb_device_descriptor dev
Definition: usb_ser_hw.c:74
LINE_STOP_FUNCTION
#define LINE_STOP_FUNCTION
Definition: nav_survey_rectangle_rotorcraft.c:89
nav_survey_south
float nav_survey_south
Definition: nav_survey_rectangle_rotorcraft.c:76
nav_survey_rectangle_rotorcraft.h
USE_INTERLEAVE
#define USE_INTERLEAVE
Definition: nav_survey_rectangle_rotorcraft.c:38
NS
@ NS
Definition: nav_survey_rectangle_rotorcraft.h:36
nav_route
void nav_route(struct EnuCoor_i *wp_start, struct EnuCoor_i *wp_end)
Definition: navigation.c:589
uint8_t
unsigned char uint8_t
Definition: types.h:14
register_periodic_telemetry
int8_t register_periodic_telemetry(struct periodic_telemetry *_pt, uint8_t _id, telemetry_cb _cb)
Register a telemetry callback function.
Definition: telemetry.c:46
SurveyGoingNorth
#define SurveyGoingNorth()
Definition: nav_survey_rectangle_rotorcraft.c:78
point::x
float x
Definition: common_nav.h:40
LINE_START_FUNCTION
#define LINE_START_FUNCTION
Definition: nav_survey_rectangle_rotorcraft.c:86
EnuCoor_f
vector in East North Up coordinates Units: meters
Definition: pprz_geodetic_float.h:72
survey_to_i
static struct EnuCoor_i survey_from_i survey_to_i
Definition: nav_survey_rectangle_rotorcraft.c:70
interleave
bool interleave
Definition: nav_survey_rectangle_rotorcraft.c:67
RECTANGLE_SURVEY_DEFAULT_SWEEP
#define RECTANGLE_SURVEY_DEFAULT_SWEEP
Definition: nav_survey_rectangle_rotorcraft.c:32
survey_uturn
static bool survey_uturn
Definition: nav_survey_rectangle_rotorcraft.c:72
nav_survey_west
float nav_survey_west
Definition: nav_survey_rectangle_rotorcraft.c:76
nav_survey_rectangle_rotorcraft_init
void nav_survey_rectangle_rotorcraft_init(void)
Definition: nav_survey_rectangle_rotorcraft.c:100
nav_survey_east
float nav_survey_east
Definition: nav_survey_rectangle_rotorcraft.c:76
nav_survey_rectangle_active
static bool nav_survey_rectangle_active
Definition: nav_survey_rectangle_rotorcraft.c:63
nav_survey_shift
float nav_survey_shift
Definition: nav_survey_rectangle_rotorcraft.c:75
send_survey
static void send_survey(struct transport_tx *trans, struct link_device *dev)
Definition: nav_survey_rectangle_rotorcraft.c:92
DC_SHOOT
@ DC_SHOOT
Definition: dc.h:100
RECTANGLE_SURVEY_HEADING_WE
#define RECTANGLE_SURVEY_HEADING_WE
Definition: nav_survey_rectangle_rotorcraft.c:59
nav_survey_active
bool nav_survey_active
Definition: nav.c:89
WE
@ WE
Definition: nav_survey_rectangle_rotorcraft.h:36
navigation.h
point::y
float y
Definition: common_nav.h:41
nav_survey_rectangle_rotorcraft_setup
void nav_survey_rectangle_rotorcraft_setup(uint8_t wp1, uint8_t wp2, float grid, survey_orientation_t so)
Definition: nav_survey_rectangle_rotorcraft.c:107
SurveyGoingSouth
#define SurveyGoingSouth()
Definition: nav_survey_rectangle_rotorcraft.c:79
nav_set_heading_deg
void nav_set_heading_deg(float deg)
Set nav_heading in degrees.
Definition: navigation.c:496
EnuCoor_i::z
int32_t z
Up.
Definition: pprz_geodetic_int.h:80
EnuCoor_f::x
float x
in meters
Definition: pprz_geodetic_float.h:73
Max
#define Max(x, y)
Definition: main_fbw.c:53
state.h
HORIZONTAL_MODE_ROUTE
#define HORIZONTAL_MODE_ROUTE
Definition: nav.h:86
nav_survey_north
float nav_survey_north
Definition: nav_survey_rectangle_rotorcraft.c:76
survey_from
static struct point survey_from
Definition: nav_survey_rectangle.c:35
horizontal_mode
uint8_t horizontal_mode
Definition: nav.c:71
DefaultPeriodic
#define DefaultPeriodic
Set default periodic telemetry.
Definition: telemetry.h:66
EnuCoor_i
vector in East North Up coordinates
Definition: pprz_geodetic_int.h:77
VECT3_COPY
#define VECT3_COPY(_a, _b)
Definition: pprz_algebra.h:140
NavVerticalAltitudeMode
#define NavVerticalAltitudeMode(_alt, _pre_climb)
Set the vertical mode to altitude control with the specified altitude setpoint and climb pre-command.
Definition: nav.h:185
ENU_BFP_OF_REAL
#define ENU_BFP_OF_REAL(_o, _i)
Definition: pprz_geodetic_int.h:194
Min
#define Min(x, y)
Definition: esc_dshot.c:85