Hi! I am trying to manually set the home position through the command MAV_CMD_DO_SET_HOME. How can it be done for SITL simulation? Is there a way to do it via MAVSDK?
Thanks in advance!
Hi!
I think that the way to do it via MAVSDK is use class MavlinkPassthrough · MAVSDK Guide
If it works, describe how you implemented the solution.
Also (I think) it will be useful:
Hi @Artem_Borisov!
I have been trying your suggestion of using MavlinkPassthrough example. Since the example ‘battery.cpp’ actually uses the Passthrough functionality I tried to write my code based on that example. My code is a modification of the example ‘takeoff_and_land.py’ in which I included the modifications to send the mavlink command ‘MAV_CMD_SO_SET_HOME’.
This the function I am trying to use:
void set_home_position(MavlinkPassthrough& mavlink_passthrough)
{mavlink_message_t message; mavlink_msg_command_long_pack( mavlink_passthrough.get_our_sysid(), mavlink_passthrough.get_our_compid(), &message, mavlink_passthrough.get_target_sysid(), // Target system mavlink_passthrough.get_target_compid(), // Target component MAV_CMD_DO_SET_HOME, // Command 0, // Confirmation 0, // Param 1 0, // Param 2 0, // Param 3 NAN, // Param 4 47.3984906, // Param 5 8.5449444, // Param 6 50); // Param 7 mavlink_passthrough.send_message(message);
}
And this is the message I get on the terminal:
If you have any idea on how to fix it, it would be really appreciated!
Hi, @Xun!
I think your problem is that you use send_message for sending command .
Try send_command_long, its more simpe.
mavsdk::MavlinkPassthrough::CommandLong ComLong;
ComLong.target_compid = mavlink_passthrough.get_target_compid();
ComLong.target_sysid = mavlink_passthrough.get_target_sysid();
ComLong.command = MAV_CMD_DO_SET_HOME;
ComLong.param1 = 0;
ComLong.param2 = 0;
ComLong.param3 = 0;
ComLong.param4 = NAN;
ComLong.param5 = 47.3984906;
ComLong.param6 = 8.5449444;
ComLong.param7 = 50;
mavlink_passthrough.send_command_long(ComLong);
Sorry, not sure
Thank you so much for the help and the suggestion @Artem_Borisov !
I tried your proposal, but unfortunately I am getting a command rejection:
Do you have an idea of what could be the cause? I am afraid I am a bit lost with this Passthrough functionality.
Thank you in advance
Hi!
I tried your code on my drone, it work same way.
https://mavlink.io/en/messages/common.html#MAV_RESULT
Command is valid, but cannot be executed at this time. This is used to indicate a problem that should be fixed just by waiting (e.g. a state machine is busy, can’t arm because have not got GPS lock, etc.). Retrying later should work.
So, you do all right, but something wrong in state of drone, or its parammetrs.
Sorry, I don’t know more than you. I have some problem with MAVSDK and PX4 too. You can see (for interests) my posts in history.
Thank you for the help @Artem_Borisov, it is much appreciated.
Maybe someone else with similar issues will help us with this.