每当我尝试在空中改变模式时,drone-kit python 脚本会继续让直升机处于引导模式。我非常希望我的 python 脚本允许我的无人机飞过某个位置并将其模式切换到空中 LOITER 并在空中停留一段时间。这是我脚本的一小部分:
print "Going towards location"
goto(5,3)
vehicle.mode = VehicleMode("LOITER")
print vehicle.mode
time.sleep(70)
每次我运行脚本时,它都会将车辆模式输出为 GUIDED 而不是 LOITER。我不明白为什么不。
这是goto python函数的定义
def goto(dNorth, dEast, gotoFunction=vehicle.simple_goto):
currentLocation=vehicle.location.global_relative_frame
targetLocation=get_location_metres(currentLocation, dNorth, dEast)
targetDistance=get_distance_metres(currentLocation, targetLocation)
gotoFunction(targetLocation)
while (vehicle.mode.name=="GUIDED") and (get_distance_metres(vehicle.home_location,vehicle.location.global_frame)<radius) and (vehicle.location.global_relative_frame.alt<alt_limit):
#Stop action if we are no longer in guided mode or outside radius.
remainingDistance=get_distance_metres(vehicle.location.global_frame, targetLocation)
print "Distance to target: ", remainingDistance
if remainingDistance<=targetDistance*0.1: #Just below target, in case of undershoot.
print "Reached target"
break
time.sleep(2)
我了解如果直升机未处于 GUIDED 模式,则 simple_goto 无法运行。但是在它到达目的地之后,该函数告诉它中断,我假设它不再在 simple_goto 中运行。如果有人可以帮助我解释为什么会发生这种情况,因为我不明白我的代码有什么问题。
(整个代码可以根据要求发布)