dronekit / dronekit-python

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

Dronekit-Sitl " Error Disarming Motors " #1058

Open drnayeem opened 4 years ago

drnayeem commented 4 years ago

Hello

I am trying to connect to SITL. The connect string works fine. But when i try to send vehicle.armed = True command to arm the quad

Error: autopilot : ARMING MOTORS CRITICAL: autopilot : GROUND START CRITICAL: autopilot : Initializing APM... ERROR: autopilot : DISARMING MOTORS

this is what i get am Running python 2.7 on a Windows10 PC

Charbel10 commented 4 years ago

Hello,

I'm trying to run the drone code "Simple_go_to" on python, but Im getting the following error and the alitude stays 0:

Starting copter simulator (SITL) SITL already Downloaded and Extracted. Ready to boot. Connecting to vehicle on: tcp:127.0.0.1:5760 CRITICAL:autopilot:APM:Copter V3.3 (d6053245) CRITICAL:autopilot:Frame: QUAD Basic pre-arm checks Arming motors Waiting for arming... ERROR:autopilot:ARMING MOTORS CRITICAL:autopilot:Initialising APM... Taking off! Altitude: 0.0 Altitude: 0.0 Altitude: 0.0 Altitude: 0.01 Altitude: 0.01 Altitude: 0.01 Altitude: 0.01 Altitude: 0.01 Altitude: 0.01 ERROR:autopilot:DISARMING MOTORS

Any help please?

Thnak you

leonardocfor commented 4 years ago

Hi, can you guys provide your source code ?

Charbel10 commented 4 years ago

Hello,

Below is the code:

from future import print_function import time from dronekit import connect, VehicleMode, LocationGlobalRelative

Set up option parsing to get connection string

import argparse parser = argparse.ArgumentParser(description='Commands vehicle using vehicle.simple_goto.') parser.add_argument('--connect', help="Vehicle connection target string. If not specified, SITL automatically started and used.") args = parser.parse_args()

connection_string = args.connect sitl = None

Start SITL if no connection string specified

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

Connect to the Vehicle

print('Connecting to vehicle on: %s' % connection_string) vehicle = connect(connection_string, wait_ready=True)

def arm_and_takeoff(aTargetAltitude): """ Arms vehicle and fly to aTargetAltitude. """

print("Basic pre-arm checks")
# Don't try to arm until autopilot is ready
while not vehicle.is_armable:
    print(" Waiting for vehicle to initialise...")
    time.sleep(1)

print("Arming motors")
# Copter should arm in GUIDED mode
vehicle.mode = VehicleMode("GUIDED")
vehicle.armed = True

# Confirm vehicle armed before attempting to take off
while not vehicle.armed:
    print(" Waiting for arming...")
    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)

arm_and_takeoff(10)

print("Set default/target airspeed to 3") vehicle.airspeed = 3

print("Going towards first point for 30 seconds ...") point1 = LocationGlobalRelative(-35.361354, 149.165218, 20) vehicle.simple_goto(point1)

sleep so we can see the change in map

time.sleep(30)

print("Going towards second point for 30 seconds (groundspeed set to 10 m/s) ...") point2 = LocationGlobalRelative(-35.363244, 149.168801, 20) vehicle.simple_goto(point2, groundspeed=10)

sleep so we can see the change in map

time.sleep(30)

print("Returning to Launch") vehicle.mode = VehicleMode("RTL")

Close vehicle object before exiting script

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

Shut down simulator if it was started.

if sitl: sitl.stop()

Sent from Mailhttps://go.microsoft.com/fwlink/?LinkId=550986 for Windows 10

From: Leonardo Camargo Foreromailto:notifications@github.com Sent: Wednesday, September 9, 2020 12:24 AM To: dronekit/dronekit-pythonmailto:dronekit-python@noreply.github.com Cc: Charbel10mailto:charbel_aoun1978@hotmail.com; Commentmailto:comment@noreply.github.com Subject: Re: [dronekit/dronekit-python] Dronekit-Sitl " Error Disarming Motors " (#1058)

Hi, can you guys provide your source code ?

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/dronekit/dronekit-python/issues/1058#issuecomment-689167899, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AQ5KDELQIRVUCGJMVHI6KHTSE2VJTANCNFSM4Q6J7HRA.

leonardocfor commented 4 years ago

Ok I assume you are using the simple_goto.py script in the examples folder. I personally don't like much dronekit-sitl, but I find dronekit to work quite good with ArduPilot SITL, which you can install it by following this link:

https://ardupilot.org/dev/docs/building-setup-linux.html#building-setup-linux (Assuming you are using Linux).

Then run your code with the --connect flag using :PORT, where port can be 14550 e.g.:

python simple_goto.py --connect localhost:14550

Charbel10 commented 4 years ago

Thk you for your quick reply. Iam using windows and not linux. I'm sorry Im a beginner in python. In addition, Im using the mission planner as simulator. I really need to run properly this example.

Thank you for your support,


From: Leonardo Camargo Forero notifications@github.com Sent: Wednesday, September 9, 2020 1:38 AM To: dronekit/dronekit-python dronekit-python@noreply.github.com Cc: Charbel10 charbel_aoun1978@hotmail.com; Comment comment@noreply.github.com Subject: Re: [dronekit/dronekit-python] Dronekit-Sitl " Error Disarming Motors " (#1058)

Ok I assume you are using the simple_goto.py script in the examples folder. I personally don't like much dronekit-sitl, but I find dronekit to work quite good with ArduPilot SITL, which you can install it by following this link:

https://ardupilot.org/dev/docs/building-setup-linux.html#building-setup-linux (Assuming you are using Linux).

Then run your code with the --connect flag using :PORT, where port can be 14550 e.g.:

python simple_goto.py --connect localhost:14550

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/dronekit/dronekit-python/issues/1058#issuecomment-689172462, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AQ5KDEKPM26DWZJGJIXGPULSE2W4XANCNFSM4Q6J7HRA.

[https://ipmcdn.avast.com/images/icons/icon-envelope-tick-round-orange-animated-no-repeat-v1.gif]https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=icon Virus-free. www.avast.comhttps://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=link

leonardocfor commented 4 years ago

You can try install ArduPilot SITL in Windows by following this link: https://ardupilot.org/dev/docs/sitl-native-on-windows.html

Or you can use virtual box or docker to run an Ubuntu in your Windows and then install ArduPilot SITL on it and run the DroneKit examples. I would recommend you to test this software on Linux nevertheless as in reality it would be unusual to have a drone running Windows hehe.

drnayeem commented 4 years ago

Hello Thanks A lot leonardocfor I tried Installing Ardupilot Sitl following the steps

  1. Install Cigwin
  2. Install MAVProxy and then we are supposed to call sim_vehicle.py from Cigwin But i did not get any directory called ' Vehicles' and containing the Vehicle_sim.py file

Am i doing something wrong ?

Regards Doc

CordobaPablo commented 4 years ago

Did you find the solution?

TulipDi commented 3 years ago

I get the same issue, have you solved it?

drnayeem commented 3 years ago

No it's still stuck at that Awaiting some way out

asosa16 commented 3 years ago

Set your vehicle mode to STABILIZE (or any other armable mode). Run your python script. Immediately change your vehicle mode manually to GUIDED. Your vehicle should perform your script commands if correct.

This solution is far from ideal, but I've found it to work. Good luck

GRS26 commented 3 years ago

@leonardocfor could you explain a little better how to setup this ardupilot sitl?

m-s-spoorthi commented 2 years ago

after the "vehicle.simple_takeoff(aTargetAltitude) # Take off to target altitude" give enough time, at least 30s to take off ex: time.sleep(30) after the command

prithvi2k2 commented 1 year ago

A potential fix could be downgrading pymavlink to 2.4.8 Try pip uninstall pymavlink then pip install pymavlink==2.4.8

Usage of pip command depends on your environment setup defaults, I assume you're on python 2.7 as you mentioned.

Another observation - If you're using python 3, the above workaround might not work with python 3.7+, will work with upto python 3.6

All credit to @Git-Ilan and @Nilasstohr for pointing this out at #1083

EDIT: I was using Windows Platform, didn't ever test it on linux

vijayakashallenki commented 1 year ago

Thank you man its working now!!!

kyrlon commented 1 year ago

Downgrading to python3.6 is not ideal. Is there a dronekit-sitl docker container available by chance? EDIT: https://github.com/Akademicki-Klub-Lotniczy/ardupilot-sitl-docker Found a decent repo for a container. The Dockerfile itself is outdated if attempted to build from scratch, but pulling the image wnt3rmute/ardupilot-sitl works fine

I am running python3.8 on my windows10 and was able to connect (from host) to the SITL (inside container) by running the following.

docker run -it -e DISPLAY=host.docker.internal:0 wnt3rmute/ardupilot-sitl ./sim_vehicle.py --out udp:host.docker.internal:14550 -L Ballarat --console --map -v ArduCopter -N