Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dds mode switch through external control #28696

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion libraries/AP_DDS/AP_DDS_Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -896,7 +896,11 @@ void AP_DDS_Client::on_request(uxrSession* uxr_session, uxrObjectId object_id, u
if (deserialize_success == false) {
break;
}
mode_switch_response.status = AP::vehicle()->set_mode(mode_switch_request.mode, ModeReason::DDS_COMMAND);
#if AP_EXTERNAL_CONTROL_ENABLED
mode_switch_response.status = AP_DDS_External_Control::set_mode(mode_switch_request.mode);
#else // AP_EXTERNAL_CONTROL_ENABLED
mode_switch_response.status = false;
#endif // AP_EXTERNAL_CONTROL_ENABLED
mode_switch_response.curr_mode = AP::vehicle()->get_mode();

const uxrObjectId replier_id = {
Expand Down
14 changes: 13 additions & 1 deletion libraries/AP_DDS/AP_DDS_ExternalControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@

#include "AP_DDS_ExternalControl.h"
#include "AP_DDS_Frames.h"
#include <AP_AHRS/AP_AHRS.h>

#include <AP_AHRS/AP_AHRS.h>
#include <AP_ExternalControl/AP_ExternalControl.h>
#include <AP_Vehicle/AP_Vehicle.h>
#include <AP_Vehicle/ModeReason.h>

// These are the Goal Interface constants. Because microxrceddsgen does not expose
// them in the generated code, they are manually maintained
Expand Down Expand Up @@ -105,6 +107,16 @@ bool AP_DDS_External_Control::disarm(AP_Arming::Method method, bool do_disarm_ch
return external_control->disarm(method, do_disarm_checks);
}

bool AP_DDS_External_Control::set_mode(const uint8_t mode)
{
auto *external_control = AP::externalcontrol();
if (external_control == nullptr) {
return false;
}

return external_control->set_mode(mode, ModeReason::DDS_COMMAND);
}

bool AP_DDS_External_Control::convert_alt_frame(const uint8_t frame_in, Location::AltFrame& frame_out)
{

Expand Down
1 change: 1 addition & 0 deletions libraries/AP_DDS/AP_DDS_ExternalControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class AP_DDS_External_Control
static bool handle_velocity_control(geometry_msgs_msg_TwistStamped& cmd_vel);
static bool arm(AP_Arming::Method method, bool do_arming_checks);
static bool disarm(AP_Arming::Method method, bool do_disarm_checks);
static bool set_mode(const uint8_t mode);

private:
static bool convert_alt_frame(const uint8_t frame_in, Location::AltFrame& frame_out);
Expand Down
7 changes: 7 additions & 0 deletions libraries/AP_ExternalControl/AP_ExternalControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#if AP_EXTERNAL_CONTROL_ENABLED

#include <AP_Vehicle/AP_Vehicle.h>

// singleton instance
AP_ExternalControl *AP_ExternalControl::singleton;

Expand All @@ -15,6 +17,11 @@ bool AP_ExternalControl::disarm(AP_Arming::Method method, bool do_disarm_checks)
return AP::arming().disarm(method, do_disarm_checks);
}

bool AP_ExternalControl::set_mode(const uint8_t mode, const ModeReason reason)
{
return AP::vehicle()->set_mode(mode, reason);
}

AP_ExternalControl::AP_ExternalControl()
{
singleton = this;
Expand Down
6 changes: 6 additions & 0 deletions libraries/AP_ExternalControl/AP_ExternalControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <AP_Arming/AP_Arming.h>
#include <AP_Common/Location.h>
#include <AP_Math/AP_Math.h>
#include <AP_Vehicle/ModeReason.h>

class AP_ExternalControl
{
Expand Down Expand Up @@ -43,6 +44,11 @@ class AP_ExternalControl
*/
virtual bool disarm(AP_Arming::Method method, bool do_disarm_checks) WARN_IF_UNUSED;

/*
Set the mode of the vehicle. The mode number is vehicle specific.
*/
virtual bool set_mode(const uint8_t mode, const ModeReason reason) WARN_IF_UNUSED;

static AP_ExternalControl *get_singleton(void) WARN_IF_UNUSED {
return singleton;
}
Expand Down
Loading