Paparazzi UAS  v5.8.2_stable-0-g6260b7c
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
nav_flower.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2008-2013 The Paparazzi Team
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 
28 #include "modules/nav/nav_flower.h"
29 
31 #include "state.h"
32 #include "autopilot.h"
33 #include "generated/flight_plan.h"
34 
35 /************** Flower Navigation **********************************************/
36 
44 static float CircleX;
45 static float CircleY;
46 static float Fly2X;
47 static float Fly2Y;
48 static float FlyFromX;
49 static float FlyFromY;
50 static float TransCurrentX;
51 static float TransCurrentY;
52 static float EdgeCurrentX;
53 static float EdgeCurrentY;
54 static float DistanceFromCenter;
55 static float FlowerTheta;
56 static float Flowerradius;
57 static uint8_t Center;
58 static uint8_t Edge;
59 
60 bool_t nav_flower_setup(uint8_t CenterWP, uint8_t EdgeWP)
61 {
62  Center = CenterWP;
63  Edge = EdgeWP;
64 
67 
69 
73 
74  FlowerTheta = atan2f(TransCurrentY, TransCurrentX);
75  Fly2X = Flowerradius * cosf(FlowerTheta + 3.14) + WaypointX(Center);
76  Fly2Y = Flowerradius * sinf(FlowerTheta + 3.14) + WaypointY(Center);
79 
82  } else {
84  }
85 
86  CircleX = 0;
87  CircleY = 0;
88  return FALSE;
89 }
90 
91 bool_t nav_flower_run(void)
92 {
96 
97  bool_t InCircle = TRUE;
98  float CircleTheta;
99 
101  InCircle = FALSE;
102  }
103 
104  NavVerticalAutoThrottleMode(0); /* No pitch */
106 
107  switch (CFlowerStatus) {
108  case Outside:
110  if (InCircle) {
112  FlowerTheta = atan2f(TransCurrentY, TransCurrentX);
113  Fly2X = Flowerradius * cosf(FlowerTheta + 3.14) + WaypointX(Center);
114  Fly2Y = Flowerradius * sinf(FlowerTheta + 3.14) + WaypointY(Center);
117  nav_init_stage();
118  }
119  break;
120  case FlowerLine:
122  if (!InCircle) {
124  CircleTheta = nav_radius / Flowerradius;
125  CircleX = Flowerradius * cosf(FlowerTheta + 3.14 - CircleTheta) + WaypointX(Center);
126  CircleY = Flowerradius * sinf(FlowerTheta + 3.14 - CircleTheta) + WaypointY(Center);
127  nav_init_stage();
128  }
129  break;
130  case Circle:
132  if (InCircle) {
138  } else {
140  }
141  FlowerTheta = atan2f(TransCurrentY, TransCurrentX);
142  Fly2X = Flowerradius * cosf(FlowerTheta + 3.14) + WaypointX(Center);
143  Fly2Y = Flowerradius * sinf(FlowerTheta + 3.14) + WaypointY(Center);
146  nav_init_stage();
147  }
148  break;
149 
150  default:
151  break;
152  }
153  return TRUE;
154 }
static struct EnuCoor_f * stateGetPositionEnu_f(void)
Get position in local ENU coordinates (float).
Definition: state.h:702
#define FALSE
Definition: std.h:5
#define TRUE
Definition: std.h:4
#define WaypointX(_wp)
Definition: common_nav.h:45
float x
in meters
#define WaypointY(_wp)
Definition: common_nav.h:46
unsigned char uint8_t
Definition: types.h:14
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 y
in meters