SITL Mavlink

23 views
Skip to first unread message

Владислав Пургин КВ-92

unread,
Apr 16, 2024, 11:01:59 AMApr 16
to MAVLink
Hello, everyone, I'm a beginner developer who started working on a project about drones. It has px4, gazebo, QGC(qgroundcontrol) and pymavlink. I'm running gazebo + QGC and through the code from pymavlink I need to build a path for the drone to fly. When I start it, I get an error, at the moment of building waypoints, the terminal freezes, and in QGC it says - Vehicle Error Operation timeout, aborting transfer.

The code used:
import math
from pymavlink import mavutil

class mission_item:
    def __init__(self, i, current,x,y,z):
        self.seq = 1
        self.frame = mavutil.mavlink.MAV_FRAME_GLOBAL_RELATIVE_ALT
        self.command = mavutil.mavlink.MAV_CMD_NAV_WAYPOINT
        self.current = current
        self.auto = 1
        self.param1 = 0.0
        self.param2 = 2.00
        self.param3 = 20.00
        self.param4 = math.nan
        self.param5 = x
        self.param6 = y
        self.param7 = z
        self.mission_type = 0

def arm (the_connection):
    print("-- Arming")

    the_connection.mav.command_long_send(the_connection.target_system, the_connection.target_component,mavutil.mavlink.MAV_CMD_COMPONENT_ARM_DISARM, 0, 1, 0, 0, 0, 0, 0, 0)


    ack(the_connection, "COMMAND_ACK")

def takeoff(the_connection):
    print("-- Takeoff Initaited")

    the_connection.mav.command_long_send(the_connection.target_system, the_connection.target_component, mavutil.mavlink.MAV_CMD_NAV_TAKEOFF, 0, 0, 0, 0, math.nan, 0, 0, 10)

    ack(the_connection, "COMMAND_ACK")

def upload_mission(the_connection, mission_items):
    n = len(mission_items)
    print("-- Sending Message out")

    the_connection.mav.mission_count_send(the_connection.target_system,the_connection.target_component, n, 0)

    ack(the_connection, "MISSION_REQUEST")

    for waypoint in mission_items:
        print("-- Creating a waypoint")

        the_connection.mav.mission_item_send(the_connection.target_system,
          the_connection.target_component,
          waypoint.seq,
          waypoint.frame,
          waypoint.command,
          waypoint.current,
          waypoint.auto,
          waypoint.param1,
          waypoint.param2,
          waypoint.param3,
          waypoint.param4,
          waypoint.param5,
          waypoint.param6,
          waypoint.param7,
          waypoint.mission_type)

    if waypoint != mission_items[n-1]:
    ack(the_connection, "MISSION_REQUEST")

    ack(the_connection, "MISSION_ACK")

def set_return(the_connection):
    print("-- Set Return To launch")
    the_connection.mav.command_long_send(the_connection.target_system,the_connection.target_component,mavutil.mavlink.MAV_CMD_NAV_RETURN_TO_LAUNCH, 0, 0, 0, 0, 0, 0, 0, 0)
   
    ack(the_connection, "COMMAND_ACK")
   
def start_mission(the_connection):
    print("-- MISSION START")
    the_connection.mav.command_long_send(the_connection.target_system,the_connection.target_component,mavutil.mavlink.MAV_CMD_MISSION_START, 0, 0, 0, 0, 0, 0, 0, 0)
   
    ack(the_connection, "COMMAND_ACK")
   
def ack(the_connection, keyword):
    connect = the_connection.recv_match(type=keyword, blocking=True)
    text_qwerty= str(connect)
    print("-- Message Read " + text_qwerty)
   
if __name__ == "__main__":
    print("-- Program Started")
    the_connection = mavutil.mavlink_connection("udpin:localhost:14540")
   
    while(the_connection.target_system == 0):
        print("-- Checking Heartbeat")
        the_connection.wait_heartbeat()
        print("-- heartbeat from system (system %u component %u)" % (the_connection.target_system, the_connection.target_component))
    mission_waypoints = []
   
    mission_waypoints.append(mission_item(0,0, 47.397741, 8.545559, 10))
    mission_waypoints.append(mission_item(1,0, 47.396567, 8.544720, 10))
    mission_waypoints.append(mission_item(2,0, 47.396567, 8.544720, 5))
   
    upload_mission(the_connection, mission_waypoints)
   
    arm(the_connection)
   
    takeoff(the_connection)
   
    start_mission(the_connection)
   
    for mission_item in mission_waypoints:
        print("-- Message Read " + str(the_connection.recv_match(type="MISSION_ITEM_REACHED", condition="MISSION_ITEM_REACHED.seq == {0}".format(mission_item.seq), blocking=True)))
   
    set_return(the_connection)

I work on Ubuntu 22.04, gazebo 11.10.2 123.jpg1234.jpg

Hamish Willee

unread,
Apr 23, 2024, 11:37:58 PMApr 23
to MAVLink
What I'm seeing in QGC is that some operation is timing out, and it is aborting transfer. Since you're talking with Python to PX4, not QGC, I guess it is some unrelated operation. Possibly download of parameters on initial connection? What happens if you wait until the vehicle is ready to fly before trying your code?

If I had to guess, you're using the same mavlink port as the GCS. WHat port are you using?
Reply all
Reply to author
Forward
0 new messages