diff --git a/libraries/AP_Camera/AP_Camera.cpp b/libraries/AP_Camera/AP_Camera.cpp index 9c3506459f..434146346a 100644 --- a/libraries/AP_Camera/AP_Camera.cpp +++ b/libraries/AP_Camera/AP_Camera.cpp @@ -216,24 +216,28 @@ AP_Camera::control_msg(mavlink_message_t* msg) } -// update location, for triggering by GPS distance moved -void AP_Camera::update_location(const struct Location &loc) +/* update location, for triggering by GPS distance moved + This function returns true if a picture should be taken + The caller is responsible for taking the picture based on the return value of this function. + The caller is also responsible for logging the details about the photo +*/ +bool AP_Camera::update_location(const struct Location &loc) { if (_trigg_dist == 0.0f) { - return; + return false; } if (_last_location.lat == 0 && _last_location.lng == 0) { _last_location = loc; - return; + return false; } if (_last_location.lat == loc.lat && _last_location.lng == loc.lng) { // we haven't moved - this can happen as update_location() may // be called without a new GPS fix - return; + return false; } if (get_distance(&loc, &_last_location) < _trigg_dist) { - return; + return false; } _last_location = loc; - trigger_pic(); + return true; } diff --git a/libraries/AP_Camera/AP_Camera.h b/libraries/AP_Camera/AP_Camera.h index b2c12058db..01503cf5ea 100644 --- a/libraries/AP_Camera/AP_Camera.h +++ b/libraries/AP_Camera/AP_Camera.h @@ -54,7 +54,8 @@ public: void configure_msg(mavlink_message_t* msg); void control_msg(mavlink_message_t* msg); - void update_location(const struct Location &loc); + // Update location of vehicle and return true if a picture should be taken + bool update_location(const struct Location &loc); static const struct AP_Param::GroupInfo var_info[]; @@ -72,7 +73,7 @@ private: void throttle_pic(); // pictures blurry? use this trigger. Turns off the throttle until for # of cycles of medium loop then takes the picture and re-enables the throttle. void distance_pic(); // pictures blurry? use this trigger. Turns off the throttle until closer to waypoint then takes the picture and re-enables the throttle. void transistor_pic(); // hacked the circuit to run a transistor? use this trigger to send output. - + AP_Float _trigg_dist; // distance between trigger points (meters) struct Location _last_location;