Data transfer for smoothing на Ardupilot PX4

Hello everyone, I hope you are doing well. Could you please tell me how I can send information to the Ardupilot PX4 flight controller, such as the number of satellites or coordinates, by spoofing the GPS data.

And here is an example of my code.

import time
import logging
from pymavlink import mavutil
import random

# Set up logging
logging.basicConfig(level=logging.DEBUG)

def send_gps_raw_int(master, time_usec, fix_type, lat, lon, alt, eph, epv, vel, cog, satellites):
    logging.debug(f"Preparing to send GPS_RAW_INT with the following parameters: "
                  f"time_usec={time_usec}, fix_type={fix_type}, lat={lat}, lon={lon}, alt={alt}, "
                  f"eph={eph}, epv={epv}, vel={vel}, cog={cog}, satellites={satellites}")
    
    # Send GPS_RAW_INT message
    master.mav.gps_raw_int_send(
        time_usec,     # UNIX time in microseconds
        fix_type,      # GPS fix type (0: no fix, 1: 2D fix, 2: 3D fix)
        lat,           # Latitude (WGS84), in degrees * 1E7
        lon,           # Longitude (WGS84), in degrees * 1E7
        alt,           # Altitude (AMSL, not WGS84), in meters * 1000 (positive for up)
        eph,           # GPS HDOP horizontal dilution of position in cm (unknown if 65535)
        epv,           # GPS VDOP vertical dilution of position in cm (unknown if 65535)
        vel,           # GPS ground speed (m/s * 100). If unknown, set to 65535
        cog,           # Course over ground (degrees * 100). If unknown, set to 65535
        satellites     # Number of satellites visible. If unknown, set to 255
    )
    
    message = master.recv_match(type='GPS_RAW_INT', timeout=1)
    if message:
        logging.info(f"Message sent and received back: "
                     f"time_usec={message.time_usec}, fix_type={message.fix_type}, lat={message.lat}, "
                     f"lon={message.lon}, alt={message.alt}, eph={message.eph}, epv={message.epv}, "
                     f"vel={message.vel}, cog={message.cog}, satellites_visible={message.satellites_visible}")
    else:
        logging.warning("Message sent but no response received")

def receive_gps_raw_int(client):
    msg = client.recv_match(type='GPS_RAW_INT', blocking=True)
    if msg:
        logging.info(f"Received GPS_RAW_INT: "
                     f"time_usec={msg.time_usec}, fix_type={msg.fix_type}, lat={msg.lat}, lon={msg.lon}, "
                     f"alt={msg.alt}, eph={msg.eph}, epv={msg.epv}, vel={msg.vel}, cog={msg.cog}, "
                     f"satellites_visible={msg.satellites_visible}")
    return msg

def main():

    master = mavutil.mavlink_connection('/dev/ttyAMA0', baud=115200)
    logging.info("Connected to MAVLink through /dev/ttyAMA0")
    
    # Wait for the autopilot to send a heartbeat signal
    master.wait_heartbeat()
    logging.info("Heartbeat received from autopilot")

    # GPS_RAW_INT parameters
    fix_type = 3
    lat = 377749000    # Latitude in degrees * 1E7
    lon = -1224194000  # Longitude in degrees * 1E7
    alt = 1657484      # Altitude in meters * 1000
    eph = 10           # Horizontal dilution of precision
    epv = 10           # Vertical dilution of precision
    vel = 0            # Speed
    cog = 0            # Course over ground
    
    while True:
        # Time in microseconds
        time_usec = int(time.time() * 1e6)
        
        # Generate a random number of satellites between 5 and 55
        satellites = random.randint(5, 55)
        logging.debug(f"Generated satellites count: {satellites}")

        # Send GPS_RAW_INT message
        send_gps_raw_int(master, time_usec, fix_type, lat, lon, alt, eph, epv, vel, cog, satellites)
        
        # Check received message
        receive_gps_raw_int(master)
        
        # Wait before sending the next message
        time.sleep(2.0)  # Increased interval for testing

if __name__ == "__main__":
    main()

ArduPilot or PX4? That’s not the same software. Check first what you’re using.

Hello, I use Ardupilot

Then you might want to ask in discuss.ardupilot.org instead.