Problems with Dronekit and MAVproxy

Hello,

I am trying to run dronekit code on dronekit-sitl but am running into quite a few problems.

I am running dronekit-sitl on Python 3 in Windows 10 (I know python 3 is not officially supported) and running MAVproxy to connect to SITL and open a few ports for Mission Planner and for running a python script. Unfortunately I am unable to change the flight mode, either through the terminal running mavproxy using “mode LAND” and through dronekit. It gives a message on the MAVproxy Console program Got COMMAND_ACK: DO_SET_MODE: UNSUPPORTED.

It has been a while since I have worked on dronekit and mavproxy and to me it has changed a lot. I have worked on dronekit and mavproxy on python3 before and had made a tutorial video of setting everything up Ardupilot Software-in-the-loop (SITL) Tutorial - Python 3. I tried to retrace my steps but MAVproxy is giving me quite a few problems.

Also when every I try to run mavproxy.py it just opens the python file in the editor and I have to go in the python scripts folder to run it, which didn’t use to happen.

Any help would be appreciated.

Cheers

Hello

I got it to work but only after I went and specifically installed the old versions using pip and python 3.7.4.

I would love to find out what the problem was and how to make it work with the updated versions of dronekit, mavproxy and pymavlink

Thanks

1 Like

I know that I can address this issue with the following PR
This issue is a matter by PYMAVLINK.
The new PYMAVLINK is not available with the old firmware.
You can either downgrade PYMAVLINK as you have done, or change it as in my PR.

1 Like

Hello

Thank you. I updated my mavutil.py file according your PR and it worked great.

They should really add it to the main code. Would make my life much easier.

I hope to get suggestions towards my problem where I can get mavproxy working but not dronekit.

python arm_quad_5.py --connect /dev/ttyAMA0 --baud 921600 2>&1 |tee arm_test19.txt

################# arm_quad_5.py ################
import dronekit
from dronekit import connect, VehicleMode, LocationGlobalRelative, APIException
import time
import socket
import exceptions
import math
import argparse

global vehicle

def connectMyCopter():
parser = argparse.ArgumentParser(description=‘commands’)
parser.add_argument(’–connect’)
parser.add_argument(’–baud’)
args = parser.parse_args()
vehicle = connect(args.connect, baud=args.baud, wait_ready=True)
return vehicle

vehicle = connectMyCopter()
print(“close”)
vehicle.close()

################### Mavproxy testing ##################
Name: MAVProxy Version: 1.8.46
Name: dronekit Version: 2.9.2
Name: pyserial Version: 3.4
Python 2.7.16

mavproxy.py --master=/dev/ttyAMA0 --baudrate 921600 --aircraft MyCopter 2>&1 |tee cubeblack_mavproxy_3.txt

Connect /dev/ttyAMA0 source_system=255
no script MyCopter/mavinit.scr
Log Directory: MyCopter/logs/2021-12-03/flight2
Telemetry log: MyCopter/logs/2021-12-03/flight2/flight.tlog
Waiting for heartbeat from /dev/ttyAMA0
MAV> Detected vehicle 1:1 on link 0
online system 1
ALT_HOLD> Mode ALT_HOLD
fence present
fence enabled
AP: ArduCopter V4.1.0 (ea559a56)
AP: ChibiOS: 08877972
AP: CubeBlack 002F0039 30385111 30343937
AP: RCOut: PWM:1-12
AP: IMU0: fast sampling enabled 8.0kHz/1.0kHz
AP: IMU2: fast sampling enabled 8.0kHz/1.0kHz
AP: Frame: HEXA/X
AP: PreArm: Hardware safety switch
AP: PreArm: Hardware safety switch
AP: PreArm: Hardware safety switch
ALT_HOLD> AP: PreArm: Hardware safety switch
AP: PreArm: Hardware safety switch
ALT_HOLD> ALT_HOLD> ALT_HOLD> ALT_HOLD> Got COMMAND_ACK: COMPONENT_ARM_DISARM: FAILED
AP: PreArm: Throttle (RC3) is not neutral
ALT_HOLD> Got COMMAND_ACK: COMPONENT_ARM_DISARM: ACCEPTED
ARMED
Arming checks disabled
DISARMED

I think dronekit is a bit obsolete. As i understand it, it is not updated anymore. Some time ago there has been a bit of a discussion to bring it back to life but i guess it didn’t happen.
You better not use it and go direct to pymavlink i think.

I am using dronekit without an issue and works fine with latest firmware on my every use case.
What is the problem?

It took very long approximate 20 to 30 minutes for dronekit.connect to return or other issue where I only see the first print out after 20 to 30 mins.

@Jai.GAY Never seen this issue, even without FTP to download parameters with wait_ready=True, it took less than 30 seconds to connect to the vehicle.
I suggest you build SITL from source code.
You can follow here and then here.

Do you think is the Raspbian OS version I used that cause the problem? I am using Raspberry Pi OS Buster (10) latest but not lite version.

Probably it is. You can follow exact steps you did before on your computer to narrow down the issue.
Dronekit should work properly on rpi because i did it before, but never started sitl in rpi.
You can run SITL on computer (i suggest you to build from source) and run your script (dronekit) on rpi.

Because it is still mentioning here I thought it is under maintaining.

@Mustafa_Gokce, Interesting, mavproxy running on the same Pi the result is instant.

How much does this code take?

import time
import dronekit
start = time.time()
vehicle = dronekit.connect("udp:127.0.0.1:14550", wait_ready=True)
vehicle.close()
end = time.time()
print(end - start)

Replace the connection string with your own.

CRITICAL:autopilot:PreArm: Hardware safety switch
/dev/ttyAMA0
921600
22.6871209145

could be due to this statement, not very sure, now consistent 22.xx secs
from future import print_function

Now new problem is forever loop in while statement
EKF OK?: False
Is Armable?: False
Armed: False

# Check that vehicle is armable
while not vehicle.is_armable:
    print(" Waiting for vehicle to initialise...")
    time.sleep(1)
print("Vehicle is ready for arm")

So you are connecting to a device, it waits you to push hardware safety switch.
Also, I don’t know your arm conditions, without GPS fix, you may wait forever.

This is more like it.

Probably this is due to GPS fix.

You can take a look at examples in here. They are really easy to follow.

Thanks for the examples, I removed pre-arm check for GPS related, still
Is Armable?: False

if I comment off and ignore the while loop check, I can arm.

connectMyCopter
/dev/ttyAMA0
921600

Connecting to vehicle on: /dev/ttyAMA0

Get all vehicle attribute values:
Autopilot Firmware version: APM:UnknownVehicleType13-4.1.0
Major version number: 4
Minor version number: 1
Patch version number: 0
Release type: rc
Release version: 0
Stable release?: True
Autopilot capabilities
Supports MISSION_FLOAT message type: True
Supports PARAM_FLOAT message type: True
Supports MISSION_INT message type: True
Supports COMMAND_INT message type: True
Supports PARAM_UNION message type: False
Supports ftp for file transfers: True
Supports commanding attitude offboard: True
Supports commanding position and velocity targets in local NED frame: True
Supports set position + velocity targets in global scaled integers: True
Supports terrain protocol / data handling: True
Supports direct actuator control: False
Supports the flight termination command: True
Supports mission_float message type: True
Supports onboard compass calibration: True
Global Location: LocationGlobal:lat=0.0,lon=0.0,alt=None
Global Location (relative altitude): LocationGlobalRelative:lat=0.0,lon=0.0,alt=-0.536
Local Location: LocationLocal:north=None,east=None,down=None
Attitude: Attitude:pitch=0.0202799346298,yaw=-2.34485840797,roll=0.0222185738385
Velocity: [0.0, 0.0, 0.0]
GPS: GPSInfo:fix=1,num_sat=0
Gimbal status: Gimbal: pitch=None, roll=None, yaw=None
Battery: Battery:voltage=16.126,current=1.18,level=98
EKF OK?: False
Last Heartbeat: 0.792305155
Rangefinder: Rangefinder: distance=None, voltage=None
Rangefinder distance: None
Rangefinder voltage: None
Heading: 225
Is Armable?: False
System status: STANDBY
Groundspeed: 0.00942026544362
Airspeed: 0.0
Mode: ALT_HOLD
Armed: False
ARM
Vehicle is ready for arm

Wait for drone to transit to arm
vehicle is now armed.
Propellers are spinning
Wait for drone to transit to disarm
Wait for drone to transit to disarm
Wait for drone to transit to disarm
close
End of python test script

Time take: 28.59

The vehicle is not armable in GUIDED mode since this mode requires GPS fix. After that vehicle mode changed to STABILIZE and this mode doesn’t require GPS and the vehicle is armable in this mode.

Thanks, changing to STABILIZE mode also hang inside while loop.

if not vehicle.is_armable:
    if not vehicle.mode.name == 'STABILIZE':
        vehicle.mode = VehicleMode("STABILIZE")
        while not vehicle.mode.name == 'STABILIZE':  #Wait until mode has changed
            print(" Waiting for mode change ...")
            time.sleep(1)

# Check that vehicle is armable, hangs
while not vehicle.is_armable:
    print(" Waiting for vehicle to initialise...")
    time.sleep(1)
print("Vehicle is ready for arm")

Instead you can do:

while not vehicle.mode.name == "STABILIZE":
    vehicle.mode = VehicleMode("STABILIZE")
    time.sleep(1)

It should not be hung without doing this though, take a look at status messages on the terminal or mavproxy console for debugging.