Send mavlink message for drone go to specific position

hello guys i’m using mavlink c++ applications. after the drone takeoff, i would like to send the mavlink message to tell the drone to go to a specific location.

  • My firmware PX4 autopilot
  • Mavlink 2 c++

i was archived that by change drone to OFFBOARD mode and then send the position_target_global_int message.

but my target is do the similar thing like the QGroundcontrol do without change the drone mode. the goto_position when click to the QGC screen.

i also used mavlink MAV_CMD_DO_REPOSITION message

mavlink_msg_command_long_pack(
        system_id,              // System ID of GCS
        component_id,           // Component ID of GCS
        &message,               // MAVLink message
        target_system,          // Target system ID
        target_component,       // Target component ID
        MAV_CMD_DO_REPOSITION,                // Command ID
        current,                // Confirmation (0: first transmission)
        param1,                 // Parameter 1
        static_cast<float>(MAV_DO_REPOSITION_FLAGS_CHANGE_MODE),                 // Parameter 2
        param3,                 // Parameter 3
        param4,                 // Parameter 4
        int32_t(std::round(latitude * 1e7)),               // Parameter 5: Latitude
        int32_t(std::round(longitude * 1e7)),              // Parameter 6: Longitude
        60                // Parameter 7: Altitude
    );

but the drone keep moving south and not go to my target
please help me !

it might be easier to use MAVSDK instead of low level mavlink2.
then, you can use this example for creating a mission:
https://mavsdk.mavlink.io/v1.4/en/cpp/examples/fly_mission.html

you might also want to read more about differences between offboard and mission modes:
https://mavsdk.mavlink.io/v1.4/en/cpp/guide/missions.html
https://mavsdk.mavlink.io/v1.4/en/cpp/guide/offboard.html

In short, as I understand when you click in QGC for “go to”, it creates a mission. and yes, you can create this missions programmatically with mavlink.

Hi, thank you for the reply. however, i dont think click goto_position in QGC will create a mission. a very small example is i uploaded a plan in to drone. start mission then pause (the drone will be HOLD mode). click goto_position. the drone keep in (HOLD mode) but it move to desired position and the old plan still in the drone firmware

yes, you are right for that feature it must be
MAV_CMD_OVERRIDE_GOTO

Still it would be much easier to use it with MAVSDK Action API “goto_location” (should be a wrapper around the same command):
https://mavsdk.mavlink.io/main/en/cpp/api_reference/classmavsdk_1_1_action.html#classmavsdk_1_1_action_1afb3546fa994357e491816f2032716818