Paparazzi UAS  v5.2.2_stable-0-gd6b9f29
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
dc.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2010 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  */
22 
23 
37 #ifndef DC_H
38 #define DC_H
39 
40 #include "float.h"
41 #include "std.h"
42 #include "led.h"
43 #include "state.h"
45 #include "generated/airframe.h"
46 #include "subsystems/gps.h"
47 
48 /* number of images taken since the last change of dc_mode */
49 extern uint16_t dc_gps_count;
50 
51 /* distance between dc shots in meters */
52 extern float dc_gps_dist;
53 
54 extern float dc_gps_next_dist;
55 
56 /* angle a where first image will be taken at a + delta */
57 extern float dc_circle_start_angle;
58 
59 /* angle between dc shots in degree */
60 extern float dc_circle_interval;
61 
62 extern float dc_circle_max_blocks;
63 
64 /* point of reference for the distance based mode */
65 extern float dc_gps_x, dc_gps_y;
66 
67 extern float dc_circle_last_block;
68 
69 extern bool_t dc_probing;
70 
72 
73 /* camera angle */
74 extern float dc_cam_angle;
75 extern uint8_t dc_cam_tracing;
76 
77 /* Generic Set of Digital Camera Commands */
78 typedef enum {
80 
81  DC_HOLD = 13,
82  DC_SHOOT = 32,
83 
84  DC_WIDER = 'w',
85  DC_TALLER = 't',
86 
87  DC_UP = 'u',
88  DC_DOWN = 'd',
89  DC_CENTER = 'c',
90  DC_LEFT = 'l',
91  DC_RIGHT = 'r',
92 
93  DC_MENU = 'm',
94  DC_HOME = 'h',
95  DC_PLAY = 'p',
96 
97  DC_ON = 'O',
98  DC_OFF = 'o',
99 
101 
102 /* Send Command To Camera */
103 extern void dc_send_command(uint8_t cmd);
104 
105 /* Auotmatic Digital Camera Photo Triggering */
106 typedef enum {
115 
116 /* AutoShoot photos every X quarter_second */
118 
119 /* AutoShoot photos on a X meter Local Tangent Plane Grid */
121 
122 /* Send Down the coordinates of where the photo was taken */
123 #ifdef SENSOR_SYNC_SEND
124 void dc_send_shot_position(void);
125 #else
126 #define dc_send_shot_position() {}
127 #endif
128 
129 /* Macro value used to indicate a discardable argument */
130 #ifndef DC_IGNORE
131 #define DC_IGNORE FLT_MAX
132 #endif
133 
134 /* Default values for buffer control */
135 #ifndef DC_IMAGE_BUFFER
136 #define DC_IMAGE_BUFFER 65535
137 #endif
138 
139 #ifndef DC_IMAGE_BUFFER_TPI
140 #define DC_IMAGE_BUFFER_TPI 0
141 #endif
142 
143 /******************************************************************
144  * FUNCTIONS
145  *****************************************************************/
156 extern uint8_t dc_circle(float interval, float start);
157 
158 #define dc_Circle(interval) dc_circle(interval, DC_IGNORE)
159 
176 extern uint8_t dc_survey(float interval, float x, float y);
177 
178 #define dc_Survey(interval) dc_survey(interval, DC_IGNORE, DC_IGNORE)
179 
180 
185 extern uint8_t dc_stop(void);
186 
187 #define dc_Stop(_) dc_stop()
188 
194 extern uint8_t dc_info(void);
195 
196 
197 /* get settings */
198 static inline void dc_init(void)
199 {
200 #ifdef DC_AUTOSHOOT_QUARTERSEC_PERIOD
201  dc_autoshoot_quartersec_period = DC_AUTOSHOOT_QUARTERSEC_PERIOD;
202 #endif
203 #ifdef DC_AUTOSHOOT_METER_GRID
204  dc_autoshoot_meter_grid = DC_AUTOSHOOT_METER_GRID;
205 #endif
206 }
207 
208 #if 0
209 /* shoot on grid */
210 static inline void dc_shot_on_utm_north_close_to_100m_grid( void )
211 {
212  uint32_t dist_to_100m_grid = (gps.utm_pos.north / 100) % 100;
213  if (dist_to_100m_grid < dc_autoshoot_meter_grid || 100 - dist_to_100m_grid < dc_autoshoot_meter_grid) {
215  }
216 }
217 #endif
218 
219 static float dim_mod(float a, float b, float m) {
220  if (a < b) {
221  float tmp = a;
222  a = b;
223  b = tmp;
224  }
225  return fminf(a-b, b+m-a);
226 }
227 
228 /* periodic 4Hz function */
229 static inline void dc_periodic_4Hz( void )
230 {
231  static uint8_t dc_shutter_timer = 0;
232 
233  switch (dc_autoshoot) {
234 
236  if (dc_shutter_timer) {
237  dc_shutter_timer--;
238  } else {
239  dc_shutter_timer = dc_autoshoot_quartersec_period;
241  }
242  break;
243 
245  {
246  uint32_t dist_to_100m_grid = (gps.utm_pos.north / 100) % 100;
247  if (dist_to_100m_grid < dc_autoshoot_meter_grid || 100 - dist_to_100m_grid < dc_autoshoot_meter_grid)
248  {
250  }
251  }
252  break;
253 
254  case DC_AUTOSHOOT_CIRCLE: {
255  float course = DegOfRad(stateGetNedToBodyEulers_f()->psi) - dc_circle_start_angle;
256  if (course < 0.)
257  course += 360.;
258  float current_block = floorf(course/dc_circle_interval);
259 
260  if (dc_probing) {
261  if (current_block == dc_circle_last_block) {
262  dc_probing = FALSE;
263  }
264  }
265 
266  if (dim_mod(current_block, dc_circle_last_block, dc_circle_max_blocks) == 1) {
267  dc_gps_count++;
268  dc_circle_last_block = current_block;
270  }
271  }
272  break;
273 
274  case DC_AUTOSHOOT_SURVEY : {
275  float dist_x = dc_gps_x - stateGetPositionEnu_f()->x;
276  float dist_y = dc_gps_y - stateGetPositionEnu_f()->y;
277 
278  if (dc_probing) {
279  if (dist_x*dist_x + dist_y*dist_y < dc_gps_dist*dc_gps_dist) {
280  dc_probing = FALSE;
281  }
282  }
283 
284  if (dist_x*dist_x + dist_y*dist_y >= dc_gps_next_dist*dc_gps_next_dist) {
285  dc_gps_next_dist += dc_gps_dist;
286  dc_gps_count++;
288  }
289  }
290  break;
291 
292  default :
294  }
295 }
296 
297 
298 
299 
300 #endif // DC_H
unsigned short uint16_t
Definition: types.h:16
Definition: dc.h:87
dc_autoshoot_type
Definition: dc.h:106
#define dc_send_shot_position()
Definition: dc.h:126
static struct FloatEulers * stateGetNedToBodyEulers_f(void)
Get vehicle body attitude euler angles (float).
Definition: state.h:1027
uint8_t dc_circle(float interval, float start)
Sets the dc control in circle mode.
Definition: dc.c:109
dc_command_type
Definition: dc.h:78
float dc_gps_next_dist
Definition: dc.c:40
void dc_send_command(uint8_t cmd)
Definition: dc.h:93
float dc_gps_y
Definition: dc.c:42
Definition: dc.h:95
float dc_cam_angle
Definition: dc.c:32
uint8_t dc_info(void)
Send an info message containing information about position, course, buffer and all other internal var...
Definition: dc.c:86
static struct EnuCoor_f * stateGetPositionEnu_f(void)
Get position in local ENU coordinates (float).
Definition: state.h:672
float dc_circle_interval
Definition: dc.c:34
float y
in meters
uint8_t dc_survey(float interval, float x, float y)
Sets the dc control in distance mode.
Definition: dc.c:130
#define FALSE
Definition: imu_chimu.h:141
uint8_t dc_autoshoot_quartersec_period
Definition: dc.c:28
float dc_gps_x
Definition: dc.c:41
Definition: dc.h:82
Definition: dc.h:85
float dc_gps_dist
Definition: dc.c:39
uint8_t dc_cam_tracing
Definition: dc.c:31
Definition: dc.h:81
float dc_circle_last_block
Definition: dc.c:36
dc_autoshoot_type dc_autoshoot
Definition: dc.c:29
uint8_t dc_autoshoot_meter_grid
Definition: dc.c:27
Device independent GPS code (interface)
Definition: dc.h:91
unsigned long uint32_t
Definition: types.h:18
static void dc_periodic_4Hz(void)
Definition: dc.h:229
float x
in meters
Definition: dc.h:84
Definition: dc.h:98
int32_t north
in centimeters
uint8_t dc_stop(void)
Sets the dc control in inactive mode, stopping all current actions.
Definition: dc.c:150
bool_t dc_probing
Definition: dc.c:44
Definition: dc.h:88
float dc_circle_max_blocks
Definition: dc.c:37
static float dim_mod(float a, float b, float m)
Definition: dc.h:219
unsigned char uint8_t
Definition: types.h:14
float dc_circle_start_angle
Definition: dc.c:35
API to get/set the generic vehicle states.
Definition: dc.h:94
Definition: dc.h:90
uint8_t dc_buffer_timer
Definition: dc.h:89
arch independent LED (Light Emitting Diodes) API
struct UtmCoor_i utm_pos
position in UTM (north,east: cm; alt: mm over ellipsoid)
Definition: gps.h:66
uint16_t dc_gps_count
Definition: dc.c:30
Definition: dc.h:97
struct GpsState gps
global GPS state
Definition: gps.c:41
static void dc_init(void)
Definition: dc.h:198