Skip to content
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

AP_Mission/AP_Camera: add mavlink STOP_CAPTURE/START_CAPTURE command support and fixes to existing implementation #24772

Merged
merged 5 commits into from
Sep 21, 2023

Conversation

khanasif786
Copy link
Contributor

@khanasif786 khanasif786 commented Aug 25, 2023

This adds support for MAV_CMD_IMAGE_STOP_CAPTURE. This is from the camera enhancements list #23151
Thanks to @trolledbypro for initial work on this
This has been tested latest in Mission and with simple mavlink command. (Single camera is used) Multiple should work.

@khanasif786
Copy link
Contributor Author

khanasif786 commented Aug 31, 2023

I see Mission doesn't support IMAGE START capture with multiple images. I will create a seperate PR for that if its okay.

@khanasif786 khanasif786 marked this pull request as ready for review August 31, 2023 16:04
Copy link
Contributor

@rmackay9 rmackay9 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. This has been tested of course?

@khanasif786 khanasif786 changed the title AP_Mission/AP_Camera: add MAV_CMD_IMAGE_STOP_CAPTURE support AP_Mission/AP_Camera: add MAV_CMD_IMAGE_STOP_CAPTURE/START_CAPTURE support and fixes to existing support Sep 7, 2023
@khanasif786 khanasif786 force-pushed the mav_cmd_stop_capture branch 2 times, most recently from d2a8025 to cf94210 Compare September 7, 2023 10:13
@khanasif786
Copy link
Contributor Author

Tested with single camera in Mission and also with simple mavlink command. Could you please review.

Copy link
Contributor Author

@khanasif786 khanasif786 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @magicrub. I Have done suggested changes in the new patch

libraries/AP_Camera/AP_Camera.cpp Show resolved Hide resolved
@khanasif786 khanasif786 changed the title AP_Mission/AP_Camera: add MAV_CMD_IMAGE_STOP_CAPTURE/START_CAPTURE support and fixes to existing support AP_Mission/AP_Camera: add mavlinks STOP_CAPTURE/START_CAPTURE command support and fixes to existing implementation Sep 7, 2023
@khanasif786 khanasif786 changed the title AP_Mission/AP_Camera: add mavlinks STOP_CAPTURE/START_CAPTURE command support and fixes to existing implementation AP_Mission/AP_Camera: add mavlink STOP_CAPTURE/START_CAPTURE command support and fixes to existing implementation Sep 7, 2023
libraries/AP_Camera/AP_Camera.cpp Outdated Show resolved Hide resolved
Copy link
Contributor Author

@khanasif786 khanasif786 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done changes suggested by @rmackay9

libraries/AP_Camera/AP_Camera.cpp Outdated Show resolved Hide resolved
Copy link
Contributor Author

@khanasif786 khanasif786 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rmackay9 Thanks. i have done changes

libraries/AP_Camera/AP_Camera.cpp Outdated Show resolved Hide resolved
libraries/AP_Camera/AP_Camera.cpp Outdated Show resolved Hide resolved
libraries/AP_Camera/AP_Camera.cpp Outdated Show resolved Hide resolved
libraries/AP_Camera/AP_Camera.h Outdated Show resolved Hide resolved
libraries/AP_Mission/AP_Mission_Commands.cpp Outdated Show resolved Hide resolved
@@ -269,6 +269,7 @@ class AP_Mission

// MAV_CMD_IMAGE_START_CAPTURE support
struct PACKED image_start_capture_Command {
uint8_t instance;
Copy link
Contributor

@rmackay9 rmackay9 Sep 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this will lead to corruption of the image-start-capture mission command for users that already have the command in a mission on a vehicle. I think this is OK though because Mission Planner at least never had the columns displayed to users so most users were probably leaving all columns blank (see MP PR here ArduPilot/MissionPlanner#3175)

@peterbarker what do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there any way we can add support without leading corruption ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@khanasif786,

Yes, I think if the instance was placed at the end of the structure instead of the beginning.

Copy link
Contributor Author

@khanasif786 khanasif786 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rmackay9 Addressed your comments. have a look

libraries/AP_Camera/AP_Camera.cpp Outdated Show resolved Hide resolved
@@ -269,6 +269,7 @@ class AP_Mission

// MAV_CMD_IMAGE_START_CAPTURE support
struct PACKED image_start_capture_Command {
uint8_t instance;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there any way we can add support without leading corruption ?

libraries/AP_Mission/AP_Mission_Commands.cpp Outdated Show resolved Hide resolved
if (backend == nullptr) {
return false;
}
backend->take_picture();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should return the result from backend->take_picture() instead of just returning true.

@rmackay9
Copy link
Contributor

@khanasif786,

Getting close now. Can you also rebase this on master?


// take multiple pictures, time_interval between two consecutive pictures is in miliseconds
// total_num is number of pictures to be taken, -1 means capture forever
void take_multiple_pictures(uint32_t time_interval_ms, int16_t total_num);
bool take_multiple_pictures(uint8_t instance, uint32_t time_interval_ms, int16_t total_num);
Copy link
Contributor

@rmackay9 rmackay9 Sep 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should make these take-multiple-pictures methods fail if the total_num is non-zero (e.g. forever or some specified number) and the time_interval_ms is zero. I know you had this originally in the command parser and I asked you to remove it but after testing I see we really do need the check of a non-zero interval... it is better to have it down here in this method anyway though.

We could do this as a follow-up PR though (even I could do it)

Copy link
Contributor Author

@khanasif786 khanasif786 Sep 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay upto you then.

if (cmd.content.image_start_capture.total_num_images == 1) {
if (cmd.content.image_start_capture.instance == 0) {
// take pictures for every backend
camera->take_picture();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally I think this take_picture() should also return a boolean which is true if any backend succeeded in taking a picture. I'm happy to do this as a follow-up PR though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay upto you now.

@khanasif786
Copy link
Contributor Author

@rmackay9 . I have rebased it. Could you add the functionalities you told in another PR, Thus the code will also get re-tested on different setup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants