-
-
Notifications
You must be signed in to change notification settings - Fork 520
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1733 from mavlink/pr-component-camera-server
Server component and server plugin infrastructure
- Loading branch information
Showing
171 changed files
with
13,663 additions
and
2,070 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
cmake_minimum_required(VERSION 3.10.2) | ||
|
||
set(CMAKE_CXX_STANDARD 17) | ||
set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
|
||
project(camera_server) | ||
|
||
add_executable(camera_server | ||
camera_server.cpp | ||
) | ||
|
||
find_package(MAVSDK REQUIRED) | ||
|
||
target_link_libraries(camera_server | ||
MAVSDK::mavsdk | ||
) | ||
|
||
if(NOT MSVC) | ||
add_compile_options(camera_server PRIVATE -Wall -Wextra) | ||
else() | ||
add_compile_options(camera_server PRIVATE -WX -W2) | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
#include <future> | ||
|
||
#include <iostream> | ||
#include <map> | ||
#include <thread> | ||
#include <mavsdk/mavsdk.h> | ||
#include <mavsdk/plugins/camera/camera.h> | ||
#include <mavsdk/plugins/camera_server/camera_server.h> | ||
|
||
using namespace mavsdk; | ||
|
||
using std::chrono::duration_cast; | ||
using std::chrono::seconds; | ||
using std::chrono::milliseconds; | ||
using std::chrono::system_clock; | ||
using std::this_thread::sleep_for; | ||
|
||
int main(int argc, char** argv) | ||
{ | ||
mavsdk::Mavsdk mavsdk; | ||
mavsdk::Mavsdk::Configuration configuration(mavsdk::Mavsdk::Configuration::UsageType::Camera); | ||
mavsdk.set_configuration(configuration); | ||
|
||
// 14030 is the default camera port for PX4 SITL | ||
// FIXME: the camera should probably initiate the connection and not just listen | ||
auto result = mavsdk.add_any_connection("udp://:14030"); | ||
if (result != mavsdk::ConnectionResult::Success) { | ||
std::cerr << "Could not establish connection: " << result << std::endl; | ||
return 1; | ||
} | ||
std::cout << "Created camera server connection" << std::endl; | ||
|
||
auto camera_server = mavsdk::CameraServer{ | ||
mavsdk.server_component_by_type(mavsdk::Mavsdk::ServerComponentType::Camera)}; | ||
|
||
// First add all subscriptions. This defines the camera capabilities. | ||
|
||
camera_server.subscribe_take_photo([&camera_server](int32_t index) { | ||
camera_server.set_in_progress(true); | ||
|
||
std::cout << "taking a picture (" << +index << ")..." << std::endl; | ||
|
||
// TODO : actually capture image here | ||
// simulating with delay | ||
sleep_for(milliseconds(500)); | ||
|
||
// TODO: populate with telemetry data | ||
auto position = CameraServer::Position{}; | ||
auto attitude = CameraServer::Quaternion{}; | ||
|
||
auto timestamp = | ||
duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count(); | ||
auto success = true; | ||
|
||
camera_server.set_in_progress(false); | ||
|
||
camera_server.respond_take_photo( | ||
mavsdk::CameraServer::TakePhotoFeedback::Ok, | ||
mavsdk::CameraServer::CaptureInfo{ | ||
.position = position, | ||
.attitude_quaternion = attitude, | ||
.time_utc_us = static_cast<uint64_t>(timestamp), | ||
.is_success = success, | ||
.index = index, | ||
.file_url = {}, | ||
}); | ||
}); | ||
|
||
// Then set the initial state of everything. | ||
|
||
// TODO: this state is not guaranteed, e.g. a new system appears | ||
// while a capture is in progress | ||
camera_server.set_in_progress(false); | ||
|
||
// Finally call set_information() to "activate" the camera plugin. | ||
|
||
auto ret = camera_server.set_information({ | ||
.vendor_name = "MAVSDK", | ||
.model_name = "Example Camera Server", | ||
.firmware_version = "1.0.0", | ||
.focal_length_mm = 3.0, | ||
.horizontal_sensor_size_mm = 3.68, | ||
.vertical_sensor_size_mm = 2.76, | ||
.horizontal_resolution_px = 3280, | ||
.vertical_resolution_px = 2464, | ||
.lens_id = 0, | ||
.definition_file_version = 0, // TODO: add this | ||
.definition_file_uri = "", // TODO: implement this using MAVLink FTP | ||
}); | ||
|
||
if (ret != CameraServer::Result::Success) { | ||
std::cerr << "Failed to set camera info, exiting" << std::endl; | ||
return 2; | ||
} | ||
|
||
while (true) { | ||
// Wait forever? | ||
sleep_for(seconds(1)); | ||
} | ||
|
||
return 0; | ||
} |
Submodule proto
updated
5 files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.