-
-
Notifications
You must be signed in to change notification settings - Fork 524
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
plugins: added skeleton for mission_raw plugin
This will be a plugin which enables direct/raw access to MAVLink MISSION_ITEM_INT messages.
- Loading branch information
Showing
7 changed files
with
309 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
add_library(dronecode_sdk_mission_raw ${PLUGIN_LIBRARY_TYPE} | ||
mission_raw.cpp | ||
mission_raw_impl.cpp | ||
) | ||
|
||
include_directories( | ||
${PROJECT_SOURCE_DIR}/core | ||
) | ||
|
||
set_target_properties(dronecode_sdk_mission_raw | ||
PROPERTIES COMPILE_FLAGS ${warnings} | ||
) | ||
|
||
target_link_libraries(dronecode_sdk_mission_raw | ||
dronecode_sdk | ||
) | ||
|
||
install(FILES | ||
include/plugins/mission_raw/mission_raw.h | ||
DESTINATION ${dronecode_sdk_install_include_dir} | ||
) | ||
|
||
install(TARGETS dronecode_sdk_mission_raw | ||
#EXPORT dronecode_sdk-targets | ||
DESTINATION ${dronecode_sdk_install_lib_dir} | ||
) | ||
|
||
target_include_directories(dronecode_sdk_mission_raw | ||
PUBLIC | ||
${CMAKE_CURRENT_SOURCE_DIR}/include | ||
PRIVATE | ||
${CMAKE_CURRENT_SOURCE_DIR} | ||
) |
133 changes: 133 additions & 0 deletions
133
plugins/mission_raw/include/plugins/mission_raw/mission_raw.h
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,133 @@ | ||
#pragma once | ||
|
||
#include <vector> | ||
#include <memory> | ||
#include <functional> | ||
#include "plugin_base.h" | ||
|
||
namespace dronecode_sdk { | ||
|
||
class MissionRawImpl; | ||
class System; | ||
|
||
/** | ||
* @brief The MissionRaw class enables direct direct access to MAVLink | ||
* mission items. | ||
*/ | ||
class MissionRaw : public PluginBase { | ||
public: | ||
/** | ||
* @brief Constructor. Creates the plugin for a specific System. | ||
* | ||
* The plugin is typically created as shown below: | ||
* | ||
* ```cpp | ||
* auto mission_raw = std::make_shared<MissionRaw>(system); | ||
* ``` | ||
* | ||
* @param system The specific system associated with this plugin. | ||
*/ | ||
explicit MissionRaw(System &system); | ||
|
||
/** | ||
* @brief Destructor (internal use only). | ||
*/ | ||
~MissionRaw(); | ||
|
||
/** | ||
* @brief Possible results returned for mission requests. | ||
*/ | ||
enum class Result { | ||
UNKNOWN, /**< @brief Unknown error. */ | ||
SUCCESS, /**< @brief %Request succeeded. */ | ||
ERROR, /**< @brief Error. */ | ||
BUSY, /**< @brief %Vehicle busy. */ | ||
TIMEOUT, /**< @brief Request timed out. */ | ||
INVALID_ARGUMENT, /**< @brief Invalid argument. */ | ||
NO_MISSION_AVAILABLE, /**< @brief No mission available on system. */ | ||
CANCELLED /**< @brief Mission upload or download has been cancelled. */ | ||
}; | ||
|
||
/** | ||
* @brief Gets a human-readable English string for an MissionRaw::Result. | ||
* | ||
* @param result Enum for which string is required. | ||
* @return Human readable string for the MissionRaw::Result. | ||
*/ | ||
static const char *result_str(Result result); | ||
|
||
/** | ||
* @brief Mission item identical to MAVLink MISSION_ITEM_INT. | ||
*/ | ||
struct MavlinkMissionItemInt { | ||
uint8_t target_system; /**< @brief System ID. */ | ||
uint8_t target_component; /**< @brief Component ID. */ | ||
uint16_t seq; /**< @brief Sequence. */ | ||
uint8_t frame; /**< @brief The coordinate system of the waypoint. */ | ||
uint16_t command; /**< @brief The scheduled action for the waypoint. */ | ||
uint8_t current; /**< @brief false:0, true:1. */ | ||
uint8_t autocontinue; /**< @brief Autocontinue to next waypoint. */ | ||
float param1; /**< @brief PARAM1, see MAV_CMD enum. */ | ||
float param2; /**< @brief PARAM2, see MAV_CMD enum. */ | ||
float param3; /**< @brief PARAM3, see MAV_CMD enum. */ | ||
float param4; /**< @brief PARAM4, see MAV_CMD enum. */ | ||
int32_t x; /**< @brief PARAM5 / local: x position in meters * 1e4, global: latitude in | ||
degrees * 10^7. */ | ||
int32_t y; /**< @brief PARAM6 / y position: local: x position in meters * 1e4, global: | ||
longitude in degrees *10^7. */ | ||
float z; /**< @brief PARAM7 / local: Z coordinate, global: altitude (relative or absolute, | ||
depending on frame). */ | ||
uint8_t mission_type; /**< @brief Mission type. */ | ||
}; | ||
|
||
/** | ||
* @brief Type for vector of mission items. | ||
*/ | ||
typedef std::function<void(Result, std::vector<std::shared_ptr<MavlinkMissionItemInt>>)> | ||
mission_items_and_result_callback_t; | ||
|
||
/** | ||
* @brief Downloads a vector of mission items from the system (asynchronous). | ||
* | ||
* The method will fail if any of the downloaded mission items are not supported | ||
* by the Dronecode SDK API. | ||
* | ||
* @param callback Callback to receive mission items and result of this request. | ||
*/ | ||
void download_mission_async(mission_items_and_result_callback_t callback); | ||
|
||
/** | ||
* @brief Cancel a mission download (asynchronous). | ||
* | ||
* This cancels an ongoing mission download. The mission download will fail | ||
* with the result `Result::CANCELLED`. | ||
*/ | ||
void download_mission_cancel(); | ||
|
||
/** | ||
* @brief Callback type to signal if the mission has changed. | ||
*/ | ||
typedef std::function<void()> mission_changed_callback_t; | ||
|
||
/** | ||
* @brief Subscribes to mission progress (asynchronous). | ||
* | ||
* @param callback Callback to receive mission progress. | ||
*/ | ||
void subscribe_mission_changed(mission_changed_callback_t callback); | ||
|
||
/** | ||
* @brief Copy constructor (object is not copyable). | ||
*/ | ||
MissionRaw(const MissionRaw &) = delete; | ||
/** | ||
* @brief Equality operator (object is not copyable). | ||
*/ | ||
const MissionRaw &operator=(const MissionRaw &) = delete; | ||
|
||
private: | ||
/** @private Underlying implementation, set at instantiation */ | ||
std::unique_ptr<MissionRawImpl> _impl; | ||
}; | ||
|
||
} // namespace dronecode_sdk |
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,47 @@ | ||
#include "plugins/mission_raw/mission_raw.h" | ||
#include "mission_raw_impl.h" | ||
#include <vector> | ||
|
||
namespace dronecode_sdk { | ||
|
||
MissionRaw::MissionRaw(System &system) : PluginBase(), _impl{new MissionRawImpl(system)} {} | ||
|
||
MissionRaw::~MissionRaw() {} | ||
|
||
void MissionRaw::download_mission_async(MissionRaw::mission_items_and_result_callback_t callback) | ||
{ | ||
_impl->download_mission_async(callback); | ||
} | ||
|
||
void MissionRaw::download_mission_cancel() | ||
{ | ||
_impl->download_mission_cancel(); | ||
} | ||
|
||
const char *MissionRaw::result_str(Result result) | ||
{ | ||
switch (result) { | ||
case Result::SUCCESS: | ||
return "Success"; | ||
case Result::BUSY: | ||
return "Busy"; | ||
case Result::ERROR: | ||
return "Error"; | ||
case Result::INVALID_ARGUMENT: | ||
return "Invalid argument"; | ||
case Result::TIMEOUT: | ||
return "Timeout"; | ||
case Result::CANCELLED: | ||
return "Cancelled"; | ||
case Result::UNKNOWN: | ||
default: | ||
return "Unknown"; | ||
} | ||
} | ||
|
||
void MissionRaw::subscribe_mission_changed(mission_changed_callback_t callback) | ||
{ | ||
_impl->subscribe_mission_changed(callback); | ||
} | ||
|
||
} // namespace dronecode_sdk |
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,56 @@ | ||
#include "mission_raw_impl.h" | ||
#include "system.h" | ||
#include "global_include.h" | ||
#include <fstream> // for `std::ifstream` | ||
#include <sstream> // for `std::stringstream` | ||
#include <cmath> | ||
|
||
namespace dronecode_sdk { | ||
|
||
using namespace std::placeholders; // for `_1` | ||
|
||
MissionRawImpl::MissionRawImpl(System &system) : PluginImplBase(system) | ||
{ | ||
_parent->register_plugin(this); | ||
} | ||
|
||
MissionRawImpl::~MissionRawImpl() | ||
{ | ||
_parent->unregister_plugin(this); | ||
} | ||
|
||
void MissionRawImpl::init() | ||
{ | ||
_parent->register_mavlink_message_handler( | ||
MAVLINK_MSG_ID_MISSION_ACK, | ||
std::bind(&MissionRawImpl::process_mission_ack, this, _1), | ||
this); | ||
} | ||
|
||
void MissionRawImpl::deinit() | ||
{ | ||
_parent->unregister_all_mavlink_message_handlers(this); | ||
} | ||
|
||
void MissionRawImpl::enable() {} | ||
|
||
void MissionRawImpl::disable() {} | ||
|
||
void MissionRawImpl::process_mission_ack(const mavlink_message_t &message) | ||
{ | ||
mavlink_mission_ack_t mission_ack; | ||
mavlink_msg_mission_ack_decode(&message, &mission_ack); | ||
UNUSED(mission_ack); | ||
|
||
// TODO: need to report that mission might have changed. | ||
} | ||
|
||
void MissionRawImpl::download_mission_async( | ||
const MissionRaw::mission_items_and_result_callback_t &callback) | ||
{ | ||
UNUSED(callback); | ||
} | ||
|
||
void MissionRawImpl::download_mission_cancel() {} | ||
|
||
} // namespace dronecode_sdk |
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,33 @@ | ||
#pragma once | ||
|
||
#include "system.h" | ||
#include "mavlink_include.h" | ||
#include "plugins/mission_raw/mission_raw.h" | ||
#include "plugin_impl_base.h" | ||
|
||
namespace dronecode_sdk { | ||
|
||
class MissionRawImpl : public PluginImplBase { | ||
public: | ||
MissionRawImpl(System &system); | ||
~MissionRawImpl(); | ||
|
||
void init() override; | ||
void deinit() override; | ||
|
||
void enable() override; | ||
void disable() override; | ||
|
||
void download_mission_async(const MissionRaw::mission_items_and_result_callback_t &callback); | ||
void download_mission_cancel(); | ||
|
||
void subscribe_mission_changed(MissionRaw::mission_changed_callback_t callback); | ||
|
||
MissionRawImpl(const MissionRawImpl &) = delete; | ||
const MissionRawImpl &operator=(const MissionRawImpl &) = delete; | ||
|
||
private: | ||
void process_mission_ack(const mavlink_message_t &message); | ||
}; | ||
|
||
} // namespace dronecode_sdk |