-
Notifications
You must be signed in to change notification settings - Fork 16.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Camera: image start/stop capture fixes #25075
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
457f143
AP_Camera: fix reporting of mount take_picture
rmackay9 1d20087
AP_Camera: take_pic and take_multiple_pic report success
rmackay9 57c3cb5
AP_Camera: start-image-capture with all zeros takes single pic
rmackay9 605cbea
AP_Camera: image-stop-capture fix for instance
rmackay9 0bd7f1e
AP_Mission: start-image-capture with all zeros takes single pic
rmackay9 5c0bacc
AP_Mission: image-stop-capture fix for instance
rmackay9 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -77,16 +77,20 @@ void AP_Camera::cam_mode_toggle() | |||||||
} | ||||||||
|
||||||||
// take a picture | ||||||||
void AP_Camera::take_picture() | ||||||||
bool AP_Camera::take_picture() | ||||||||
{ | ||||||||
WITH_SEMAPHORE(_rsem); | ||||||||
|
||||||||
// call for each instance | ||||||||
bool success = false; | ||||||||
for (uint8_t i = 0; i < AP_CAMERA_MAX_INSTANCES; i++) { | ||||||||
if (_backends[i] != nullptr) { | ||||||||
_backends[i]->take_picture(); | ||||||||
success |= _backends[i]->take_picture(); | ||||||||
} | ||||||||
} | ||||||||
|
||||||||
// return true if at least once pic taken | ||||||||
return success; | ||||||||
} | ||||||||
|
||||||||
bool AP_Camera::take_picture(uint8_t instance) | ||||||||
|
@@ -97,28 +101,45 @@ bool AP_Camera::take_picture(uint8_t instance) | |||||||
if (backend == nullptr) { | ||||||||
return false; | ||||||||
} | ||||||||
backend->take_picture(); | ||||||||
return true; | ||||||||
return backend->take_picture(); | ||||||||
} | ||||||||
|
||||||||
// take multiple pictures, time_interval between two consecutive pictures is in miliseconds | ||||||||
// if instance is not provided, all available cameras affected | ||||||||
// time_interval_ms must be positive | ||||||||
// total_num is number of pictures to be taken, -1 means capture forever | ||||||||
void AP_Camera::take_multiple_pictures(uint32_t time_interval_ms, int16_t total_num) | ||||||||
// returns true if at least one camera is successful | ||||||||
bool AP_Camera::take_multiple_pictures(uint32_t time_interval_ms, int16_t total_num) | ||||||||
{ | ||||||||
WITH_SEMAPHORE(_rsem); | ||||||||
|
||||||||
// sanity check time interval | ||||||||
if (time_interval_ms == 0) { | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't need to have the semaphore to make this check, |
||||||||
return false; | ||||||||
} | ||||||||
|
||||||||
// call for all instances | ||||||||
bool success = false; | ||||||||
for (uint8_t i = 0; i < AP_CAMERA_MAX_INSTANCES; i++) { | ||||||||
if (_backends[i] != nullptr) { | ||||||||
_backends[i]->take_multiple_pictures(time_interval_ms, total_num); | ||||||||
success = true; | ||||||||
} | ||||||||
} | ||||||||
|
||||||||
// return true if at least once backend was successful | ||||||||
return success; | ||||||||
} | ||||||||
|
||||||||
bool AP_Camera::take_multiple_pictures(uint8_t instance, uint32_t time_interval_ms, int16_t total_num) | ||||||||
{ | ||||||||
WITH_SEMAPHORE(_rsem); | ||||||||
|
||||||||
// sanity check time interval | ||||||||
if (time_interval_ms == 0) { | ||||||||
return false; | ||||||||
} | ||||||||
|
||||||||
auto *backend = get_instance(instance); | ||||||||
if (backend == nullptr) { | ||||||||
return false; | ||||||||
|
@@ -304,45 +325,48 @@ MAV_RESULT AP_Camera::handle_command_long(const mavlink_command_long_t &packet) | |||||||
} | ||||||||
return MAV_RESULT_DENIED; | ||||||||
case MAV_CMD_IMAGE_START_CAPTURE: | ||||||||
// check if this is a single picture request | ||||||||
if (is_equal(packet.param3, 1.0f)) { | ||||||||
// param1 : camera id | ||||||||
// param2 : interval (in seconds) | ||||||||
// param3 : total num images | ||||||||
// sanity check instance | ||||||||
if (is_negative(packet.param1)) { | ||||||||
return MAV_RESULT_UNSUPPORTED; | ||||||||
} | ||||||||
// check if this is a single picture request (e.g. total images is 1 or interval and total images are zero) | ||||||||
if (is_equal(packet.param3, 1.0f) || | ||||||||
(is_zero(packet.param2) && is_zero(packet.param3))) { | ||||||||
if (is_zero(packet.param1)) { | ||||||||
// take pictures for every backend | ||||||||
take_picture(); | ||||||||
return MAV_RESULT_ACCEPTED; | ||||||||
} | ||||||||
if (take_picture(packet.param1-1)) { | ||||||||
return MAV_RESULT_ACCEPTED; | ||||||||
return take_picture() ? MAV_RESULT_ACCEPTED : MAV_RESULT_FAILED; | ||||||||
} | ||||||||
// take picture for specified instance | ||||||||
return take_picture(packet.param1-1) ? MAV_RESULT_ACCEPTED : MAV_RESULT_FAILED; | ||||||||
} else if (is_zero(packet.param3)) { | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
// multiple picture request, take pictures forever | ||||||||
if (is_zero(packet.param1)) { | ||||||||
// take pictures for every backend | ||||||||
take_multiple_pictures(packet.param2*1000, -1); | ||||||||
return MAV_RESULT_ACCEPTED; | ||||||||
} | ||||||||
if (take_multiple_pictures(packet.param1-1,packet.param2*1000, -1)) { | ||||||||
return MAV_RESULT_ACCEPTED; | ||||||||
return take_multiple_pictures(packet.param2*1000, -1) ? MAV_RESULT_ACCEPTED : MAV_RESULT_FAILED; | ||||||||
} | ||||||||
return take_multiple_pictures(packet.param1-1, packet.param2*1000, -1) ? MAV_RESULT_ACCEPTED : MAV_RESULT_FAILED; | ||||||||
} else { | ||||||||
// take multiple pictures equal to the number specified in param3 | ||||||||
if (is_zero(packet.param1)) { | ||||||||
// take pictures for every backend | ||||||||
take_multiple_pictures(packet.param2*1000, packet.param3); | ||||||||
return MAV_RESULT_ACCEPTED; | ||||||||
} | ||||||||
if (take_multiple_pictures(packet.param1-1,packet.param2*1000, packet.param3)) { | ||||||||
return MAV_RESULT_ACCEPTED; | ||||||||
return take_multiple_pictures(packet.param2*1000, packet.param3) ? MAV_RESULT_ACCEPTED : MAV_RESULT_FAILED; | ||||||||
} | ||||||||
return take_multiple_pictures(packet.param1-1, packet.param2*1000, packet.param3) ? MAV_RESULT_ACCEPTED : MAV_RESULT_FAILED; | ||||||||
} | ||||||||
return MAV_RESULT_UNSUPPORTED; | ||||||||
case MAV_CMD_IMAGE_STOP_CAPTURE: | ||||||||
// param1 : camera id | ||||||||
if (is_negative(packet.param1)) { | ||||||||
return MAV_RESULT_UNSUPPORTED; | ||||||||
} | ||||||||
if (is_zero(packet.param1)) { | ||||||||
// stop capture for every backend | ||||||||
stop_capture(); | ||||||||
return MAV_RESULT_ACCEPTED; | ||||||||
} | ||||||||
if (stop_capture(packet.param1)) { | ||||||||
if (stop_capture(packet.param1-1)) { | ||||||||
return MAV_RESULT_ACCEPTED; | ||||||||
} | ||||||||
return MAV_RESULT_UNSUPPORTED; | ||||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.