Skip to content

Support sending GPS_GLOBAL_ORIGIN and DO_SET_HOME commands #108

@tedlin0913

Description

@tedlin0913

Hello!
Thank you for this great work. My goal is to use this library together with VIO for position estimation in order to fly my drone in GNSS-denied areas. To achieve this, I followed the px4 guide on enable auto mode with local position, which suggests sending the VEHICLE_CMD_SET_GPS_GLOBAL_ORIGIN command. In addition, VEHICLE_CMD_DO_SET_HOME can be used to set the home position once the global position estimate is available.
I am now trying to figure out how to send these two VehicleCommands correctly using this library. So far, I have attempted to send the commands via sendCommandSync in my mode executor ModeExecutorTest, which inherits from ModeExecutorBase. The functions I written for sending the command looks like this:

void ModeExecutorTest::setHome(const CompletedCallback &on_completed)
{
    if (is_home_set_)
    {
        on_completed(Result::Success);
        return;
    }
    // TODO: check if global position is available before sending the command? 
    const Result result = sendCommandSync(
        px4_msgs::msg::VehicleCommand::VEHICLE_CMD_DO_SET_HOME,
        1.f);

    // TODO: maybe subscribe HomePosition.msg to check if home position is availible?

    if (result != Result::Success)
    {
        on_completed(result);
        return;
    }
}

void ModeExecutorTest::setGlobalOrigin(const CompletedCallback &on_completed)
{
    if (is_origin_set_)
    {
        on_completed(Result::Success);
        return;
    }
   
    // VEHICLE_CMD_SET_GPS_GLOBAL_ORIGIN does not send back a VehicleCommandAck.
    sendCommandSync(
        px4_msgs::msg::VehicleCommand::VEHICLE_CMD_SET_GPS_GLOBAL_ORIGIN,
        NAN, NAN, NAN, NAN,
        0.0, 0.0, 0.0);
}

VEHICLE_CMD_DO_SET_HOME sends back a VehicleCommandAck, whereas VEHICLE_CMD_SET_GPS_GLOBAL_ORIGIN does not.

I plan to use these commands in runState. Two follow up questions occur:

  1. How can I check, inside the mode executor, when the global position estimate becomes available, before setting the home position?
  2. How can I subscribe to HomePosition.msg to detect when the home position becomes available, and then set on_completed to Result::Success using this library?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions