-
-
Notifications
You must be signed in to change notification settings - Fork 515
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ff7c993
commit 2c4c82c
Showing
25 changed files
with
19,999 additions
and
2 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,15 @@ | ||
target_sources(mavsdk | ||
PRIVATE | ||
gripper.cpp | ||
gripper_impl.cpp | ||
) | ||
|
||
target_include_directories(mavsdk PUBLIC | ||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> | ||
$<INSTALL_INTERFACE:include/mavsdk> | ||
) | ||
|
||
install(FILES | ||
include/plugins/gripper/gripper.h | ||
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/mavsdk/plugins/gripper | ||
) |
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,75 @@ | ||
// WARNING: THIS FILE IS AUTOGENERATED! As such, it should not be edited. | ||
// Edits need to be made to the proto files | ||
// (see https://github.com/mavlink/MAVSDK-Proto/blob/master/protos/gripper/gripper.proto) | ||
|
||
#include <iomanip> | ||
|
||
#include "gripper_impl.h" | ||
#include "plugins/gripper/gripper.h" | ||
|
||
namespace mavsdk { | ||
|
||
Gripper::Gripper(System& system) : PluginBase(), _impl{std::make_unique<GripperImpl>(system)} {} | ||
|
||
Gripper::Gripper(std::shared_ptr<System> system) : | ||
PluginBase(), | ||
_impl{std::make_unique<GripperImpl>(system)} | ||
{} | ||
|
||
Gripper::~Gripper() {} | ||
|
||
void Gripper::grab_async(uint32_t instance, const ResultCallback callback) | ||
{ | ||
_impl->grab_async(instance, callback); | ||
} | ||
|
||
Gripper::Result Gripper::grab(uint32_t instance) const | ||
{ | ||
return _impl->grab(instance); | ||
} | ||
|
||
void Gripper::release_async(uint32_t instance, const ResultCallback callback) | ||
{ | ||
_impl->release_async(instance, callback); | ||
} | ||
|
||
Gripper::Result Gripper::release(uint32_t instance) const | ||
{ | ||
return _impl->release(instance); | ||
} | ||
|
||
std::ostream& operator<<(std::ostream& str, Gripper::Result const& result) | ||
{ | ||
switch (result) { | ||
case Gripper::Result::Unknown: | ||
return str << "Unknown"; | ||
case Gripper::Result::Success: | ||
return str << "Success"; | ||
case Gripper::Result::NoSystem: | ||
return str << "No System"; | ||
case Gripper::Result::Busy: | ||
return str << "Busy"; | ||
case Gripper::Result::Timeout: | ||
return str << "Timeout"; | ||
case Gripper::Result::Unsupported: | ||
return str << "Unsupported"; | ||
case Gripper::Result::Failed: | ||
return str << "Failed"; | ||
default: | ||
return str << "Unknown"; | ||
} | ||
} | ||
|
||
std::ostream& operator<<(std::ostream& str, Gripper::GripperAction const& gripper_action) | ||
{ | ||
switch (gripper_action) { | ||
case Gripper::GripperAction::Release: | ||
return str << "Release"; | ||
case Gripper::GripperAction::Grab: | ||
return str << "Grab"; | ||
default: | ||
return str << "Unknown"; | ||
} | ||
} | ||
|
||
} // namespace mavsdk |
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,118 @@ | ||
#include "gripper_impl.h" | ||
|
||
namespace mavsdk { | ||
|
||
GripperImpl::GripperImpl(System& system) : PluginImplBase(system) | ||
{ | ||
_parent->register_plugin(this); | ||
} | ||
|
||
GripperImpl::GripperImpl(std::shared_ptr<System> system) : PluginImplBase(std::move(system)) | ||
{ | ||
_parent->register_plugin(this); | ||
} | ||
|
||
GripperImpl::~GripperImpl() | ||
{ | ||
_parent->unregister_plugin(this); | ||
} | ||
|
||
void GripperImpl::init() {} | ||
|
||
void GripperImpl::deinit() {} | ||
|
||
void GripperImpl::enable() {} | ||
|
||
void GripperImpl::disable() {} | ||
|
||
void GripperImpl::grab_async(uint32_t instance, const Gripper::ResultCallback callback) | ||
{ | ||
MavlinkCommandSender::CommandLong command{}; | ||
|
||
command.command = MAV_CMD_DO_GRIPPER; | ||
command.params.maybe_param1 = instance; | ||
command.params.maybe_param2 = static_cast<float>(Gripper::GripperAction::Grab); | ||
|
||
command.target_component_id = MAV_COMPONENT::MAV_COMP_ID_WINCH; // TODO | ||
|
||
_parent->send_command_async( | ||
command, [this, callback](MavlinkCommandSender::Result result, float) { | ||
command_result_callback(result, callback); | ||
}); | ||
} | ||
|
||
Gripper::Result GripperImpl::grab(uint32_t instance) | ||
{ | ||
auto prom = std::promise<Gripper::Result>(); | ||
auto fut = prom.get_future(); | ||
|
||
grab_async(instance, [&prom](Gripper::Result result) { prom.set_value(result); }); | ||
|
||
return fut.get(); | ||
} | ||
|
||
void GripperImpl::release_async(uint32_t instance, const Gripper::ResultCallback callback) | ||
{ | ||
MavlinkCommandSender::CommandLong command{}; | ||
|
||
command.command = MAV_CMD_DO_GRIPPER; | ||
command.params.maybe_param1 = instance; | ||
command.params.maybe_param2 = static_cast<float>(Gripper::GripperAction::Release); | ||
|
||
command.target_component_id = MAV_COMPONENT::MAV_COMP_ID_WINCH; // TODO | ||
|
||
_parent->send_command_async( | ||
command, [this, callback](MavlinkCommandSender::Result result, float) { | ||
command_result_callback(result, callback); | ||
}); | ||
} | ||
|
||
Gripper::Result GripperImpl::release(uint32_t instance) | ||
{ | ||
auto prom = std::promise<Gripper::Result>(); | ||
auto fut = prom.get_future(); | ||
|
||
release_async(instance, [&prom](Gripper::Result result) { prom.set_value(result); }); | ||
|
||
return fut.get(); | ||
} | ||
|
||
Gripper::Result GripperImpl::gripper_result_from_command_result(MavlinkCommandSender::Result result) | ||
{ | ||
switch (result) { | ||
case MavlinkCommandSender::Result::Success: | ||
return Gripper::Result::Success; | ||
case MavlinkCommandSender::Result::NoSystem: | ||
return Gripper::Result::NoSystem; | ||
case MavlinkCommandSender::Result::ConnectionError: | ||
// Fallthrough | ||
case MavlinkCommandSender::Result::Timeout: | ||
return Gripper::Result::Timeout; | ||
case MavlinkCommandSender::Result::Busy: | ||
return Gripper::Result::Busy; | ||
case MavlinkCommandSender::Result::Denied: | ||
// Fallthrough | ||
case MavlinkCommandSender::Result::TemporarilyRejected: | ||
// Fallthrough | ||
case MavlinkCommandSender::Result::Failed: | ||
return Gripper::Result::Failed; | ||
case MavlinkCommandSender::Result::Unsupported: | ||
return Gripper::Result::Unsupported; | ||
default: | ||
return Gripper::Result::Unknown; | ||
} | ||
} | ||
|
||
void GripperImpl::command_result_callback( | ||
MavlinkCommandSender::Result command_result, const Gripper::ResultCallback& callback) const | ||
{ | ||
Gripper::Result action_result = gripper_result_from_command_result(command_result); | ||
|
||
if (callback) { | ||
auto temp_callback = callback; | ||
_parent->call_user_callback( | ||
[temp_callback, action_result]() { temp_callback(action_result); }); | ||
} | ||
} | ||
|
||
} // namespace mavsdk |
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,35 @@ | ||
#pragma once | ||
|
||
#include "plugins/gripper/gripper.h" | ||
|
||
#include "plugin_impl_base.h" | ||
|
||
namespace mavsdk { | ||
|
||
class GripperImpl : public PluginImplBase { | ||
public: | ||
explicit GripperImpl(System& system); | ||
explicit GripperImpl(std::shared_ptr<System> system); | ||
|
||
~GripperImpl() override; | ||
|
||
void init() override; | ||
void deinit() override; | ||
|
||
void enable() override; | ||
void disable() override; | ||
|
||
void grab_async(uint32_t instance, const Gripper::ResultCallback callback); | ||
Gripper::Result grab(uint32_t instance); | ||
|
||
void release_async(uint32_t instance, const Gripper::ResultCallback callback); | ||
Gripper::Result release(uint32_t instance); | ||
|
||
private: | ||
static Gripper::Result gripper_result_from_command_result(MavlinkCommandSender::Result result); | ||
|
||
void command_result_callback( | ||
MavlinkCommandSender::Result command_result, const Gripper::ResultCallback& callback) const; | ||
}; | ||
|
||
} // namespace mavsdk |
Oops, something went wrong.