我如何使用drone Kit python创建一个方法来计算我是否有时间将电池留在无人机中?

2024-05-16 10:42:22 发布

您现在位置:Python中文网/ 问答频道 /正文

这三种方法可能会改变,以实现我需要的方法

我正在尝试的是创建一种方法,不断计算返回家园和着陆所需的时间,以及它当前剩余的电池是否足够

,,,,,,,, def获取位置(原始位置,德诺思,迪斯特):

earth_radius=6378137.0 #Radius of "spherical" earth
#Coordinate offsets in radians
dLat = dNorth/earth_radius
dLon = dEast/(earth_radius*math.cos(math.pi*original_location.lat/180))

#New position in decimal degrees
newlat = original_location.lat + (dLat * 180/math.pi)
newlon = original_location.lon + (dLon * 180/math.pi)
return LocationGlobal(newlat, newlon,original_location.alt)

def获取距离(位置1、位置2):

dlat = aLocation2.lat - aLocation1.lat
dlong = aLocation2.lon - aLocation1.lon
return math.sqrt((dlat*dlat) + (dlong*dlong)) * 1.113195e5

,,,,,,,,,,, 定义到当前航路点的距离()

nextwaypoint = vehicle.commands.next
if nextwaypoint==0:
    return None
missionitem=vehicle.commands[nextwaypoint-1] #commands are zero indexed
lat = missionitem.x
lon = missionitem.y
alt = missionitem.z
WaypointLocation = LocationGlobalRelative(lat,lon,alt)
distancetopoint = get_distance_metres(vehicle.location.global_relative_frame, WaypointLocation)
return distancetopoint

def return_home():

logging.info('Returning to Launch Site')
if(vehicle.mode.name != "RTL"):
    vehicle.mode = VehicleMode("RTL")
while not vehicle.mode.name == "RTL":
    time.sleep(1)
if(vehicle.home_location != None):
    while get_distance_metres(vehicle.location.global_relative_frame,vehicle.home_location)>3:
        time.sleep(1)
        if(vehicle.mode.name != "RTL" or vehicle.mode.name != "LAND"):
            vehicle.mode = VehicleMode("RTL")
            while not vehicle.mode.name == "RTL" and 

,,,,,,,, 获取距离米(车辆.位置.全局相对框架,车辆.主位置)>;1: 时间。睡眠(1)

    logging.info('Reached home. Landing.')
else:
    logging.warning("Changed to RTL but home cannot be accesed.")
vehicle.close()
sys.exit()


Tags: 方法namehomereturnifmodelocationmath