-
-
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 #2093 from prokas-nikos/dist_sensor_orientation
Customizing distance sensor to add orientation for multiple sensor support
- Loading branch information
Showing
10 changed files
with
839 additions
and
295 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
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(distance_sensor) | ||
|
||
add_executable(distance_sensor | ||
distance_sensor.cpp | ||
) | ||
|
||
find_package(MAVSDK REQUIRED) | ||
|
||
target_link_libraries(distance_sensor | ||
MAVSDK::mavsdk | ||
) | ||
|
||
if(NOT MSVC) | ||
add_compile_options(distance_sensor PRIVATE -Wall -Wextra) | ||
else() | ||
add_compile_options(distance_sensor 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,74 @@ | ||
// | ||
// Simple example to demonstrate how to imitate that all distance sensor | ||
// readings are read from all orientations. | ||
// | ||
// Author: Julian Oes <julian@oes.ch> | ||
|
||
#include <mavsdk/mavsdk.h> | ||
#include <mavsdk/plugins/mavlink_passthrough/mavlink_passthrough.h> | ||
#include <mavsdk/plugins/telemetry/telemetry.h> | ||
#include <chrono> | ||
#include <cstdint> | ||
#include <iostream> | ||
#include <future> | ||
#include <memory> | ||
#include <thread> | ||
|
||
using namespace mavsdk; | ||
using std::chrono::seconds; | ||
|
||
static void subscribe_distance_sensor(Telemetry& telemetry); | ||
|
||
void usage(const std::string& bin_name) | ||
{ | ||
std::cerr << "Usage : " << bin_name << " <connection_url>\n" | ||
<< "Connection URL format should be :\n" | ||
<< " For TCP : tcp://[server_host][:server_port]\n" | ||
<< " For UDP : udp://[bind_host][:bind_port]\n" | ||
<< " For Serial : serial:///path/to/serial/dev[:baudrate]\n" | ||
<< "For example, to connect to the simulator use URL: udp://:14540\n"; | ||
} | ||
|
||
int main(int argc, char** argv) | ||
{ | ||
if (argc != 2) { | ||
usage(argv[0]); | ||
return 1; | ||
} | ||
|
||
Mavsdk mavsdk; | ||
ConnectionResult connection_result = mavsdk.add_any_connection(argv[1]); | ||
|
||
if (connection_result != ConnectionResult::Success) { | ||
std::cerr << "Connection failed: " << connection_result << '\n'; | ||
return 1; | ||
} | ||
|
||
auto system = mavsdk.first_autopilot(3.0); | ||
if (!system) { | ||
std::cerr << "Timed out waiting for system\n"; | ||
return 1; | ||
} | ||
|
||
// Instantiate plugins. | ||
auto telemetry = Telemetry{system.value()}; | ||
|
||
// subscribe to distance sensor readings | ||
subscribe_distance_sensor(telemetry); | ||
|
||
// endless loop so that the sensor readings will keep comming | ||
// will close only with kill or Ctrl+C | ||
while (true) { | ||
std::this_thread::sleep_for(std::chrono::seconds(1)); | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
void subscribe_distance_sensor(Telemetry& telemetry) | ||
{ | ||
telemetry.subscribe_distance_sensor([](Telemetry::DistanceSensor dist_sensor) { | ||
std::cout << "Distance sensor dist: " << dist_sensor.current_distance_m | ||
<< " - orient: " << dist_sensor.orientation << '\n'; | ||
}); | ||
} |
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.