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

Added camera plugin with basic functionality #338

Merged
merged 89 commits into from
Apr 23, 2018
Merged
Show file tree
Hide file tree
Changes from 88 commits
Commits
Show all changes
89 commits
Select commit Hold shift + click to select a range
452ba9c
Added camera plugin with basic functionality
julianoes Mar 23, 2018
780c1e1
camera: added API docstrings
julianoes Mar 23, 2018
4916523
camera: added setter/getter for camera mode
julianoes Mar 23, 2018
f50af93
camera: status, mode, capture, status, tests
julianoes Mar 24, 2018
eba1144
camera: add missing include
julianoes Mar 24, 2018
81f33bd
camera: clean up camera ID comments
julianoes Mar 25, 2018
8f99d44
camera: actually use using namespace
julianoes Mar 25, 2018
e8c7091
camera: don't ignore get_mode command ack
julianoes Mar 25, 2018
0a95d07
camera: clean up different timeouts and mutices
julianoes Mar 25, 2018
6ca5d05
camera: add integration test for status
julianoes Mar 25, 2018
604288a
camera: Added camera definition files (WIP)
julianoes Mar 25, 2018
5fba828
camera: remove PHOTO_SURVEY mode
julianoes Mar 25, 2018
8261818
camera: improve comment
julianoes Mar 26, 2018
0240dff
Added C++11 any class
julianoes Mar 26, 2018
1960f18
mavlink_parameters: refactor to use Any, add types
julianoes Mar 26, 2018
6bffd15
camera: WIP on definition parsing
julianoes Mar 26, 2018
638cac0
core: fix missing return
julianoes Mar 26, 2018
a6e18fc
camera_definition: add some more xml parsing
julianoes Mar 27, 2018
20be737
build_system: ignore old style casts on macOS
julianoes Mar 27, 2018
fcc6787
camera_definition: fields into settings structure
julianoes Mar 27, 2018
8b1c662
core: call abort on bad_cast
julianoes Mar 27, 2018
91a762b
camera_definition: method just to parse the xml
julianoes Mar 28, 2018
3ee1f72
build_system: update tinyxml2 and gtest
julianoes Mar 28, 2018
151f449
Move tinyxml2 to root
julianoes Mar 28, 2018
08b49b4
camera: move all parsing into one method
julianoes Mar 28, 2018
8a6ca92
camera: continue with camera definition
julianoes Apr 3, 2018
31cf390
camera_definition: added some getters/setters
julianoes Apr 4, 2018
821e790
camera: Added TODOs
julianoes Apr 5, 2018
dccb346
camera: added missing return
julianoes Apr 5, 2018
fc0bbfa
camera: fixes after device became system
julianoes Apr 5, 2018
9f9646f
camera_definition: continued settings
julianoes Apr 5, 2018
c168dd3
camera_definition: updated e90 xml, more todos
julianoes Apr 6, 2018
59c5f5c
camera_definition: wip on get_possible_settings
julianoes Apr 6, 2018
67a19a7
camera: possible options working
julianoes Apr 9, 2018
097a29a
camera: keep track of what params have been set
julianoes Apr 11, 2018
59aa9b5
camera_definition: API for needed param updates
julianoes Apr 11, 2018
ae84ed3
camera_definition: don't use insert for maps
julianoes Apr 11, 2018
2c70a9b
camera: Rebase with latest changes in core
Apr 13, 2018
bd7618b
camera: Add private method for Request camera info
Apr 13, 2018
8830330
camera: Add video streaming interface
Apr 13, 2018
2069406
camera: Correct video stream MAVLink command
Apr 13, 2018
f97e10e
core: Fix CI error in mavlink_parameters.h
Apr 13, 2018
62eaadd
camera: fix exception when instantiating string
julianoes Apr 13, 2018
ead13c9
appveyor: try to fix reference not found
julianoes Apr 13, 2018
54e7e56
build_system: remove warning for MSVC
julianoes Apr 13, 2018
3043d75
core: always initialize params
julianoes Apr 13, 2018
d6f4fc8
camera: check for camera before testing
julianoes Apr 13, 2018
b1c1b9d
camera: fix uninitialized memory bug
julianoes Apr 13, 2018
6136eb9
camera: check for camera before testing
julianoes Apr 17, 2018
b4227a7
camera: set correct param to set camera mode
julianoes Apr 17, 2018
65db7fc
mavlink: update submodule
julianoes Apr 17, 2018
9b7a36b
camera: start sequence at 1
julianoes Apr 17, 2018
7f9e3ae
camera: lookup option name from value
julianoes Apr 17, 2018
6015f27
camera: check that we have a camera before testing
julianoes Apr 17, 2018
877e620
camera: ignore missing defaults for now
julianoes Apr 17, 2018
8207824
camera: get settings and options tests to work
julianoes Apr 17, 2018
18a755c
mavlink_parameters: fix missing return
julianoes Apr 18, 2018
a3d3d92
call_every_handler: correctly invalidate iterator
julianoes Apr 18, 2018
4fed230
any: add copy test
julianoes Apr 18, 2018
f162c42
mavlink_parameters: assigment operator for value
julianoes Apr 18, 2018
bbcd979
mavlink_system: add generic param interface
julianoes Apr 18, 2018
4965f56
camera: rename settings API (no more key)
julianoes Apr 18, 2018
e003bc5
camera_definition: method for option from string
julianoes Apr 18, 2018
b541d79
mavlink_parameters: missing is_type methods
julianoes Apr 18, 2018
4329a23
mavlink_system: generic param setters
julianoes Apr 18, 2018
3ebd5b9
camera: implement setting/getting params
julianoes Apr 18, 2018
770cd9d
mavlink_parameters: add type check to avoid abort
julianoes Apr 19, 2018
cd5f905
camera: fix unit/integration tests
julianoes Apr 19, 2018
80460c0
camera: sleep a bit more for tests
julianoes Apr 19, 2018
eaf1cf5
camera: don't set mode if already correct
julianoes Apr 19, 2018
1781bfe
camera: remove some verbosity, improve printfs
julianoes Apr 19, 2018
6211461
camera: include and link to curl
julianoes Apr 19, 2018
6249eaa
video streaming: Improve naming of members
Apr 20, 2018
cd7b264
camera_definition: added human readable names
julianoes Apr 20, 2018
c3a2682
Merge branch 'develop' into add-camera
julianoes Apr 20, 2018
1367076
core: remove ERROR define
julianoes Apr 20, 2018
3bba620
camera: remove some wrong or unnecessary comments
julianoes Apr 20, 2018
efdfa43
build_system: remove unnecesary comments
julianoes Apr 20, 2018
1ff5fdd
camera: improve and add comments
julianoes Apr 20, 2018
6f40598
camera: add getter for setting/option names
julianoes Apr 20, 2018
ff2580d
camera: use std::string instead of const char*
julianoes Apr 20, 2018
35a7e83
appveyor: copy dronecore_camera.dll for unit tests
julianoes Apr 20, 2018
a94ff6d
camera: the lastest E90 version has more options
julianoes Apr 20, 2018
993bcf5
camera: don't do E90 specific tests by default
julianoes Apr 20, 2018
6f63912
camera: add tests for Yuneec E50 and ET as well
julianoes Apr 20, 2018
8c54323
camera: get mode before set mode not needed
julianoes Apr 20, 2018
7594450
appveyor: copy tinyxml2.dll for unit test
julianoes Apr 20, 2018
c8a5c17
Minor docs fixes
hamishwillee Apr 23, 2018
bcb5009
video stream: Add missing docs
Apr 23, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
path = core/third_party/curl-android-ios
url = https://github.com/dronecore/curl-android-ios.git
[submodule "tinyxml2"]
path = core/third_party/tinyxml2
path = third_party/tinyxml2
url = https://github.com/leethomason/tinyxml2.git
[submodule "dronecore-proto"]
path = backend/proto
Expand Down
35 changes: 35 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,41 @@ endif()
set(dronecore_install_include_dir "include/dronecore")
set(dronecore_install_lib_dir ${lib_path})

# We need tinyxml2 for the camera definition parsing.
add_subdirectory(third_party/tinyxml2 EXCLUDE_FROM_ALL)
link_directories(third_party/tinyxml2)
include_directories(SYSTEM third_party/tinyxml2)
set(TINYXML2_LIBRARY tinyxml2)

if(APPLE AND NOT IOS)
# We install the tinyxml2 library manually for macOS and iOS.
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
# Need to remove that d again.
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/third_party/tinyxml2/libtinyxml2d.6.0.0.dylib
DESTINATION ${lib_path}
#RENAME libtinyxml2.dylib
)
else()
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/third_party/tinyxml2/libtinyxml2.6.0.0.dylib
DESTINATION ${lib_path}
#RENAME libtinyxml2.dylib
)
endif()
elseif(ANDROID)
# We install the tinyxml2 library manually for Android.
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
# Need to remove that d again.
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/third_party/tinyxml2/libtinyxml2d.so
DESTINATION ${lib_path}
RENAME libtinyxml2.so
)
else()
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/third_party/tinyxml2/libtinyxml2.so
DESTINATION ${lib_path}
)
endif()
endif()

add_subdirectory(core)
add_subdirectory(plugins)

Expand Down
6 changes: 5 additions & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ clone_folder: C:\dronecore
before_build:

- cd C:\dronecore
- git submodule update --init --recursive --depth 20
- git submodule update --init --recursive --depth 100
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't wanna know :D

- cd C:\
- appveyor DownloadFile https://curl.haxx.se/download/curl-7.56.1.zip
- 7z x -y curl-7.56.1.zip
Expand Down Expand Up @@ -148,12 +148,16 @@ test_script:
copy build\third_party\gtest\googlemock\Debug\gmockd.dll build\Debug\ &&
copy build\plugins\mission\Debug\dronecore_mission.dll build\Debug\ &&
copy build\plugins\mission\third_party\json11\Debug\json11.dll build\Debug\ &&
copy build\plugins\camera\Debug\dronecore_camera.dll build\Debug\ &&
copy build\third_party\tinyxml2\Debug\tinyxml2d.dll build\Debug\ &&
build\Debug\unit_tests_runner.exe
) else (
copy build\third_party\gtest\googlemock\gtest\Release\gtest.dll build\Release\ &&
copy build\third_party\gtest\googlemock\gtest\Release\gtest_main.dll build\Release\ &&
copy build\third_party\gtest\googlemock\Release\gmock.dll build\Release\ &&
copy build\plugins\mission\Release\dronecore_mission.dll build\Release\ &&
copy build\plugins\mission\third_party\json11\Release\json11.dll build\Release\ &&
copy build\plugins\camera\Release\dronecore_camera.dll build\Release\ &&
copy build\third_party\tinyxml2\Release\tinyxml2.dll build\Release\ &&
build\Release\unit_tests_runner.exe
)
6 changes: 4 additions & 2 deletions cmake/compiler_flags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,16 @@ else()
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
set(warnings "${warnings} -Wno-missing-braces -Wno-unused-parameter")
endif()

# Otherwise tinyxml2 complains.
set(warnings "${warnings} -Wno-old-style-cast")
endif()

# We need a define if on APPLE
if(APPLE)
add_definitions("-DAPPLE")
endif()

# Add DEBUG define for Debug target
# Add DEBUG define for Debug target because that is not done automatically.
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG")

set(CMAKE_CXX_FLAGS_COVERAGE "${CMAKE_CXX_FLAGS_COVERAGE} --coverage")
Expand Down
1 change: 1 addition & 0 deletions cmake/unit_tests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ set_target_properties(unit_tests_runner
target_link_libraries(unit_tests_runner
dronecore
dronecore_mission
dronecore_camera
gtest
gtest_main
gmock
Expand Down
52 changes: 1 addition & 51 deletions core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,57 +12,6 @@ else()
set(LIBRARY_TYPE "SHARED")
endif()

# We need tinyxml2 for the camera definition parsing.
if(APPLE)
if(NOT IOS)
# We install the tinyxml2 library manually for macOS and iOS.
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
# Need to remove that d again.
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/third_party/tinyxml2/libtinyxml2d.5.0.1.dylib
DESTINATION ${lib_path}
#RENAME libtinyxml2.dylib
)
else()
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/third_party/tinyxml2/libtinyxml2.5.0.1.dylib
DESTINATION ${lib_path}
#RENAME libtinyxml2.dylib
)
endif()

add_subdirectory(third_party/tinyxml2 EXCLUDE_FROM_ALL)
include_directories(SYSTEM third_party/tinyxml2)
link_directories(third_party/tinyxml2)
set(TINYXML2_LIBRARY tinyxml2)
endif()
elseif(ANDROID)
# We install the tinyxml2 library manually for Android.
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
# Need to remove that d again.
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/third_party/tinyxml2/libtinyxml2d.so
DESTINATION ${lib_path}
RENAME libtinyxml2.so
)
else()
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/third_party/tinyxml2/libtinyxml2.so
DESTINATION ${lib_path}
)
endif()

add_subdirectory(third_party/tinyxml2 EXCLUDE_FROM_ALL)
include_directories(SYSTEM third_party/tinyxml2)
link_directories(third_party/tinyxml2)
set(TINYXML2_LIBRARY tinyxml2)
elseif(MSVC)
add_subdirectory(third_party/tinyxml2 EXCLUDE_FROM_ALL)
include_directories(SYSTEM third_party/tinyxml2)
link_directories(third_party/tinyxml2)
set(TINYXML2_LIBRARY tinyxml2)
else()
# For Linux for now we use the system tinyxml2, otherwise the unit test crashes
# miraculously.
set(TINYXML2_LIBRARY tinyxml2)
endif()

add_library(dronecore ${LIBRARY_TYPE}
call_every_handler.cpp
connection.cpp
Expand Down Expand Up @@ -140,5 +89,6 @@ list(APPEND UNIT_TEST_SOURCES
${CMAKE_SOURCE_DIR}/core/timeout_handler_test.cpp
${CMAKE_SOURCE_DIR}/core/call_every_handler_test.cpp
${CMAKE_SOURCE_DIR}/core/curl_test.cpp
${CMAKE_SOURCE_DIR}/core/any_test.cpp
)
set(UNIT_TEST_SOURCES ${UNIT_TEST_SOURCES} PARENT_SCOPE)
135 changes: 135 additions & 0 deletions core/any.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
#pragma once

#include <type_traits>
#include <utility>
#include <typeinfo>
#include <cassert>
#include "log.h"

namespace dronecore {

// Any class taken from:
// https://codereview.stackexchange.com/questions/20058/c11-any-class


template <class T>
using StorageType = typename std::decay<T>::type;

struct Any {
bool is_null() const { return !ptr; }
bool not_null() const { return ptr; }

template<typename U> Any(U &&value)
: ptr(new Derived<StorageType<U>>(std::forward<U>(value))) {}

template<class U> bool is() const
{
typedef StorageType<U> T;

auto derived = dynamic_cast<Derived<T>*>(ptr);

return derived;
}

template<class U>
StorageType<U> &as() const
{
typedef StorageType<U> T;

auto derived = dynamic_cast<Derived<T>*>(ptr);

if (!derived) {
// FIXME: We don't have exceptions, so this is commented out
// and we'll abort instead.
//throw bad_cast();
LogErr() << "Need to abort because of a bad_cast";
abort();
}

return derived->value;
}

template<class U>
operator U() const
{
return as<StorageType<U>>();
}

Any()
: ptr(nullptr) {}

Any(Any &that)
: ptr(that.clone()) {}

Any(Any &&that)
: ptr(that.ptr)
{
that.ptr = nullptr;
}

Any(const Any &that)
: ptr(that.clone()) {}

Any(const Any &&that)
: ptr(that.clone()) {}

Any &operator=(const Any &a)
{
if (ptr == a.ptr) {
return *this;
}

auto old_ptr = ptr;

ptr = a.clone();

delete old_ptr;

return *this;
}

Any &operator=(Any &&a)
{
if (ptr == a.ptr) {
return *this;
}

std::swap(ptr, a.ptr);

return *this;
}

~Any()
{
delete ptr;
}

private:
struct Base {
virtual ~Base() {}

virtual Base *clone() const = 0;
};

template<typename T>
struct Derived : Base {
template<typename U> Derived(U &&value_tmp) : value(std::forward<U>(value_tmp)) { }

T value;

Base *clone() const { return new Derived<T>(value); }
};

Base *clone() const
{
if (ptr) {
return ptr->clone();
} else {
return nullptr;
}
}

Base *ptr;
};

} // namespace dronecore
62 changes: 62 additions & 0 deletions core/any_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@

#include <string>
#include "any.h"
#include <gtest/gtest.h>

using namespace dronecore;

TEST(Any, StringAndInt)
{
Any n;
ASSERT_TRUE(n.is_null());

std::string s1 = "foo";

Any a1 = s1;

ASSERT_TRUE(a1.not_null());
ASSERT_TRUE(a1.is<std::string>());
ASSERT_TRUE(!a1.is<int>());

Any a2(a1);

ASSERT_TRUE(a2.not_null());
ASSERT_TRUE(a2.is<std::string>());
ASSERT_TRUE(!a2.is<int>());

std::string s2 = a2;

ASSERT_TRUE(s1 == s2);
}

TEST(Any, Casts)
{
const int some_number = 42;
Any n;
ASSERT_TRUE(n.is_null());

int i = some_number;
n = i;

ASSERT_TRUE(n.not_null());
ASSERT_EQ(n.as<int>(), some_number);

// We can't actually cast using `as`.
ASSERT_FLOAT_EQ(float(n.as<int>()), float(some_number));
}

TEST(Any, Copys)
{
const float some_float = 0.7f;

Any n1;
Any n2;
ASSERT_TRUE(n1.is_null());
ASSERT_TRUE(n2.is_null());

n1 = some_float;
n2 = n1;
ASSERT_TRUE(n1.is<float>());
ASSERT_TRUE(n2.is<float>());
ASSERT_TRUE(n1.as<float>() == n2.as<float>());
}
8 changes: 8 additions & 0 deletions core/call_every_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ void CallEveryHandler::remove(const void *cookie)
auto it = _entries.find(const_cast<void *>(cookie));
if (it != _entries.end()) {
_entries.erase(const_cast<void *>(cookie));
_iterator_invalidated = true;
}
}

Expand All @@ -81,6 +82,13 @@ void CallEveryHandler::run_once()
_entries_mutex.lock();
}
}

// We leave the loop.
// FIXME: there should be a nicer way to do this.
Copy link
Collaborator

@JonasVautherin JonasVautherin Apr 19, 2018

Choose a reason for hiding this comment

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

(Just trying, maybe it's not better)

size_t i = 0;
while (i < _entries.size() && !_iterator_invalidated) {
    ...
    i++;
}

... instead of the for loop of line 68. Or maybe it's a do...while in this case? Again, maybe not better. But a while makes it clear that it stops under some condition, whereas a for is supposed to go through a range.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yer I like it, thanks.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The problem with your suggestion is that the i++ still happens without check because during the loop while the callback is called, the remove can happen.

if (_iterator_invalidated) {
_iterator_invalidated = false;
break;
}
}
_entries_mutex.unlock();
}
Expand Down
1 change: 1 addition & 0 deletions core/call_every_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class CallEveryHandler

std::map<void *, std::shared_ptr<Entry>> _entries {};
std::mutex _entries_mutex {};
bool _iterator_invalidated {false};

Time &_time;
};
Expand Down
Loading