Skip to content

Commit

Permalink
[modules] dc: add dc_distance function
Browse files Browse the repository at this point in the history
- use dc_gps_count in distance mode
- cleanup some variables
  • Loading branch information
flixr committed Nov 25, 2014
1 parent e9da5c5 commit 0833613
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 25 deletions.
5 changes: 3 additions & 2 deletions conf/modules/digital_cam.xml
Expand Up @@ -14,6 +14,7 @@

<define name="DC_AUTOSHOOT_QUARTERSEC_PERIOD" value="6" description="quarter_second"/>
<define name="DC_AUTOSHOOT_DISTANCE_INTERVAL" value="50" description="distance interval for DC_AUTOSHOOT_DISTANCE in meters"/>
<define name="DC_AUTOSHOOT_SURVEY_INTERVAL" value="50" description="distance interval for DC_AUTOSHOOT_SURVEY in meters"/>
<define name="DC_SHOT_SYNC_SEND" value="TRUE|FALSE" description="send DC_SHOT message when photo was taken (default: TRUE)"/>
</doc>
<settings>
Expand All @@ -33,9 +34,9 @@
</dl_setting>

<dl_setting max="255" min="1" step="1" var="dc_autoshoot_quartersec_period" shortname="Periodic" param="DC_AUTOSHOOT_QUARTERSEC_PERIOD" unit="quarter-sec"/>
<dl_setting max="255" min="0" step="1" var="dc_autoshoot_distance_interval" shortname="dist" param="DC_AUTOSHOOT_DISTANCE_INTERVAL" unit="meter"/>
<dl_setting max="255" min="0" step="1" var="dc_distance_interval" shortname="dist" param="DC_AUTOSHOOT_DISTANCE_INTERVAL" unit="meter"/>

<dl_setting max="250" min="0" step="5" module="digital_cam/dc" var="dc_gps_dist" handler="Survey" shortname="Linear-Interval"/>
<dl_setting max="250" min="0" step="5" module="digital_cam/dc" var="dc_survey_interval" handler="Survey" shortname="Survey-Interval"/>
<dl_setting max="90" min="5" step="5" module="digital_cam/dc" var="dc_circle_interval" handler="Circle" shortname="Circle-Interval"/>
<dl_setting max="1" min="0" step="1" var="dc_cam_tracing" shortname="Cam-Tracing"/>
</dl_settings>
Expand Down
37 changes: 28 additions & 9 deletions sw/airborne/modules/digital_cam/dc.c
Expand Up @@ -46,11 +46,16 @@
#define DC_AUTOSHOOT_QUARTERSEC_PERIOD 2
#endif

/** default distance interval 50m */
/** default distance interval for distance mode: 50m */
#ifndef DC_AUTOSHOOT_DISTANCE_INTERVAL
#define DC_AUTOSHOOT_DISTANCE_INTERVAL 50
#endif

/** default distance interval for survey mode: 50m */
#ifndef DC_AUTOSHOOT_SURVEY_INTERVAL
#define DC_AUTOSHOOT_SURVEY_INTERVAL 50
#endif

// Variables with boot defaults
dc_autoshoot_type dc_autoshoot = DC_AUTOSHOOT_STOP;
uint16_t dc_gps_count = 0;
Expand All @@ -62,12 +67,14 @@ float dc_circle_start_angle = 0;
float dc_circle_last_block = 0;
float dc_circle_max_blocks = 0;

float dc_gps_dist = 50;
float dc_survey_interval = DC_AUTOSHOOT_SURVEY_INTERVAL;
float dc_gps_next_dist = 0;
float dc_gps_x = 0;
float dc_gps_y = 0;

uint8_t dc_autoshoot_distance_interval;
static struct FloatVect2 last_shot_pos = {0.0, 0.0};
float dc_distance_interval;

uint8_t dc_autoshoot_quartersec_period;

/** by default send DC_SHOT message when photo was taken */
Expand Down Expand Up @@ -121,7 +128,7 @@ void dc_init(void)
{
dc_autoshoot = DC_AUTOSHOOT_STOP;
dc_autoshoot_quartersec_period = DC_AUTOSHOOT_QUARTERSEC_PERIOD;
dc_autoshoot_distance_interval = DC_AUTOSHOOT_DISTANCE_INTERVAL;
dc_distance_interval = DC_AUTOSHOOT_DISTANCE_INTERVAL;
}

uint8_t dc_info(void) {
Expand All @@ -135,7 +142,7 @@ uint8_t dc_info(void) {
&stateGetPositionLla_i()->alt,
&course,
&dc_photo_nr,
&dc_gps_dist,
&dc_survey_interval,
&dc_gps_next_dist,
&dc_gps_x,
&dc_gps_y,
Expand All @@ -148,6 +155,18 @@ uint8_t dc_info(void) {
return 0;
}

/* shoot on distance */
uint8_t dc_distance(float interval) {
dc_autoshoot = DC_AUTOSHOOT_DISTANCE;
dc_gps_count = 0;
dc_distance_interval = interval;
last_shot_pos.x = 0;
last_shot_pos.y = 0;

dc_info();
return 0;
}

/* shoot on circle */
uint8_t dc_circle(float interval, float start) {
dc_autoshoot = DC_AUTOSHOOT_CIRCLE;
Expand All @@ -172,7 +191,7 @@ uint8_t dc_circle(float interval, float start) {
uint8_t dc_survey(float interval, float x, float y) {
dc_autoshoot = DC_AUTOSHOOT_SURVEY;
dc_gps_count = 0;
dc_gps_dist = interval;
dc_survey_interval = interval;

if (x == DC_IGNORE && y == DC_IGNORE) {
dc_gps_x = stateGetPositionEnu_f()->x;
Expand Down Expand Up @@ -222,14 +241,14 @@ void dc_periodic_4Hz(void)

case DC_AUTOSHOOT_DISTANCE:
{
static struct FloatVect2 last_shot_pos = {0.0, 0.0};
struct FloatVect2 cur_pos;
cur_pos.x = stateGetPositionEnu_f()->x;
cur_pos.y = stateGetPositionEnu_f()->y;
struct FloatVect2 delta_pos;
VECT2_DIFF(delta_pos, cur_pos, last_shot_pos);
float dist_to_last_shot = float_vect2_norm(&delta_pos);
if (dist_to_last_shot > dc_autoshoot_distance_interval) {
if (dist_to_last_shot > dc_distance_interval) {
dc_gps_count++;
dc_send_command(DC_SHOOT);
VECT2_COPY(last_shot_pos, cur_pos);
}
Expand Down Expand Up @@ -257,7 +276,7 @@ void dc_periodic_4Hz(void)
float dist_y = dc_gps_y - stateGetPositionEnu_f()->y;

if (dist_x*dist_x + dist_y*dist_y >= dc_gps_next_dist*dc_gps_next_dist) {
dc_gps_next_dist += dc_gps_dist;
dc_gps_next_dist += dc_survey_interval;
dc_gps_count++;
dc_send_command(DC_SHOOT);
}
Expand Down
57 changes: 43 additions & 14 deletions sw/airborne/modules/digital_cam/dc.h
Expand Up @@ -42,30 +42,52 @@
#include "generated/airframe.h"
#include "subsystems/gps.h"

/** export the number of the last photo */
extern uint16_t dc_photo_nr;

/** number of images taken since the last change of dc_mode */
extern uint16_t dc_gps_count;

/** export the number of the last photo */
extern uint16_t dc_photo_nr;

/*
* Variables for PERIODIC mode.
*/
/** AutoShoot photos every X quarter_second */
extern uint8_t dc_autoshoot_quartersec_period;


/*
* Variables for DISTANCE mode.
*/
/** AutoShoot photos on distance to last shot in meters */
extern float dc_distance_interval;


/*
* Variables for SURVEY mode.
*/
/** distance between dc shots in meters */
extern float dc_gps_dist;
extern float dc_survey_interval;

/** point of reference for the survey mode */
extern float dc_gps_x, dc_gps_y;

extern float dc_gps_next_dist;


/*
* Variables for CIRCLE mode.
*/
/** angle a where first image will be taken at a + delta */
extern float dc_circle_start_angle;

/*' angle between dc shots in degree */
/** angle between dc shots in degree */
extern float dc_circle_interval;

extern float dc_circle_max_blocks;

/** point of reference for the distance based mode */
extern float dc_gps_x, dc_gps_y;

extern float dc_circle_last_block;


/** camera angle */
extern float dc_cam_angle;
extern uint8_t dc_cam_tracing;
Expand Down Expand Up @@ -109,12 +131,6 @@ typedef enum {
} dc_autoshoot_type;
extern dc_autoshoot_type dc_autoshoot;

/** AutoShoot photos every X quarter_second */
extern uint8_t dc_autoshoot_quartersec_period;

/** AutoShoot photos on distance to last shot in meters */
extern uint8_t dc_autoshoot_distance_interval;

/** Send Down the coordinates of where the photo was taken */
void dc_send_shot_position(void);

Expand All @@ -138,6 +154,19 @@ extern void dc_init(void);
/** periodic 4Hz function */
extern void dc_periodic_4Hz(void);

/**
* Sets the dc control in distance mode.
*
* Shoot the next pic if distance to last saved shot position
* is greater than @a interval.
*
* The first picture is taken at after @a interval.
*
* @param interval minimum distance between shots in m
* @return zero
*/
extern uint8_t dc_distance(float interval);

/**
* Sets the dc control in circle mode.
*
Expand Down

0 comments on commit 0833613

Please sign in to comment.