Fake GPS via mavlink HIL_GPS message

I’m attempting to provide fake GPS data (generated via mavros from an opitrack motion capture system) to arducopter. According to this pull request the HIL_GPS message, which is generated by mavros, should be able to do this.

I am sending the HIL_GPS message over telemetry cable to the TELEM2 port on a Pixhawk 2.1. I am able to see the HIL_GPS message coming through correctly in the Mavlink Inspector of QGroundControl, but there is still no GPS fix.

image

I know that the HIL_GPS message is generated correctly, as I am able to get a GPS fix using the PX4 flight stack and setting then MAV_USEHILGPS parameter to 1.

I have tried Ardupilot Firmware versions 3.4.6, 3.5.5, and 3.6.0dev, all with the same result.

What am I missing?

1 Like

The parameter I was missing was GPS_TYPE = 14 (mavlink)

1 Like

I am doing similar thing with you. I want to inject GPS data (generated from other position sources). Could you provide more detail on how to generate the message? Do you use “dronekit” to do this?

@Mana_Saedan - I wasn’t using dronekit to generate the HIL_GPS message, though I’m fairly sure that would be possible as well.

Instead, I used the mavros fake_gps plugin. To use this plugin, you publish a ROS pose message to the /mavros/fake_gps/mocap/pose ROS topic and the plugin generates a HIL_GPS message that gets sent to the ardupilot. You can find some example configurations on this thread.

As a bit of a caveat, I haven’t been able to achieve a reliable position hold with this method, though I believe others have. I’ve recently tried using some other message types that seem better suited to the task, but haven’t had success with that method yet either.

1 Like

@vkurtz hey, just a quick newbie question. Is a mocap system necessary to introduce fake gps in my HIL simulation?? I’ve tried to change the gps coordinates of my HIL setup (Gazebo+QGC) from the default Zurich Irchel Park by just changing the lat, long and alt positions in the fake_gps.cpp plugging but the mavros is still reporting the default coordinates. I have not understood the plugin fully yet. Am I missing something? Kindly help me, thanks in advance :slight_smile:

@pranavn248 no, a mocap system isn’t necessary to introduce fake gps. All you need is something that publishes to the /mavros/fake_gps/mocap/pose topic. Then instead of changing fake_gps.cpp by hand, you should set the default coordinates via parameters in a yaml file (by default apm_config.yaml, part of the mavros package) like the one in the question here.

2 Likes

@vkurtz understood, thanks a ton.

@vkurtz Thank you for your pointer. I do manage to get the “fake gps” to make the copter fly in loiter mode. My positioning system came from DWM1001 (UWB). Currently it is to early to enclose all settings and coding (python-dronekit).

My first run is still having some “GPS glitch” that I could not figure out how it came from. And too excite to take any video. Other than that, the copter was held in place nicely. I hope we can share information that will benefit to others who do this kind of things. I am also interested in ROS but the time is not allowed me to sit and study it throughly.

@Mana_Saedan
Good evening dear,
Can you explain me how you connect dwm1001?
I want create a similar setup, like raspberry, pixhawk and dwm1001.
Can you share some suggestions?
Thank you for your time and consideration