MAVSDK icon indicating copy to clipboard operation
MAVSDK copied to clipboard

examples: add camera_manager

Open dayjaby opened this issue 3 years ago • 10 comments

Tested with

cmake -Bbuild -H. && cmake --build build -j4 && ./build/camera_manager .

and QGroundControl version v4.2.0. On top of the default communication link to the drone, you just need to add a UDP connection to 127.0.0.1:24547 , which will make QGC show the camera control interface: Screenshot from 2021-12-23 14-02-43

dayjaby avatar Dec 23 '21 13:12 dayjaby

@JonasVautherin It's just about sys ids and comp ids, not about ip addresses/ports. QGroundControl receives a HEARTBEAT from this mavlink camera manager component (with MAV_COMP_ID_CAMERA = 100). Upon receiving a heartbeat from any camera component, QGC will send a request to this component to retrieve the CAMERA_INFORMATION, which contains the cam_definition_uri. From exactly this camera component (same mavlink sysid/compid), QGC will start to retrieve the camera definition file via MAVLink FTP.

There is some inconsistency regarding "mavlinkftp" vs "mftp". In some commits I've seen mavlinkftp, but the mavlink documentation specifies "mftp" (https://mavlink.io/en/services/camera.html) and you can find that as well in QGroundControl: https://github.com/mavlink/qgroundcontrol/commit/4b50ffd48b1588d9e7f3a35779a5cb207384f896

Maybe it's working for me just because it still had some old data being cached, so would be good if someone else tests it (:

So basically this PR allows MAVSDK to implement the camera side of the mavlink camera protocol. There is lots of room for improvements: e.g. storing the parameters in a local file, publish all camera parameters on boot as PARAM_EXT, implement some streaming pipelines. The list is long :D

dayjaby avatar Dec 23 '21 16:12 dayjaby

My first approach was invalid, as I first tested it against a camera_definition_uri with http, which made QGroundControl preserve that in its cache. So the mavlinkftp did not work at all, as QGroundControl never used mavlink ftp for CAMERA_INFORMATION in the first place (a PR that fixes this issue in QGC is mentioned above).

The correct URL at the moment is something like mftp://[;comp=100]infos/camera_info.xml.

dayjaby avatar Dec 25 '21 09:12 dayjaby

Probably going to turn this into an own plugin, as this would allow to react to parameter changes quite easily:

void CameraManagerPluginImpl::init()
{
    _parent->provide_server_param_int("CAM_EV", 5);

    _parent->provide_server_param_int("CAM_ISO", 0);
    _parent->subscribe_param<uint32_t>(
        "CAM_ISO", [](uint32_t iso) { std::cout << "NEW ISO: " << iso << std::endl; }, nullptr);
}

Just not sure how to handle the different typing yet. E.g. one could end up using float for CAM_ISO or uint32 or int32 or whatever.

dayjaby avatar Jan 03 '22 17:01 dayjaby

@julianoes applied your suggestions.

However, I still don't feel comfortable having this just as an example. I think it's doing a lot of similar stuff as your component_information plugin; and eventually we will need something similar for VIDEO_STREAMING_INFORMATION as well.

I think of something along the lines of:

  1. We implement a camera_manager plugin
  • Users can use that plugin to provide callback functions for the different camera parameters, to forward parameter changes to their non-mavlink cameras
  1. We implement a video_stream_manager plugin
  • Users provide callback functions to establish a video stream, for example via GStreamer

Any common functionality among the camera_manager, video_stream_manager, component_information and ftp plugin, we should put into src/mavsdk/core. D'accord?

If you have a better word than "manager", let me know ;)

dayjaby avatar Jan 14 '22 13:01 dayjaby

If you have a better word than "manager", let me know ;)

All of the existing plugins that implement such features are called xyz_server.

dlech avatar Jan 14 '22 21:01 dlech

This is awesome!

Jaeyoung-Lim avatar Jan 31 '22 08:01 Jaeyoung-Lim

I assume we will merge this once the #1733 is in. Or should we get it in before that?

julianoes avatar Apr 13 '22 22:04 julianoes

I don't think we want to merge it as-is, but rather reuse the ideas on top of the new changes. Don't we want a MAVSDK-Proto API for this too?

dlech avatar Apr 13 '22 23:04 dlech

@dlech we only need to add subscribe/provide parameter callbacks to the .proto.

For the ftp camera information file transmission: I think @julianoes moved the FTP stuff out of a plugin into something that we can include in the camera server implementation already. Just the FTP burst needs some update.

dayjaby avatar Apr 14 '22 06:04 dayjaby

There has been some progress in https://github.com/mavlink/MAVSDK/pull/2088 in the same direction. I think once that other PR is merged, we can take a diff and see what is missing from this PR and pull it in.

julianoes avatar Dec 17 '23 22:12 julianoes