How to set custom_mode in HEARTBEAT

I want to know how to set the base_mode and custom_mode in HEARTBEAT.

HEARTBEAT (0) 
Field Name
base_mode, 
custom_mode

I am working on a vehicle side and using Server plugins. I have the following process:

QGC -> Send "Takeoff" command -> Vehicle take off
QGC <- Send "Custom_mode" with "AUTO:TAKEOFF" <- Vehicle
QGC show "AUTO:TAKEOFF"

But set_custom_mode() is private API in MAVSDK

void ServerComponentImpl::send_heartbeat()
{

mavlink_address.component_id == MAV_COMP_ID_AUTOPILOT1 ? _base_mode.load() : 0,
mavlink_address.component_id == MAV_COMP_ID_AUTOPILOT1 ? _custom_mode.load() : 0,

}
class ActionServerImpl : public ServerPluginImplBase {
private:
void set_base_mode(uint8_t base_mode);
void set_custom_mode(uint32_t custom_mode);
}

And I tried “mavlink_msg_set_mode_pack_chan()” to send the message but it doesn’t work.

So I modified the MAVSDK in action_server.cpp

void ActionServer::set_base_mode(uint8_t base_mode) const
{
_impl->set_base_mode(base_mode);
}
void ActionServer::set_custom_mode(uint32_t custom_mode) const
{
_impl->set_custom_mode(custom_mode);
}

Additionally, set_system_status() and add_capablilities() also have the same problem, so I modified them as follows.
Sever_component.cpp

void ServerComponent::set_system_status(uint8_t system_status)
{
_impl->set_system_status(system_status);
}
void ServerComponent::add_capablilities(uint64_t capablilities)
{
if (_impl) {
_impl->add_capabilities(capablilities);
}
}

I want to use MAVSDK without modifying it. I want to know if there is another way.

1 Like