CRITICAL:autopilot:Crash:Disarm Debugging issues


#1

Ok so I setup a flight from a grocerty store to my friends house with dronekit… Now interestingly whenever it gets past say 500 meters on a 1500 meter flight or so I get a CRITICAL autopilot Crash: disarming message.

So then I switched from my GUIDED code to AUTO mode and figured maybe it was a out of reach for commands in guided but got the same result at about the same spot…

I looked online and found some possible issues for that error due to Lean Angle more the 30 degrees or not accelerating by more then 3ms but since this is the simulator and on AUTO pilot I am thinking this would not happen… I am going to do some outputs on those values to monitor it as it flys tonight and possibly auto adjust on the fly if that is the issue…

But my actual question is… Me being new to how these function and the simulator behavior… Is there something Obvious I am missing that happens after say 500 meters of GUIDED or AUTO flight? Which would cause it to disarm and crash?


#2

Post your output and AUTO dk code to review. SIM distance doesn’t matter - you can fly around the world.

But battery capacity does matter. In mavproxy use param show BATT_CAPACITY to check, use param set BATT_CAPACITY xxxxx to increase. Use the following in dk code:

print “Battery: %s” % vehicle.battery


#3

Ahhh ok I am going to track my battery power and pitch and a few other items when I am coding later tonight and see if anything looks off, I will let you know if that fixes it…

Also side note, when using physical quads whats the battery power distance/length of flight time on average or ranges that are easily obtainable. I have a few adversarial hacking projects I am working on that might need decent automated flight time…


#4

I was incorrect re the battery. I just ran a sim mission at 0% BATT_CAPACITY and it did not matter. So w/o looking at your code I do not have an answer.

When using real drones the flight time and distance depends on the build (eg, frame size, motors, props), wind conditions, payload, amps used based on flying (eg, altitude, aggressiveness), etc.

Design factors include thrust/weight, amperage draw, battery capacity.
You did not specify what “decent” means, so hard to answer. The dojo drone kit build will typically get 15-20 min.

You can play around with design parameters at https://www.ecalc.ch/xcoptercalc.php and see what you can do in ideal conditions.


#5

OK cool yea I have one of the drone dojo kits I am going to be putting together in about 2 weeks, currently working through a few other projects first… 20 minutes should be sufficient for a lot of my POC testing. I can look at the other things later if I need to extend it. I just kind of wanted a rough estimate and some info on what changes that which you provided so that’s perfect.

Yea I will do some debugging tonight and play around if it keeps doing it I will upload the code, its not all that much different then the test code from the first course I was going through…


#6

Yea so the battery is at 83% when it crashes… Based on the FS_CRASH crash type checking params being at specific values more then 2 seconds I changed the MAX Angle to be 20 in QgroundControl since that FS_CRASH detection checks for a value over 30 for more then 2 seconds and now my quad did not crash…
HOWEVER the speed drops after about 500 of the 1500 meters from a speed of 5.00 to .006 and starts crawling slowly forward but never crashes do to the angle constraint… So it fixed the crash detection but not the underlying issue of whats happening at 500 meters.

Output I was monitoring below died at 1065 dropped to a speed of .006 and remained there:


AirSpeed: 5.008000373840332
HeartBeat 2227.253474317
Distance from dropoff point: 1071.0173701304914

AirSpeed: 5.005000114440918
HeartBeat 2229.28461993
Distance from dropoff point: 1065.909084532523

AirSpeed: 0.03500000014901161
HeartBeat 2231.266562261
Distance from dropoff point: 1065.773969685431

AirSpeed: 0.006000000052154064
HeartBeat 2233.276560427

Here is the code I am using:

 from dronekit import Vehicle, connect, VehicleMode, LocationGlobal, APIException, LocationGlobalRelative, Command
import time
import socket
import math
import argparse
from pymavlink import mavutil

def get_distance_meters(targetLocation, currentLocation):
    """ Takes a target location and current location and returns the distance"""
    dlat = targetLocation.lat - currentLocation.lat
    dlon = targetLocation.lon - currentLocation.lon

    return math.sqrt((dlon*dlon) + (dlat*dlat))*1.113195e5

def calculate_currentDistance(targetLocation):
    """Takes a target location object and returns your distance to that location """
    distanceToTargetLocation = get_distance_meters(targetLocation, vehicle.location.global_relative_frame)
    return distanceToTargetLocation


def connectMyCopter():
    """Connects to your quad and returns a vehicle connection object"""
    parser = argparse.ArgumentParser(description='commands')
    parser.add_argument('--connect')
    args = parser.parse_args()

    connection_string = args.connect

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

    vehicle = connect(connection_string, wait_ready=True)
    return vehicle

def arm_and_takeoff(targetHeight):
    """Arms the drone and gets it up in the air to the meters height of input targetheight"""
    while (vehicle.is_armable != True):
        print("Waiting for vehical to become armable")
        time.sleep(1)
    print("--------------------------------")
    print("Vehical Is armable")
    print("--------------------------------")
    vehicle.mode = VehicleMode("GUIDED")
    while(vehicle.mode != "GUIDED"):
        print(vehicle.mode)
        print("Waiting for the drone to enter GUIDED flight mode")
        time.sleep(1)

    vehicle.armed = True
    while(vehicle.armed == False):
        print("Waiting to arm vehical")
        time.sleep(2)
    print("--------------------------------")
    print("Props are spinning")
    print("--------------------------------")
    vehicle.simple_takeoff(targetHeight) #meters

    while True:
        print(f"Current Altitude: {vehicle.location.global_relative_frame.alt}")
        if (vehicle.location.global_relative_frame.alt) >=.95*targetHeight:
            break 
        time.sleep(1)
    print("--------------------------------")
    print("Target Altitude Reached")
    print("--------------------------------")
    return None

#############Start of Main#################
wp1 = LocationGlobalRelative(REMOVED,-REMOVED, 10)
vehicle = connectMyCopter()

wphome=vehicle.location.global_relative_frame
cmd1=Command(0,0,0,mavutil.mavlink.MAV_FRAME_GLOBAL_RELATIVE_ALT,mavutil.mavlink.MAV_CMD_NAV_WAYPOINT,0,0,0,0,0,0,wphome.lat, wphome.lon,wphome.alt)
cmd2=Command(0,0,0,mavutil.mavlink.MAV_FRAME_GLOBAL_RELATIVE_ALT,mavutil.mavlink.MAV_CMD_NAV_WAYPOINT,0,0,0,0,0,0,REMOVED,-REMOVED, 10)
cmd3=Command(0,0,0,mavutil.mavlink.MAV_FRAME_GLOBAL_RELATIVE_ALT,mavutil.mavlink.MAV_CMD_NAV_RETURN_TO_LAUNCH,0,0,0,0,0,0,0,0,0)



################# Setting Up AUTO COMMANDS####################
#Download list of commands from current drone
cmds = vehicle.commands  
cmds.download()
cmds.wait_ready()

#Clear List of commands from drone: 
cmds.clear()

#Add in our new commands
cmds.add(cmd1)
cmds.add(cmd2)
cmds.add(cmd3)


#upload our commands to the drone
vehicle.commands.upload()
##################END SETUP COMMANDS##########################
#Arm Your Copter#
arm_and_takeoff(10)

print("Setting to Auto Mode...")
vehicle.mode = VehicleMode("AUTO")
while(vehicle.mode != "AUTO"):
    time.sleep(.2)
print("--------------------------------")
print("Vehical entered AutoFlight Mode")
print("--------------------------------")
print("---------------------------------------------------")
print("Drone is executing Auto fly to dropoff point")
print("---------------------------------------------------")

########## Mission Execution Loop###########
while (vehicle.location.global_relative_frame.alt > 2):
    current_distance = calculate_currentDistance(wp1)
    print(f"Distance from dropoff point: {current_distance}")
    print("---------------------------------------")
    print(f"AirSpeed: {vehicle.airspeed}")
    print(f"HeartBeat {vehicle._heartbeat_lastreceived}")

    time.sleep(2)
print("---------------------------------------")
print("---------------------------------------")
print ("Mission Completed")
print("---------------------------------------")
print("---------------------------------------")

#7

The code seems good. It almost seems like it is behaving as if it has reached the wp.
But I don’t see your goto() function to check.

Caleb or a more knowledgeable member hopefully can help.

I noticed this link that might be relevant: https://ardupilot.org/copter/docs/crash_check.html

I was going to ask about the failsafe settings. I am unfamiliar with MAX angle. If you decrease the angle it seems it would trigger more?

What if you just set FS_CRASH to zero?


#8

Yea that’s the exact crash referencing regarding my max angle change. I started googling my errors and found that page and made that adjustment. Since its based on that list of possible 2 second long issues the angle made the most sense to change… So I adjusted the Max angle to 20 degrees so there is no way to trigger a 2 second 30 degree angle and checked to see if it still crashed but it didnt… So that fixed the crash making me think it has something to do with the issue but it didn’t fix the problem.

And if I let it keep running the simulation it does keep decrementing the distance just really really slowly at that .006 speed…

This would be my goto command right? Those 2 removed Coordinates which are about 1 mile from the starting coordinates of the arducopter UI:
cmd2=Command(0,0,0,mavutil.mavlink.MAV_FRAME_GLOBAL_RELATIVE_ALT,mavutil.mavlink.MAV_CMD_NAV_WAYPOINT,0,0,0,0,0,0,REMOVED,-REMOVED, 10)


#9

Sorry, yes that is the command, though I am not familiar with using REMOVED, -REMOVED. I’m also looking at the QGC Vehicle Setup FS and Safety Setup Parameters but do not see FS_CRASH. How was this set?
What happens if you disregard the max angle and FS_CRASH altogether? I wasn’t aware of those settings and hence haven’t used them and the auto mission works fine. Not sure what the defaults are for them though.


#10

Ummm I was opening them up right within the QGC for the MAX Angle and turning them off becuase I tried within the actual Param file but it didnt do anything… I believe I did try to shutoff the FS Crash completely flipping it from 1 to 0 via the config parameter file… Though I am not sure it did anything… I didnt look for it within QGC but its probably in the same place as Max Angle.

Wierd that yours works just find but mine does not…


#11

I wanted to update this posting for future reference that it is never a good idea to disable FS_CRASH as it provides an important safety feature and helps to prevent vehicle damage after a crash.


#12

Good to know, I still never resolved that issue… I am pretty sure its just an issue with the simulator… but I just setup my quadcopter now to do real coding on… so we will see if I face the same issues…