Paparazzi UAS  v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
dc.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2010-2014 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 
35 #include "dc.h"
36 
37 // for waypoints, include correct header until we have unified API
38 #ifdef FIXEDWING_FIRMWARE
39 #include "modules/nav/common_nav.h"
40 #else
42 #endif
43 
44 #include "mcu_periph/sys_time.h"
45 
47 #ifndef DC_AUTOSHOOT_PERIOD
48 #define DC_AUTOSHOOT_PERIOD 1.0
49 #endif
50 
52 #ifndef DC_AUTOSHOOT_DISTANCE_INTERVAL
53 #define DC_AUTOSHOOT_DISTANCE_INTERVAL 50
54 #endif
55 
57 #ifndef DC_AUTOSHOOT_DISTANCE_INIT
58 #define DC_AUTOSHOOT_DISTANCE_INIT 0
59 #endif
60 
62 #ifndef DC_AUTOSHOOT_SURVEY_INTERVAL
63 #define DC_AUTOSHOOT_SURVEY_INTERVAL 50
64 #endif
65 
66 // Variables with boot defaults
70 float dc_cam_angle = 0;
71 
76 
78 float dc_gps_next_dist = 0;
79 float dc_gps_x = 0;
80 float dc_gps_y = 0;
81 
82 static struct FloatVect2 last_shot_pos = {0.0, 0.0};
85 
87 #ifndef DC_SHOT_SYNC_SEND
88 #define DC_SHOT_SYNC_SEND 1
89 #endif
90 
91 #if DC_SHOT_SYNC_SEND
92 
94 
95 #include "mcu_periph/uart.h"
96 #include "pprzlink/messages.h"
98 #include "state.h"
99 #include "modules/gps/gps.h"
100 #if DC_SHOT_EXTRA_DL
102 #endif
103 
105 {
106  // angles in decideg
107  int16_t phi = DegOfRad(stateGetNedToBodyEulers_f()->phi * 10.0f);
108  int16_t theta = DegOfRad(stateGetNedToBodyEulers_f()->theta * 10.0f);
109  int16_t psi = DegOfRad(stateGetNedToBodyEulers_f()->psi * 10.0f);
110  // course in decideg
111  int16_t course = DegOfRad(stateGetHorizontalSpeedDir_f()) * 10;
112  // ground speed in cm/s
114  int16_t photo_nr = -1;
115 
117  dc_photo_nr++;
118  photo_nr = dc_photo_nr;
119  }
120 
121 #if DC_SHOT_EXTRA_DL
122  // send a message on second datalink first
123  // (for instance an embedded CPU)
124  DOWNLINK_SEND_DC_SHOT(extra_pprz_tp, EXTRA_DOWNLINK_DEVICE,
125  &photo_nr,
126  &stateGetPositionLla_i()->lat,
127  &stateGetPositionLla_i()->lon,
128  &stateGetPositionLla_i()->alt,
129  &gps.hmsl,
130  &phi,
131  &theta,
132  &psi,
133  &course,
134  &speed,
135  &gps.tow);
136 #endif
137  DOWNLINK_SEND_DC_SHOT(DefaultChannel, DefaultDevice,
138  &photo_nr,
139  &stateGetPositionLla_i()->lat,
140  &stateGetPositionLla_i()->lon,
141  &stateGetPositionLla_i()->alt,
142  &gps.hmsl,
143  &phi,
144  &theta,
145  &psi,
146  &course,
147  &speed,
148  &gps.tow);
149 }
150 #else
151 void dc_send_shot_position(void)
152 {
153 }
154 #endif /* DC_SHOT_SYNC_SEND */
155 
156 void dc_init(void)
157 {
161 }
162 
164 {
165 #ifdef DOWNLINK_SEND_DC_INFO
166  float course = DegOfRad(stateGetNedToBodyEulers_f()->psi);
168  uint8_t shutter = dc_autoshoot_period * 10;
169  DOWNLINK_SEND_DC_INFO(DefaultChannel, DefaultDevice,
170  &mode,
171  &stateGetPositionLla_i()->lat,
172  &stateGetPositionLla_i()->lon,
173  &stateGetPositionLla_i()->alt,
174  &course,
175  &dc_photo_nr,
178  &dc_gps_x,
179  &dc_gps_y,
183  &dc_gps_count,
184  &shutter);
185 #endif
186  return 0;
187 }
188 
189 void dc_send_command_common(uint8_t cmd __attribute__((unused)))
190 {
191 #if DC_SHOT_EXTRA_DL
192  uint8_t tab[] = { cmd };
193  uint8_t dst_id = 0;
194  DOWNLINK_SEND_PAYLOAD_COMMAND(extra_pprz_tp, EXTRA_DOWNLINK_DEVICE, &dst_id, 1, tab);
195 #endif
196 }
197 
198 
199 /* shoot on distance */
200 uint8_t dc_distance(float interval)
201 {
203  dc_gps_count = 0;
204  dc_distance_interval = interval;
205  last_shot_pos.x = 0;
206  last_shot_pos.y = 0;
207 
208  dc_info();
209  return 0;
210 }
211 
212 /* shoot on circle */
213 uint8_t dc_circle(float interval, float start)
214 {
216  dc_gps_count = 0;
217  dc_circle_interval = fmodf(fmaxf(interval, 1.), 360.);
218 
219  if (start == DC_IGNORE) {
220  start = DegOfRad(stateGetNedToBodyEulers_f()->psi);
221  }
222 
223  dc_circle_start_angle = fmodf(start, 360.);
224  if (start < 0.) {
225  start += 360.;
226  }
227  //dc_circle_last_block = floorf(dc_circle_start_angle/dc_circle_interval);
229  dc_circle_max_blocks = floorf(360. / dc_circle_interval);
230  dc_info();
231  return 0;
232 }
233 
234 /* shoot on survey */
235 uint8_t dc_survey(float interval, float x, float y)
236 {
238  dc_gps_count = 0;
239  dc_survey_interval = interval;
240 
241  if (x == DC_IGNORE && y == DC_IGNORE) {
244  } else if (y == DC_IGNORE) {
245  uint8_t wp = (uint8_t)x;
246  dc_gps_x = WaypointX(wp);
247  dc_gps_y = WaypointY(wp);
248  } else {
249  dc_gps_x = x;
250  dc_gps_y = y;
251  }
253  dc_info();
254  return 0;
255 }
256 
258 {
260  dc_info();
261  return 0;
262 }
263 
264 static float dim_mod(float a, float b, float m)
265 {
266  if (a < b) {
267  float tmp = a;
268  a = b;
269  b = tmp;
270  }
271  return fminf(a - b, b + m - a);
272 }
273 
274 void dc_periodic(void)
275 {
276  static float last_shot_time = 0.;
277 
278  switch (dc_autoshoot) {
279 
280  case DC_AUTOSHOOT_PERIODIC: {
281  float now = get_sys_time_float();
282  if (now - last_shot_time > dc_autoshoot_period) {
283  last_shot_time = now;
285  }
286  }
287  break;
288 
289  case DC_AUTOSHOOT_DISTANCE: {
290  struct FloatVect2 cur_pos;
291  cur_pos.x = stateGetPositionEnu_f()->x;
292  cur_pos.y = stateGetPositionEnu_f()->y;
293  struct FloatVect2 delta_pos;
294  VECT2_DIFF(delta_pos, cur_pos, last_shot_pos);
295  float dist_to_last_shot = float_vect2_norm(&delta_pos);
296  if (dist_to_last_shot > dc_distance_interval) {
297  dc_gps_count++;
299  VECT2_COPY(last_shot_pos, cur_pos);
300  }
301  }
302  break;
303 
304  case DC_AUTOSHOOT_CIRCLE: {
305  float course = DegOfRad(stateGetNedToBodyEulers_f()->psi) - dc_circle_start_angle;
306  if (course < 0.) {
307  course += 360.;
308  }
309  float current_block = floorf(course / dc_circle_interval);
310 
311  if (dim_mod(current_block, dc_circle_last_block, dc_circle_max_blocks) == 1) {
312  dc_gps_count++;
313  dc_circle_last_block = current_block;
315  }
316  }
317  break;
318 
319  case DC_AUTOSHOOT_SURVEY: {
320  float dist_x = dc_gps_x - stateGetPositionEnu_f()->x;
321  float dist_y = dc_gps_y - stateGetPositionEnu_f()->y;
322 
323  if (dist_x * dist_x + dist_y * dist_y >= dc_gps_next_dist * dc_gps_next_dist) {
325  dc_gps_count++;
327  }
328  }
329  break;
330 
331  default:
333  }
334 }
static int16_t course[3]
Definition: airspeed_uADC.c:58
void dc_send_command(uint8_t cmd)
Send Command To Camera.
#define WaypointX(_wp)
Definition: common_nav.h:45
#define WaypointY(_wp)
Definition: common_nav.h:46
#define DC_AUTOSHOOT_PERIOD
default time interval for periodic mode: 1sec
Definition: dc.c:48
float dc_circle_start_angle
angle a where first image will be taken at a + delta
Definition: dc.c:73
#define DC_AUTOSHOOT_DISTANCE_INIT
default distance of the first shoot: 0m (start immediately)
Definition: dc.c:58
#define DC_AUTOSHOOT_SURVEY_INTERVAL
default distance interval for survey mode: 50m
Definition: dc.c:63
float dc_survey_interval
distance between dc shots in meters
Definition: dc.c:77
void dc_periodic(void)
periodic function
Definition: dc.c:274
uint8_t dc_survey(float interval, float x, float y)
Sets the dc control in distance mode.
Definition: dc.c:235
void dc_init(void)
initialize settings
Definition: dc.c:156
float dc_distance_interval
AutoShoot photos on distance to last shot in meters.
Definition: dc.c:83
dc_autoshoot_type dc_autoshoot
Definition: dc.c:67
uint8_t dc_stop(void)
Stop dc control.
Definition: dc.c:257
void dc_send_command_common(uint8_t cmd)
Command sending function.
Definition: dc.c:189
float dc_circle_last_block
Definition: dc.c:74
#define DC_AUTOSHOOT_DISTANCE_INTERVAL
default distance interval for distance mode: 50m
Definition: dc.c:53
static float dim_mod(float a, float b, float m)
Definition: dc.c:264
float dc_gps_next_dist
Definition: dc.c:78
uint16_t dc_photo_nr
export the number of the last photo
Definition: dc.c:93
float dc_gps_x
point of reference for the survey mode
Definition: dc.c:79
uint8_t dc_distance(float interval)
Sets the dc control in distance mode.
Definition: dc.c:200
uint8_t dc_cam_tracing
Definition: dc.c:69
float dc_autoshoot_period
AutoShoot photos every X seconds.
Definition: dc.c:84
uint16_t dc_gps_count
number of images taken since the last change of dc_mode
Definition: dc.c:68
void dc_send_shot_position(void)
Send Down the coordinates of where the photo was taken.
Definition: dc.c:104
uint8_t dc_info(void)
Send an info message.
Definition: dc.c:163
float dc_gps_y
Definition: dc.c:80
float dc_circle_interval
angle between dc shots in degree
Definition: dc.c:72
uint8_t dc_circle(float interval, float start)
Sets the dc control in circle mode.
Definition: dc.c:213
float dc_cam_angle
camera angle
Definition: dc.c:70
float dc_circle_max_blocks
Definition: dc.c:75
static struct FloatVect2 last_shot_pos
Definition: dc.c:82
Standard Digital Camera Control Interface.
#define DC_IMAGE_BUFFER
Definition: dc.h:147
@ DC_SHOOT
Definition: dc.h:100
#define DC_IGNORE
Definition: dc.h:142
dc_autoshoot_type
Auotmatic Digital Camera Photo Triggering modes.
Definition: dc.h:127
@ DC_AUTOSHOOT_DISTANCE
Definition: dc.h:130
@ DC_AUTOSHOOT_PERIODIC
Definition: dc.h:129
@ DC_AUTOSHOOT_SURVEY
Definition: dc.h:132
@ DC_AUTOSHOOT_CIRCLE
Definition: dc.h:133
@ DC_AUTOSHOOT_STOP
Definition: dc.h:128
struct pprz_transport extra_pprz_tp
Definition: extra_pprz_dl.c:57
Extra datalink and telemetry using PPRZ protocol.
struct GpsState gps
global GPS state
Definition: gps.c:69
Device independent GPS code (interface)
uint32_t tow
GPS time of week in ms.
Definition: gps.h:107
int32_t hmsl
height above mean sea level (MSL) in mm
Definition: gps.h:92
static float float_vect2_norm(struct FloatVect2 *v)
#define VECT2_DIFF(_c, _a, _b)
Definition: pprz_algebra.h:92
#define VECT2_COPY(_a, _b)
Definition: pprz_algebra.h:68
static struct FloatEulers * stateGetNedToBodyEulers_f(void)
Get vehicle body attitude euler angles (float).
Definition: state.h:1143
static struct EnuCoor_f * stateGetPositionEnu_f(void)
Get position in local ENU coordinates (float).
Definition: state.h:719
static struct LlaCoor_i * stateGetPositionLla_i(void)
Get position in LLA coordinates (int).
Definition: state.h:683
static float stateGetHorizontalSpeedNorm_f(void)
Get norm of horizontal ground speed (float).
Definition: state.h:935
static float stateGetHorizontalSpeedDir_f(void)
Get dir of horizontal ground speed (float).
Definition: state.h:944
float y
in meters
float x
in meters
Rotorcraft navigation functions.
static uint8_t mode
mode holds the current sonar mode mode = 0 used at high altitude, uses 16 wave patterns mode = 1 used...
Definition: sonar_bebop.c:69
API to get/set the generic vehicle states.
Architecture independent timing functions.
static float get_sys_time_float(void)
Get the time in seconds since startup.
Definition: sys_time.h:138
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
Definition: vl53l1_types.h:88
short int16_t
Typedef defining 16 bit short type.
Definition: vl53l1_types.h:93
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
Definition: vl53l1_types.h:98
float b
Definition: wedgebug.c:202