Paparazzi UAS  v5.0.5_stable-7-g4b8bbb7
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
common_nav.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2007-2009 ENAC, Pascal Brisset, Antoine Drouin
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 "generated/flight_plan.h"
29 #include "subsystems/gps.h"
31 
34 
36 
37 const uint8_t nb_waypoint = NB_WAYPOINT;
38 struct point waypoints[NB_WAYPOINT] = WAYPOINTS;
39 
40 float ground_alt;
41 
42 int32_t nav_utm_east0 = NAV_UTM_EAST0;
43 int32_t nav_utm_north0 = NAV_UTM_NORTH0;
44 uint8_t nav_utm_zone0 = NAV_UTM_ZONE0;
45 float max_dist_from_home = MAX_DIST_FROM_HOME;
46 
51  struct EnuCoor_f* pos = stateGetPositionEnu_f();
52  float ph_x = waypoints[WP_HOME].x - pos->x;
53  float ph_y = waypoints[WP_HOME].y - pos->y;
54  dist2_to_home = ph_x*ph_x + ph_y *ph_y;
55  too_far_from_home = dist2_to_home > (MAX_DIST_FROM_HOME*MAX_DIST_FROM_HOME);
56 #if defined InAirspace
57  too_far_from_home = too_far_from_home || !(InAirspace(pos_x, pos_y));
58 #endif
59 }
60 
61 
62 static float previous_ground_alt;
63 
65 unit_t nav_reset_reference( void ) {
66 #ifdef GPS_USE_LATLONG
67  /* Set the real UTM zone */
68  nav_utm_zone0 = (DegOfRad(gps.lla_pos.lon/1e7)+180) / 6 + 1;
69 
70  /* Recompute UTM coordinates in this zone */
71  struct LlaCoor_f lla;
72  lla.lat = gps.lla_pos.lat/1e7;
73  lla.lon = gps.lla_pos.lon/1e7;
74  struct UtmCoor_f utm;
75  utm.zone = nav_utm_zone0;
76  utm_of_lla_f(&utm, &lla);
77  nav_utm_east0 = utm.east;
78  nav_utm_north0 = utm.north;
79 #else
83 #endif
84 
85  // reset state UTM ref
86  struct UtmCoor_f utm0 = { nav_utm_north0, nav_utm_east0, 0., nav_utm_zone0 };
88 
90  ground_alt = gps.hmsl/1000.;
91  return 0;
92 }
93 
95 unit_t nav_update_waypoints_alt( void ) {
96  uint8_t i;
97  for(i = 0; i < NB_WAYPOINT; i++) {
98  waypoints[i].a += ground_alt - previous_ground_alt;
99  }
100  return 0;
101 }
102 
104  RunOnceEvery(4, { stage_time++; block_time++; });
105 }
106 
107 void nav_move_waypoint(uint8_t wp_id, float ux, float uy, float alt) {
108  if (wp_id < nb_waypoint) {
109  float dx, dy;
110  dx = ux - nav_utm_east0 - waypoints[WP_HOME].x;
111  dy = uy - nav_utm_north0 - waypoints[WP_HOME].y;
112  BoundAbs(dx, max_dist_from_home);
113  BoundAbs(dy, max_dist_from_home);
114  waypoints[wp_id].x = waypoints[WP_HOME].x + dx;
115  waypoints[wp_id].y = waypoints[WP_HOME].y + dy;
116  waypoints[wp_id].a = alt;
117  }
118 }
unit_t nav_update_waypoints_alt(void)
Shift altitude of the waypoint according to a new ground altitude.
Definition: common_nav.c:95
uint16_t block_time
struct LlaCoor_i lla_pos
position in LLA (lat,lon: rad*1e7; alt: mm over ellipsoid)
Definition: gps.h:65
int32_t lat
in radians*1e7
float ground_alt
size == nb_waypoint, waypoint 0 is a dummy waypoint
Definition: common_nav.c:40
uint8_t zone
UTM zone number.
void compute_dist2_to_home(void)
Computes square distance to the HOME waypoint potentially sets too_far_from_home. ...
Definition: common_nav.c:50
float a
Definition: common_nav.h:42
uint8_t nav_utm_zone0
Definition: common_nav.c:44
int32_t hmsl
height above mean sea level in mm
Definition: gps.h:67
static float previous_ground_alt
Definition: common_nav.c:62
void nav_move_waypoint(uint8_t wp_id, float ux, float uy, float alt)
Definition: common_nav.c:107
float lat
in radians
float dist2_to_home
Definition: common_nav.c:32
static struct EnuCoor_f * stateGetPositionEnu_f(void)
Get position in local ENU coordinates (float).
Definition: state.h:672
float y
in meters
vector in Latitude, Longitude and Altitude
Paparazzi floating point math for geodetic calculations.
uint8_t zone
UTM zone number.
void common_nav_periodic_task_4Hz()
Definition: common_nav.c:103
int32_t nav_utm_north0
Definition: common_nav.c:43
float north
in meters
Device independent GPS code (interface)
position in UTM coordinates Units: meters
unit_t nav_reset_reference(void)
Reset the geographic reference to the current GPS fix.
Definition: common_nav.c:65
float x
in meters
int32_t north
in centimeters
float max_dist_from_home
Definition: common_nav.c:45
uint16_t stage_time
In s.
const uint8_t nb_waypoint
Definition: common_nav.c:37
signed long int32_t
Definition: types.h:19
int32_t east
in centimeters
unsigned char uint8_t
Definition: types.h:14
int32_t lon
in radians*1e7
bool_t too_far_from_home
Definition: common_nav.c:35
int32_t nav_utm_east0
Definition: common_nav.c:42
struct point waypoints[NB_WAYPOINT]
Definition: common_nav.c:38
float y
Definition: common_nav.h:41
float dist2_to_wp
Definition: common_nav.c:33
struct UtmCoor_i utm_pos
position in UTM (north,east: cm; alt: mm over ellipsoid)
Definition: gps.h:66
vector in East North Up coordinates Units: meters
float lon
in radians
float east
in meters
float alt
in meters above WGS84 reference ellipsoid
static void stateSetLocalUtmOrigin_f(struct UtmCoor_f *utm_def)
Set the local (flat earth) coordinate frame origin from UTM (float).
Definition: state.h:459
struct GpsState gps
global GPS state
Definition: gps.c:33
float x
Definition: common_nav.h:40
void utm_of_lla_f(struct UtmCoor_f *utm, struct LlaCoor_f *lla)