Skip to content

Commit

Permalink
Merge c027f9c into 556a84e
Browse files Browse the repository at this point in the history
  • Loading branch information
julianoes committed Aug 17, 2018
2 parents 556a84e + c027f9c commit ad83af5
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 81 deletions.
13 changes: 1 addition & 12 deletions appveyor.yml
Expand Up @@ -37,8 +37,6 @@ before_build:
- cd C:\
- appveyor DownloadFile https://curl.haxx.se/download/curl-7.56.1.zip
- 7z x -y curl-7.56.1.zip
- appveyor DownloadFile https://dl.bintray.com/boostorg/release/1.64.0/source/boost_1_64_0.7z
- 7z x -y boost_1_64_0.7z

build: on

Expand All @@ -65,15 +63,6 @@ build_script:
) else (
cmake --build . --target install --config Release
)
- cd C:\boost_1_64_0
- set boost_dir=C:\boost_1_64_0
- set cores=%NUMBER_OF_PROCESSORS%
- set msvcver=msvc-14.1
- cd %boost_dir%
- bootstrap.bat
- b2 --with-system --with-date_time --j%cores% toolset=%msvcver% address-model=64 architecture=x86 link=static threading=multi runtime-link=shared --build-type=minimal stage --stagedir=stage/x64
- set BOOST_ROOT=%boost_dir%
- set BOOST_LIBRARYDIR=%boost_dir%\stage\x64\lib
- cd %dronecode_sdk_dir%
- cd example\takeoff_land
- md build
Expand Down Expand Up @@ -118,7 +107,7 @@ build_script:
- cd example\follow_me
- md build
- cd build
- cmake .. -G "Visual Studio 15 2017 Win64" -DBoost_USE_STATIC_LIBS=ON
- cmake .. -G "Visual Studio 15 2017 Win64"
- if "%configuration%"=="Debug" (
cmake --build . --config Debug
) else (
Expand Down
10 changes: 3 additions & 7 deletions example/follow_me/CMakeLists.txt
Expand Up @@ -2,31 +2,27 @@ cmake_minimum_required(VERSION 2.8.12)

project(follow_me)

find_package(Threads REQUIRED)

if(NOT MSVC)
add_definitions("-std=c++11 -Wall -Wextra -Werror")
# Line below required if /usr/local/include is not in your default includes
#include_directories(/usr/local/include)
# Line below required if /usr/local/lib is not in your default linker path
#link_directories(/usr/local/lib)
find_package(Boost 1.58 COMPONENTS system REQUIRED )
else()
include_directories(${CMAKE_SOURCE_DIR}/../../install/include)
link_directories(${CMAKE_SOURCE_DIR}/../../install/lib)
add_definitions("-std=c++11 -WX -W2")
find_package(Boost 1.64 COMPONENTS system date_time REQUIRED )
# This is to avoid auto-linking of libraries that we don't build
add_definitions("-DBOOST_ALL_NO_LIB")
endif()

include_directories(${Boost_INCLUDE_DIR})

add_executable(follow_me
follow_me.cpp
fake_location_provider.cpp
)

target_link_libraries(follow_me
LINK_PUBLIC ${Boost_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT}
dronecode_sdk
dronecode_sdk_action
dronecode_sdk_follow_me
Expand Down
94 changes: 52 additions & 42 deletions example/follow_me/fake_location_provider.cpp
Expand Up @@ -6,56 +6,66 @@
using std::this_thread::sleep_for;
using std::chrono::seconds;

FakeLocationProvider::FakeLocationProvider() {}

FakeLocationProvider::~FakeLocationProvider()
{
stop();
}

void FakeLocationProvider::request_location_updates(location_callback_t callback)
{
location_callback_ = callback;
timer_.async_wait(std::bind(&FakeLocationProvider::compute_next_location, this));
stop();
start();
}

void FakeLocationProvider::start()
{
should_exit_ = false;
thread_ = new std::thread(&FakeLocationProvider::compute_locations, this);
}

void FakeLocationProvider::stop()
{
should_exit_ = true;

if (thread_) {
thread_->join();
delete thread_;
thread_ = nullptr;
}
}

// Rudimentary location provider whose successive lat, lon combination
// makes Drone revolve in a semi-circular path.
void FakeLocationProvider::compute_next_location()
void FakeLocationProvider::compute_locations()
{
if (count_++ < 10) {
location_callback_(latitude_deg_, longitude_deg_);
latitude_deg_ -= LATITUDE_DEG_PER_METER * 4;
timer_.expires_at(timer_.expires_at() + boost::posix_time::seconds(1));
timer_.async_wait(std::bind(&FakeLocationProvider::compute_next_location, this));
sleep_for(seconds(1));
}
if (count_++ < 20) {
location_callback_(latitude_deg_, longitude_deg_);
longitude_deg_ += LONGITUDE_DEG_PER_METER * 4;
timer_.expires_at(timer_.expires_at() + boost::posix_time::seconds(1));
timer_.async_wait(std::bind(&FakeLocationProvider::compute_next_location, this));
sleep_for(seconds(1));
}
if (count_++ < 30) {
location_callback_(latitude_deg_, longitude_deg_);
latitude_deg_ += LATITUDE_DEG_PER_METER * 4;
timer_.expires_at(timer_.expires_at() + boost::posix_time::seconds(1));
timer_.async_wait(std::bind(&FakeLocationProvider::compute_next_location, this));
sleep_for(seconds(1));
}
if (count_++ < 40) {
location_callback_(latitude_deg_, longitude_deg_);
longitude_deg_ -= LONGITUDE_DEG_PER_METER * 4;
timer_.expires_at(timer_.expires_at() + boost::posix_time::seconds(1));
timer_.async_wait(std::bind(&FakeLocationProvider::compute_next_location, this));
sleep_for(seconds(1));
}
if (count_++ < 50) {
location_callback_(latitude_deg_, longitude_deg_);
latitude_deg_ -= LATITUDE_DEG_PER_METER * 3;
timer_.expires_at(timer_.expires_at() + boost::posix_time::seconds(1));
timer_.async_wait(std::bind(&FakeLocationProvider::compute_next_location, this));
sleep_for(seconds(1));
}
if (count_++ < MAX_LOCATIONS) {
location_callback_(latitude_deg_, longitude_deg_);
longitude_deg_ += LONGITUDE_DEG_PER_METER * 3;
timer_.expires_at(timer_.expires_at() + boost::posix_time::seconds(1));
timer_.async_wait(std::bind(&FakeLocationProvider::compute_next_location, this));
while (!should_exit_) {
if (count_++ < 10) {
location_callback_(latitude_deg_, longitude_deg_);
latitude_deg_ -= LATITUDE_DEG_PER_METER * 4;
}
if (count_++ < 20) {
location_callback_(latitude_deg_, longitude_deg_);
longitude_deg_ += LONGITUDE_DEG_PER_METER * 4;
}
if (count_++ < 30) {
location_callback_(latitude_deg_, longitude_deg_);
latitude_deg_ += LATITUDE_DEG_PER_METER * 4;
}
if (count_++ < 40) {
location_callback_(latitude_deg_, longitude_deg_);
longitude_deg_ -= LONGITUDE_DEG_PER_METER * 4;
}
if (count_++ < 50) {
location_callback_(latitude_deg_, longitude_deg_);
latitude_deg_ -= LATITUDE_DEG_PER_METER * 3;
}
if (count_++ < MAX_LOCATIONS) {
location_callback_(latitude_deg_, longitude_deg_);
longitude_deg_ += LONGITUDE_DEG_PER_METER * 3;
}
sleep_for(seconds(1));
}
}
Expand Down
26 changes: 10 additions & 16 deletions example/follow_me/fake_location_provider.h
@@ -1,18 +1,8 @@
#pragma once

#include <functional>
/**
********************************************************************************************
********************************************************************************************
Important note: Boost isn't a dependency for the Dronecode SDK library.
We're using Boost::Asio in this example ONLY to simulate asynchronous Fake location provider.
Applications on platforms Android, Windows, Apple, etc should make use of their platform-specific
Location Provider in place of FakeLocationProvider.
********************************************************************************************
********************************************************************************************
*/
#include <boost/asio.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <atomic>
#include <thread>

/**
* @brief The FakeLocationProvider class
Expand All @@ -22,16 +12,20 @@ class FakeLocationProvider {
public:
typedef std::function<void(double lat, double lon)> location_callback_t;

FakeLocationProvider(boost::asio::io_service &io) : timer_(io, boost::posix_time::seconds(1)) {}
FakeLocationProvider();

~FakeLocationProvider() {}
~FakeLocationProvider();

void request_location_updates(location_callback_t callback);

private:
void compute_next_location();
void start();
void stop();
void compute_locations();

std::thread *thread_{nullptr};
std::atomic<bool> should_exit_{false};

boost::asio::deadline_timer timer_;
location_callback_t location_callback_ = nullptr;
double latitude_deg_ = 47.3977419;
double longitude_deg_ = 8.5455938;
Expand Down
6 changes: 2 additions & 4 deletions example/follow_me/follow_me.cpp
Expand Up @@ -116,14 +116,12 @@ int main(int argc, char **argv)
follow_me_result = follow_me->start();
follow_me_error_exit(follow_me_result, "Failed to start FollowMe mode");

boost::asio::io_service io; // for event loop
std::unique_ptr<FakeLocationProvider> location_provider(new FakeLocationProvider(io));
FakeLocationProvider location_provider;
// Register for platform-specific Location provider. We're using FakeLocationProvider for the
// example.
location_provider->request_location_updates([&system, &follow_me](double lat, double lon) {
location_provider.request_location_updates([&system, &follow_me](double lat, double lon) {
follow_me->set_target_location({lat, lon, 0.0, 0.f, 0.f, 0.f});
});
io.run(); // will run as long as location updates continue to happen.

// Stop Follow Me
follow_me_result = follow_me->stop();
Expand Down

0 comments on commit ad83af5

Please sign in to comment.