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

How to set custom_mode in HEARTBEAT #2514

Open
souljt01 opened this issue Feb 19, 2025 · 2 comments
Open

How to set custom_mode in HEARTBEAT #2514

souljt01 opened this issue Feb 19, 2025 · 2 comments

Comments

@souljt01
Copy link

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, add_capablilities() also have the same problem, so I modified them as follows.
Sever_component.cpp
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.

@julianoes
Copy link
Collaborator

We should implement standard flight modes in MAVSDK which will make this easier/possible.

See: https://mavlink.io/en/services/standard_modes.html

@souljt01
Copy link
Author

Thanks for your reply. I'm trying to implement MAVSDK on my vehicle and I want to make my vehicle controllable with QGC. I'm facing an issue where GCS is not displaying the flight mode transmitted from the vehicle.
I can see that mavsdk is sending a heartbeat below.

void ServerComponentImpl::send_heartbeat()
{
    queue_message([&](MavlinkAddress mavlink_address, uint8_t channel) {
        mavlink_message_t message;
        mavlink_msg_heartbeat_pack_chan(
            get_own_system_id(),
            mavlink_address.component_id,
            channel,
            &message,
            _mavsdk_impl.get_mav_type(),
            mavlink_address.component_id == MAV_COMP_ID_AUTOPILOT1 ? MAV_AUTOPILOT_GENERIC :
                                                                     MAV_AUTOPILOT_INVALID,
            mavlink_address.component_id == MAV_COMP_ID_AUTOPILOT1 ? _base_mode.load() : 0,
            mavlink_address.component_id == MAV_COMP_ID_AUTOPILOT1 ? _custom_mode.load() : 0,
            get_system_status());
        return message;
    });
}

_base_mode, _custom_mode, and related functions are also private and cannot be accessed from my vehicle.
So I tried this on my vehicle:

  1. Send MAV_CMD_DO_SET_MODE with base_mode and custom_mode in the vehicle, but QGC does not display the flight mode sent by the vehicle.

  2. Send HEARTBEAT message in the vehicle. However, QGC displays the flight mode sent by the vehicle, but it changes to the HEARTBEAT message sent by MAVSDK itself.

So, what I would like to suggest is to change the following functions to public.

class ActionServerImpl : public ServerPluginImplBase {
private:
void set_base_mode(uint8_t base_mode);
uint8_t get_base_mode() const;

void set_custom_mode(uint32_t custom_mode);
uint32_t get_custom_mode() const;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants