Fake GPS with APM

Hello, I am new in building up a drone on my own. I am utilizing ArduPilot as the firmware for my vehicle, which is interfaced with MAVROS (MAVLink to ROS). Additionally, the hardware includes APM (ArduPilot Mega) for enhanced control and autonomy.

However, i am stuck at changing to guided mode due to “Position Estimate Required” along with “No GPS Fix” and is unable to take off the drone automatically.

I understand that position hold requires an Optical Flow Sensor which i am planning to get. Meanwhile, i tried solving the GPS issue. This were the steps taken:

  1. In /opt/ros/noetic, i created a catkin_workspace and inside i created “fake_gps_node”.

This is the code:
#!/usr/bin/env python3

import rospy
from sensor_msgs.msg import NavSatFix
from std_msgs.msg import Header

def fake_gps_node():
rospy.init_node(‘fake_gps_node’, anonymous=True)
gps_pub = rospy.Publisher(‘/mavros/fake_gps/mavros/gpsfix’, NavSatFix, queue_size=10)
rate = rospy.Rate(1) # 1 Hz

while not rospy.is_shutdown():
    gps_data = NavSatFix()
    gps_data.header = Header()
    gps_data.header.stamp = rospy.Time.now()
    gps_data.header.frame_id = 'fake_gps_frame'
    gps_data.latitude = 47.3667 # Replace with your desired latitude
    gps_data.longitude = 8.55# Replace with your desired longitude
    gps_data.altitude = 408.5  # Replace with your desired altitude
    gps_pub.publish(gps_data)
    rate.sleep()

if name == ‘main’:
try:
fake_gps_node()
except rospy.ROSInterruptException:
pass

  1. i went into opt/ros/noetic/share/mavros/launch and edited the apm.launch file.

This is the updated code:

<node pkg="fake_gps" type="fake_gps_node.py" name="fake_gps_node" output="screen"/>

<arg name="fcu_url" default="udp://:flight_controller_ip@" />
<arg name="gcs_url" default="udp://:14551@laptop_ip with QGCS" />
<arg name="tgt_system" default="1" />
<arg name="tgt_component" default="1" />
<arg name="log_output" default="screen" />
<arg name="fcu_protocol" default="v2.0" />
<arg name="respawn_mavros" default="false" />

<include file="$(find mavros)/launch/node.launch">
    <arg name="pluginlists_yaml" value="$(find mavros)/launch/apm_p$ />
    <arg name="config_yaml" value="$(find mavros)/launch/apm_config$ />

    <arg name="fcu_url" value="$(arg fcu_url)" />
    <arg name="gcs_url" value="$(arg gcs_url)" />
    <arg name="tgt_system" value="$(arg tgt_system)" />
    <arg name="tgt_component" value="$(arg tgt_component)" />
    <arg name="log_output" value="$(arg log_output)" />
    <arg name="fcu_protocol" value="$(arg fcu_protocol)" />
    <arg name="respawn_mavros" value="$(arg respawn_mavros)" />
</include>
  1. I rebooted the entire system and used “source /opt/ros/noetic/catkin_workspace/devel/setup.bash” before running “roslaunch mavros apm.launch”

Upon running, i did see the fake_gps_node got loaded together but QGroundControl still symbolises no gps fix.

This are some diagnostic informations:

header:
seq: 9
stamp:
secs: 1703731499
status:
nsecs: 628628492
frame_id: “fake_gps_frame”
status: 0
service: 0
latitude: 47.3667
longitude: 8.55
altitude: 408.0
position_covariance: [0.0, 0.0, 0.0, 0.0,
0.0, 0.0, 0.0, 0.0, 0.0]
position_covariance_type: 0

&

INOGE L/Take_gps_node]
Publications:
*/mavros/fake_gps/mavros/gpsfix [sensor_msgs/NavSatFix]

  • /rosout [rosgraph_msgs/Log]
    Services:
    Subscriptions: None
    */fake_gps_node/get_loggers */fake_gps_node/set_logger_level
    contacting node http://navio:44413/
    Pid: 14481
    Connections:
  • topic: /rosout
  • to: /rosout
  • direction: ound (41055-127.0.0.1:33124) [9]

May i ask what is it that i am doing wrong? Thank you!