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

how to get Ardupilot Camera Trigger status? #2209

Open
SeongminJaden opened this issue Jan 12, 2024 · 1 comment
Open

how to get Ardupilot Camera Trigger status? #2209

SeongminJaden opened this issue Jan 12, 2024 · 1 comment

Comments

@SeongminJaden
Copy link

Hello, I am developing software to control drones using MAVSDK c++, but I am having a problem, so I would like to ask a question.

What I want to do is set a flight mission to control the camera trigger at each waypoint of misson, but in mavsdk, I want to do a cout every time the trigger is controlled during the mission. But it's not working well. Please help.

` mavsdk.subscribe_on_message_async(
MAVLinkMessage::Message::CAMERA_IMAGE_CAPTURED,
[&](const MAVLinkMessage& message) {
// 이미지가 캡처되면 실행될 코드
std::cout << "이미지 캡처 완료\n";

            std::ostringstream filenameStream;
            filenameStream << baseFilename << i << fileExtension;
            std::string filename = filenameStream.str();
            std::string command = "gphoto2 --port=usb: --folder=" + downloadPath +
                " --capture-image-and-download --filename=\"" + downloadPath + filename + "\"";
            int result_trigger = std::system(command.c_str());
            if (result_trigger == 0) {
                std::cout << "Image captured and downloaded: " << filename << std::endl;
            }
            else {
                std::cerr << "Error capturing or downloading image." << std::endl;
                return 1;
            }
            sleep_for(seconds(5));

            std::string exifCommand = exifCommandTemplate + filePathPrefix + std::to_string(i) + filePathSuffix;
            std::string move_enc = move + filePathPrefix + std::to_string(i) + filePathSuffix + enc;
            std::cout << exifCommand << std::endl;
            // Convert latitude and longitude to strings with full precision
            std::ostringstream latitudeStr, longitudeStr;
            latitudeStr << latitude;
            longitudeStr << longitude;

            // Convert altitude to a string and append "m"
            std::ostringstream altitudeStr;
            altitudeStr << altitude;

            size_t pos = exifCommand.find("xxx");
            exifCommand.replace(pos, 3, latitudeStr.str());
            pos = exifCommand.find("xxx");
            exifCommand.replace(pos, 3, longitudeStr.str());
            pos = exifCommand.find("xxx");
            exifCommand.replace(pos, 3, altitudeStr.str());
            int result = std::system(exifCommand.c_str());
    },
    nullptr);

trigger_result = action.set_trigger_control(Action::TriggerControl::Disable);
if (trigger_result != Action::Result::Success) {
    std::cerr << "트리거 제어 비활성화 실패: " << trigger_result << '\n';
    return 1;
}`
@JonasVautherin
Copy link
Collaborator

First, instead of subscribe_on_message_async, you should probably use the Camera plugin (subscribe_capture_info, which will give you an CaptureInfo object for each photo taken.

Then, when you say "it is not working well", what you do mean? What can happen is that the corresponding mavlink message is lost (because it is an unreliable mavlink broadcast), and therefore MAVSDK does not guarantee that the callback is triggered for every single photo taken.

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

No branches or pull requests

2 participants