Skip to content

Commit

Permalink
action: add option to force arming (#2276)
Browse files Browse the repository at this point in the history
This is for bench things.

Signed-off-by: Julian Oes <julian@oes.ch>
  • Loading branch information
julianoes committed Apr 12, 2024
1 parent 2e76c14 commit 585936c
Show file tree
Hide file tree
Showing 11 changed files with 1,541 additions and 507 deletions.
2 changes: 1 addition & 1 deletion proto
10 changes: 10 additions & 0 deletions src/mavsdk/plugins/action/action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ Action::Result Action::arm() const
return _impl->arm();
}

void Action::arm_force_async(const ResultCallback callback)
{
_impl->arm_force_async(callback);
}

Action::Result Action::arm_force() const
{
return _impl->arm_force();
}

void Action::disarm_async(const ResultCallback callback)
{
_impl->disarm_async(callback);
Expand Down
25 changes: 25 additions & 0 deletions src/mavsdk/plugins/action/action_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,16 @@ Action::Result ActionImpl::arm() const
return fut.get();
}

Action::Result ActionImpl::arm_force() const
{
auto prom = std::promise<Action::Result>();
auto fut = prom.get_future();

arm_force_async([&prom](Action::Result result) { prom.set_value(result); });

return fut.get();
}

Action::Result ActionImpl::disarm() const
{
auto prom = std::promise<Action::Result>();
Expand Down Expand Up @@ -285,6 +295,21 @@ bool ActionImpl::need_hold_before_arm_apm() const
}
}

void ActionImpl::arm_force_async(const Action::ResultCallback& callback) const
{
MavlinkCommandSender::CommandLong command{};

command.command = MAV_CMD_COMPONENT_ARM_DISARM;
command.params.maybe_param1 = 0.0f; // arm
command.params.maybe_param2 = 21196.f; // magic number to force
command.target_component_id = _system_impl->get_autopilot_id();

_system_impl->send_command_async(
command, [this, callback](MavlinkCommandSender::Result result, float) {
command_result_callback(result, callback);
});
}

void ActionImpl::disarm_async(const Action::ResultCallback& callback) const
{
MavlinkCommandSender::CommandLong command{};
Expand Down
2 changes: 2 additions & 0 deletions src/mavsdk/plugins/action/action_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class ActionImpl : public PluginImplBase {
void disable() override;

Action::Result arm() const;
Action::Result arm_force() const;
Action::Result disarm() const;
Action::Result terminate() const;
Action::Result kill() const;
Expand All @@ -47,6 +48,7 @@ class ActionImpl : public PluginImplBase {
Action::Result transition_to_multicopter() const;

void arm_async(const Action::ResultCallback& callback) const;
void arm_force_async(const Action::ResultCallback& callback) const;
void disarm_async(const Action::ResultCallback& callback) const;
void terminate_async(const Action::ResultCallback& callback) const;
void kill_async(const Action::ResultCallback& callback) const;
Expand Down
26 changes: 26 additions & 0 deletions src/mavsdk/plugins/action/include/plugins/action/action.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,32 @@ class Action : public PluginBase {
*/
Result arm() const;

/**
* @brief Send command to force-arm the drone without any checks.
*
* Attention: this is not to be used for normal flying but only bench tests!
*
* Arming a drone normally causes motors to spin at idle.
* Before arming take all safety precautions and stand clear of the drone!
*
* This function is non-blocking. See 'arm_force' for the blocking counterpart.
*/
void arm_force_async(const ResultCallback callback);

/**
* @brief Send command to force-arm the drone without any checks.
*
* Attention: this is not to be used for normal flying but only bench tests!
*
* Arming a drone normally causes motors to spin at idle.
* Before arming take all safety precautions and stand clear of the drone!
*
* This function is blocking. See 'arm_force_async' for the non-blocking counterpart.
*
* @return Result of request.
*/
Result arm_force() const;

/**
* @brief Send command to disarm the drone.
*
Expand Down
1 change: 1 addition & 0 deletions src/mavsdk/plugins/action/mocks/action_mock.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace testing {
class MockAction {
public:
MOCK_CONST_METHOD0(arm, Action::Result()){};
MOCK_CONST_METHOD0(arm_force, Action::Result()){};
MOCK_CONST_METHOD0(disarm, Action::Result()){};
MOCK_CONST_METHOD0(takeoff, Action::Result()){};
MOCK_CONST_METHOD0(land, Action::Result()){};
Expand Down
124 changes: 83 additions & 41 deletions src/mavsdk_server/src/generated/action/action.grpc.pb.cc

Large diffs are not rendered by default.

564 changes: 371 additions & 193 deletions src/mavsdk_server/src/generated/action/action.grpc.pb.h

Large diffs are not rendered by default.

758 changes: 529 additions & 229 deletions src/mavsdk_server/src/generated/action/action.pb.cc

Large diffs are not rendered by default.

Loading

0 comments on commit 585936c

Please sign in to comment.