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

Server component and server plugin infrastructure #1733

Merged
merged 54 commits into from
May 12, 2022

Conversation

julianoes
Copy link
Collaborator

I started some refactoring towards an infrastructure that better works for server plugins as mentioned in #1700.

The current state is just a rough try in that direction to see if it could be feasible.

FYI @dlech @dayjaby

@julianoes
Copy link
Collaborator Author

@dlech I have a simple take picture integration test working:

cmake --build build/debug -j8 --target integration_tests_runner && build/debug/src/integration_tests/integration_tests_runner --gtest_filter=CameraTest.TakePhotoSingle

...
Note: Google Test filter = CameraTest.TakePhotoSingle
[==========] Running 1 test from 1 test suite.
[----------] Global test environment set-up.
[----------] 1 test from CameraTest
[ RUN      ] CameraTest.TakePhotoSingle

[09:58:43|Info ] MAVSDK version: v1.2.0-12-g13c7bf48-dirty (mavsdk_impl.cpp:28)
[09:58:43|Info ] MAVSDK version: v1.2.0-12-g13c7bf48-dirty (mavsdk_impl.cpp:28)
[09:58:43|Debug] Initializing connection to remote system... (mavsdk_impl.cpp:510)
[09:58:43|Info ] New system on: 127.0.0.1:46411 (with sysid: 1) (udp_connection.cpp:192)
[09:58:43|Debug] New: System ID: 1 Comp ID: 100 (mavsdk_impl.cpp:512)
[09:58:43|Debug] Component Camera 1 (100) added. (system_impl.cpp:386)
[09:58:43|Debug] New: System ID: 245 Comp ID: 190 (mavsdk_impl.cpp:241)
[09:58:43|Debug] Component Unsupported component (190) added. (system_impl.cpp:386)
[09:58:43|Debug] Discovered 1 component(s) (system_impl.cpp:547)
[09:58:45|Warn ] Dropping command 521 that is already being sent (mavlink_command_sender.cpp:111)
[09:58:46|Debug] sent storage ack (camera_server_impl.cpp:417)
[09:58:46|Debug] sent storage msg (camera_server_impl.cpp:453)
[09:58:46|Warn ] sending again after 0.507855 s, retries to do: 3  (521). (mavlink_command_sender.cpp:287)
[09:58:46|Warn ] command temporarily rejected (521). (mavlink_command_sender.cpp:205)
[09:58:46|Debug] received image start capture request - interval: 0 total: 1 index: 1 (camera_server_impl.cpp:606)
[09:58:47|Info ] Let's take a photo now! (camera_take_photo.cpp:26)
[09:58:47|Debug] sent camera image captured msg - index: 99 (camera_server_impl.cpp:245)

[       OK ] CameraTest.TakePhotoSingle (3139 ms)
[----------] 1 test from CameraTest (3139 ms total)

[----------] Global test environment tear-down
[==========] 1 test from 1 test suite ran. (3139 ms total)
[  PASSED  ] 1 test.

@dlech
Copy link
Collaborator

dlech commented Apr 10, 2022

Nice!

@julianoes julianoes force-pushed the pr-component-camera-server branch from 9597656 to c9c2197 Compare April 11, 2022 02:08
@julianoes julianoes force-pushed the pr-component-camera-server branch 3 times, most recently from e041252 to 4969dd3 Compare April 18, 2022 10:35
@julianoes julianoes force-pushed the pr-component-camera-server branch from 32b2554 to dfe7f3e Compare April 22, 2022 01:00
@julianoes julianoes mentioned this pull request May 5, 2022
@julianoes julianoes force-pushed the pr-component-camera-server branch from 8b5f646 to 011d227 Compare May 6, 2022 03:14
@julianoes julianoes marked this pull request as ready for review May 6, 2022 03:14
@julianoes
Copy link
Collaborator Author

For anyone reading along, we now have some system_tests which exercise plugins against the server plugins:

cmake --build build/debug -j8 && build/debug/src/system_tests/system_tests_runner
...
[==========] Running 4 tests from 1 test suite.
[----------] Global test environment set-up.
[----------] 4 tests from SystemTest
[ RUN      ] SystemTest.CameraTakePhoto
...
[       OK ] SystemTest.CameraTakePhoto (329 ms)
[ RUN      ] SystemTest.ActionArmDisarm
...
[       OK ] SystemTest.ActionArmDisarm (176 ms)
[ RUN      ] SystemTest.ParamSetAndGet
...
[       OK ] SystemTest.ParamSetAndGet (107 ms)
[ RUN      ] SystemTest.ParamCustomSetAndGet
...
[       OK ] SystemTest.ParamCustomSetAndGet (173 ms)
[----------] 4 tests from SystemTest (786 ms total)

[----------] Global test environment tear-down
[==========] 4 tests from 1 test suite ran. (786 ms total)
[  PASSED  ] 4 tests.

@julianoes julianoes force-pushed the pr-component-camera-server branch from bcecd20 to 6f9dcb6 Compare May 6, 2022 03:38
.horizontal_sensor_size_mm = 3.68,
.vertical_sensor_size_mm = 2.76,
.horizontal_resolution_px = 3280,
.vertical_resolution_px = 2464,
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add the following here?

.lens_id = 0,
.definition_file_version = 0,
.definition_file_uri = "https://raw.githubusercontent.com/mavlink/mavlink-devguide/master/en/services/camera_definition_example.xml"

These fields are already part of the proto.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think we want to do it properly with a locally hosted file that can be queried using MAVLink FTP.

all_camera_servers.insert({system->get_system_id(), camera_server});

// First add all subscriptions. This defines the camera capabilities.

Copy link
Contributor

Choose a reason for hiding this comment

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

Would be great to see your new mavsdk/core/mavlink_parameters here in action, maybe by subscribing to the parameters listed in https://raw.githubusercontent.com/mavlink/mavlink-devguide/master/en/services/camera_definition_example.xml

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, agreed, we should. I think the camera_server plugin and example will require quite a bit more work for settings to work properly.

src/mavsdk/core/mavsdk_impl.h Outdated Show resolved Hide resolved
@julianoes
Copy link
Collaborator Author

Thanks for the review @dayjaby, that's great! We'll get to it next week, probably.

dlech and others added 10 commits May 10, 2022 13:32
example:

- fix more than one new system in subscribe_on_new_system() callback
- fix use after free
- publish photo to all systems

plugin:

- fix take photo logic
- add support for interval flag in capture status message
- add support for image count in capture status message
This introduces a ServerComponent(Impl) class which can be used by
server plugins instead of the System(Impl) class. This means that the
server is really tied to the Mavsdk instance rather than a System's
representation.
julianoes added 14 commits May 10, 2022 13:32
We can now take advantage of the server components.
We actually need a default component ID, so that heartbeats are sent
out.
Instead of creating it in the desctructor, we create it right before
sending out the first heartbeat.
We add the start_sending_heartbeats() call the thread queue to avoid
deadlocks.

What happens is that the mavlink receiver mutex is locked when a
heartbeat arrives which then creates the server component to send out
heartbeats. Creating the server component involves registering for
mavlink messages which is what blocks.
I previously had commented out some code related to the autopilot
version and heartbeat state messages. This should clean this up,
however, it will need some testing.
@julianoes julianoes force-pushed the pr-component-camera-server branch from 1efd615 to d722098 Compare May 10, 2022 02:27
Copy link
Collaborator

@JonasVautherin JonasVautherin left a comment

Choose a reason for hiding this comment

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

Started looking into it 🙂

examples/camera_server/camera_server.cpp Show resolved Hide resolved
src/integration_tests/CMakeLists.txt Outdated Show resolved Hide resolved
src/integration_tests/camera_take_photo.cpp Outdated Show resolved Hide resolved
src/mavsdk/core/mavlink_ftp.cpp Outdated Show resolved Hide resolved
src/mavsdk/core/mavlink_parameters.cpp Outdated Show resolved Hide resolved
src/mavsdk/core/mavsdk_impl.cpp Show resolved Hide resolved
julianoes added 4 commits May 12, 2022 13:24
This moves the component information test from the integration tests
over to system tests. However, it is currently disabled pending MAVLink
FTP refactoring.
Not sure why this had been disabled.
@julianoes julianoes force-pushed the pr-component-camera-server branch from f14183d to a62c249 Compare May 12, 2022 02:05
@julianoes julianoes merged commit bb6941d into main May 12, 2022
@julianoes julianoes deleted the pr-component-camera-server branch May 12, 2022 10:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants