Send GPS to ardupilot in mavlink packets for PosHold or Loiter

Hello, I am using speedyBee f4v4. My goal is custom visual odometry which will compute gps coordinates and send them to flight controller via Mavlink to allow the copter to hold position in mode Loiter or PosHold. I tried to emulate NMEA gps packets and send them via serial, but it always says gps unhealthy or PosHold required position. So how can I send gps via Mavlink to allow copter initialize position and hold position without real gps. @rmackay9

@ollksander welcome to the community,

there are lots of posts addressing the issue you are describing. Search the forum. But I can already tell you that it is a complex and difficult topic.

@amilcarlucas Yes, I searched the forum, all recommend the optical flow or vision_position_estimate setup for FlowHold, but it is not suitable for me, I need just emulate sending gps coordinates.

mavlink_msg_gps_input message is what you are looking for.

Hi @ollksander,

I’ve been meaning to write a wiki page on this subject for quite some time. In general though I’d recommend using the ODOMETRY message if you can instead of using a fake GPS. The only downside is that you’d need to set the EKF origin but that can be done through a lua script or mavlink.

You’ve probably already seen it but our mavlink interface wiki page is here.

Thank you so much @rmackay9 , as I understand I should send ODOMETRY (331) mavlink message, but how should I configure ardupilot on my copter to consider ODOMETRY message and what system and component id I should send with it? And will Loiter work with this configuration?

@rmackay9 Can you help with ardupilot configuration, please?