Paparazzi UAS v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
nav_line_osam.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2008-2012 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
31
33#include "state.h"
34#include "autopilot.h"
35#include "generated/flight_plan.h"
36
37#ifndef LINE_START_FUNCTION
38#define LINE_START_FUNCTION {}
39#endif
40#ifndef LINE_STOP_FUNCTION
41#define LINE_STOP_FUNCTION {}
42#endif
43
44struct Point2D {float x; float y;};
45
47
49static struct Point2D FLCircle;
50static struct Point2D FLFROMWP;
51static struct Point2D FLTOWP;
52static float FLQDR;
53static float FLRadius;
54
55/*
56 Translates point so (transX, transY) are (0,0) then rotates the point around z by Zrot
57*/
58static void TranslateAndRotateFromWorld(struct Point2D *p, float Zrot, float transX, float transY)
59{
60 float temp;
61
62 p->x = p->x - transX;
63 p->y = p->y - transY;
64
65 temp = p->x;
66 p->x = p->x * cosf(Zrot) + p->y * sinf(Zrot);
67 p->y = -temp * sinf(Zrot) + p->y * cosf(Zrot);
68}
69
70
72{
73 struct Point2D V;
74 struct Point2D P;
75 float dv;
76
77 switch (CFLStatus) {
78 case FLInitialize:
79
80 //Translate WPs so From_WP is origin
83
84 //Record Aircraft Position
87
88 //Rotate Aircraft Position so V is aligned with x axis
90
91 //Find which side of the flight line the aircraft is on
92 if (P.y > 0) {
93 FLRadius = -radius;
94 } else {
95 FLRadius = radius;
96 }
97
98 //Find unit vector of V
99 dv = sqrtf(V.x * V.x + V.y * V.y);
100 V.x = V.x / dv;
101 V.y = V.y / dv;
102
103 //Find begin and end points of flight line
104 FLFROMWP.x = -V.x * Space_Before;
105 FLFROMWP.y = -V.y * Space_Before;
106
107 FLTOWP.x = V.x * (dv + Space_After);
108 FLTOWP.y = V.y * (dv + Space_After);
109
110 //Find center of circle
111 FLCircle.x = FLFROMWP.x + V.y * FLRadius;
112 FLCircle.y = FLFROMWP.y - V.x * FLRadius;
113
114 //Find the angle to exit the circle
116
117 //Translate back
120
123
126
129
130 break;
131
132 case FLCircleS:
133
134 NavVerticalAutoThrottleMode(0); /* No pitch */
136
138
139 if (NavCircleCount() > 0.2 && NavQdrCloseTo(DegOfRad(FLQDR))) {
143 }
144 break;
145
146 case FLLine:
147
148 NavVerticalAutoThrottleMode(0); /* No pitch */
150
152
153
158 }
159 break;
160
161 case FLFinished:
164 return false;
165 break;
166
167 default:
168 break;
169 }
170 return true;
171
172}
173
175
177{
178 if (First_WP < Last_WP) {
180
181 if (CFLStatus == FLInitialize) {
182 FLBlockCount++;
183 if (First_WP + FLBlockCount >= Last_WP) {
184 FLBlockCount = 0;
185 return false;
186 }
187 }
188 } else {
190
191 if (CFLStatus == FLInitialize) {
192 FLBlockCount++;
193 if (First_WP - FLBlockCount <= Last_WP) {
194 FLBlockCount = 0;
195 return false;
196 }
197 }
198 }
199
200 return true;
201}
Core autopilot interface common to all firmwares.
struct point waypoints[NB_WAYPOINT]
size == nb_waypoint, waypoint 0 is a dummy waypoint
Definition common_nav.c:44
#define WaypointX(_wp)
Definition common_nav.h:45
#define WaypointY(_wp)
Definition common_nav.h:46
static struct EnuCoor_f * stateGetPositionEnu_f(void)
Get position in local ENU coordinates (float).
Definition state.h:848
static float p[2][2]
uint16_t foo
Definition main_demo5.c:58
bool 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.
Definition nav.c:325
void nav_init_stage(void)
needs to be implemented by fixedwing and rotorcraft seperately
Definition nav.c:92
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.
Definition nav.c:382
void nav_circle_XY(float x, float y, float radius)
Navigates around (x, y).
Definition nav.c:108
Fixedwing Navigation library.
#define NavQdrCloseTo(x)
True if x (in degrees) is close to the current QDR (less than 10 degrees)
Definition nav.h:161
#define NavCircleCount()
Definition nav.h:155
#define NavVerticalAltitudeMode(_alt, _pre_climb)
Set the vertical mode to altitude control with the specified altitude setpoint and climb pre-command.
Definition nav.h:191
#define NavVerticalAutoThrottleMode(_pitch)
Set the climb control to auto-throttle with the specified pitch pre-command.
Definition nav.h:177
static struct Point2D FLFROMWP
static enum FLStatus CFLStatus
#define LINE_STOP_FUNCTION
static struct Point2D FLTOWP
static uint8_t FLBlockCount
#define LINE_START_FUNCTION
FLStatus
@ FLLine
@ FLInitialize
@ FLCircleS
@ FLFinished
static void TranslateAndRotateFromWorld(struct Point2D *p, float Zrot, float transX, float transY)
static float FLQDR
static float FLRadius
bool nav_line_osam_block_run(uint8_t First_WP, uint8_t Last_WP, float radius, float Space_Before, float Space_After)
bool nav_line_osam_run(uint8_t From_WP, uint8_t To_WP, float radius, float Space_Before, float Space_After)
static struct Point2D FLCircle
float x
float y
float y
in meters
float x
in meters
API to get/set the generic vehicle states.
static float P[3][3]
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.