Skip to content

Commit 6c17373

Browse files
committed
camera_server: use subscriptions as capability flags
1 parent b5ea0d6 commit 6c17373

File tree

3 files changed

+27
-27
lines changed

3 files changed

+27
-27
lines changed

examples/camera_server/camera_server.cpp

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,6 @@
77
#include <mavsdk/plugins/camera/camera.h>
88
#include <mavsdk/plugins/camera_server/camera_server.h>
99

10-
/*
11-
This example runs a MAVLink "camera" utilizing the MAVSDK server plugins
12-
on a separate thread. This uses two MAVSDK instances, one GCS, one camera.
13-
14-
The main thread acts as a GCS and reads telemetry, parameters, transmits across
15-
a mission, clears the mission, arms the vehicle and then triggers a vehicle takeoff.
16-
17-
The camera thread handles all the servers and triggers callbacks, publishes telemetry,
18-
handles and stores parameters, prints received missions and sets the vehicle height to 10m on
19-
successful takeoff request.
20-
*/
21-
2210
using namespace mavsdk;
2311

2412
using std::chrono::duration_cast;
@@ -54,17 +42,7 @@ int main(int argc, char** argv)
5442

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

57-
camera_server->set_information({
58-
.vendor_name = "MAVSDK",
59-
.model_name = "Example Camera Server",
60-
.focal_length_mm = 3.0,
61-
.horizontal_sensor_size_mm = 3.68,
62-
.vertical_sensor_size_mm = 2.76,
63-
.horizontal_resolution_px = 3280,
64-
.vertical_resolution_px = 2464,
65-
});
66-
67-
camera_server->set_in_progress(false);
45+
// First add all subscriptions. This defines the camera capabilities.
6846

6947
camera_server->subscribe_take_photo(
7048
[camera_server, &all_camera_servers](CameraServer::Result result, int32_t index) {
@@ -99,6 +77,22 @@ int main(int argc, char** argv)
9977
}
10078
});
10179

80+
// Then set the initial state of everything.
81+
82+
camera_server->set_in_progress(false);
83+
84+
// Finally call set_information() to "activate" the camera plugin.
85+
86+
camera_server->set_information({
87+
.vendor_name = "MAVSDK",
88+
.model_name = "Example Camera Server",
89+
.focal_length_mm = 3.0,
90+
.horizontal_sensor_size_mm = 3.68,
91+
.vertical_sensor_size_mm = 2.76,
92+
.horizontal_resolution_px = 3280,
93+
.vertical_resolution_px = 2464,
94+
});
95+
10296
std::cout << "Connected to " << (system->is_standalone() ? "GCS" : "autopilot")
10397
<< " system ID " << +system->get_system_id() << std::endl;
10498
}

proto

src/mavsdk/plugins/camera_server/camera_server_impl.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,13 @@ std::optional<mavlink_message_t> CameraServerImpl::process_camera_information_re
291291
const uint16_t camera_definition_version = 0;
292292
auto camera_definition_uri = "";
293293

294+
// capability flags are determined by subscriptions
295+
uint32_t capability_flags{};
296+
297+
if (_take_photo_callback) {
298+
capability_flags |= CAMERA_CAP_FLAGS::CAMERA_CAP_FLAGS_CAPTURE_IMAGE;
299+
}
300+
294301
mavlink_message_t msg{};
295302
mavlink_msg_camera_information_pack(
296303
_parent->get_own_system_id(),
@@ -306,7 +313,7 @@ std::optional<mavlink_message_t> CameraServerImpl::process_camera_information_re
306313
_information.horizontal_resolution_px,
307314
_information.vertical_resolution_px,
308315
lens_id,
309-
CAMERA_CAP_FLAGS::CAMERA_CAP_FLAGS_CAPTURE_IMAGE,
316+
capability_flags,
310317
camera_definition_version,
311318
camera_definition_uri);
312319

@@ -561,8 +568,7 @@ CameraServerImpl::process_image_start_capture(const MavlinkCommandReceiver::Comm
561568

562569
if (!_take_photo_callback) {
563570
LogDebug() << "image capture requested with no take photo subscriber";
564-
return _parent->make_command_ack_message(
565-
command, MAV_RESULT::MAV_RESULT_TEMPORARILY_REJECTED);
571+
return _parent->make_command_ack_message(command, MAV_RESULT::MAV_RESULT_UNSUPPORTED);
566572
}
567573

568574
// single image capture

0 commit comments

Comments
 (0)