dronekit / dronekit-python

DroneKit-Python library for communicating with Drones via MAVLink.
https://readthedocs.org/projects/dronekit-python/
Apache License 2.0
1.5k stars 1.42k forks source link

can not set to land #1222

Closed epkeefe123 closed 1 week ago

epkeefe123 commented 1 week ago

idk im just trying to set simulated vehicle to land here is the script if anyone wants to help: ` from dronekit import connect, VehicleMode, LocationGlobalRelative, LocationGlobal, Command import time import argparse import dronekit_sitl from pymavlink import mavutil

############################FUNCTION####################### def connectMyCopter(): parser = argparse.ArgumentParser(description='commands') parser.add_argument('--connect') args = parser.parse_args()

connection_string = args.connect

if not connection_string:
    sitl = dronekit_sitl.start_default()
    connection_string = sitl.connection_string()

vehicle = connect(connection_string, wait_ready=True)

print(vehicle.mode)
return vehicle

def arm_and_takeoff(aTargetAltitude): """ Arms vehicle and flies to aTargetAltitude. """ print("Basic pre-arm checks")

Don't try to arm until autopilot is ready

while not vehicle.is_armable:
    time.sleep(1)

print("Arming motors")
# Copter should arm in GUIDED mode
vehicle.mode = 4
time.sleep(5)
vehicle.armed = True

# Confirm vehicle armed before attempting to take off
while not vehicle.armed:
    time.sleep(1)

print("Taking off!")
vehicle.simple_takeoff(aTargetAltitude)  # Take off to target altitude

# Wait until the vehicle reaches a safe height before processing the goto (otherwise the command
# after Vehicle.simple_takeoff will execute immediately).
while True:
    print(" Altitude: ", vehicle.location.global_relative_frame.alt)
    # Break and return from function just below target altitude.
    if vehicle.location.global_relative_frame.alt >= aTargetAltitude * 0.95:
        print("Reached target altitude")
        break
    time.sleep(1)

MAIN

vehicle = connectMyCopter() cmds = vehicle.commands cmds.download() cmds.wait_ready() arm_and_takeoff(4) vehicle.airspeed = 3 time.sleep(10) print("Going towards first point for 30 seconds ...") point1 = LocationGlobalRelative(-35.3626835,149.1651455 , 20) vehicle.simple_goto(point1)

sleep so we can see the change in map

time.sleep(40)

print("Rlanding") vehicle.simple_goto (vehicle.home_location, -5) vehicle.simple_goto ("LAND")

Close vehicle object before exiting script

print("Close vehicle object") vehicle.close()

`

hamishwillee commented 1 week ago

@epkeefe123 The best place to ask DroneKit questions is in the discussion board for your flight stack - presumably Ardupilot. That may see unintuitive, but this project has only limited maintenance, and there are more people looking at those forums that here.