有些人知道通过任务规划师以编程方式驾驶无人机可以帮助我解决下方问题吗?
我是无人机的初学者。我正在尝试使用Python通过Mission Planner对起飞,悬停和降落等四轴飞行器进行非常基本的导航。
我在基础知识方面遇到了一些困难。我一直在浏览示例代码并编写一些脚本。
我写了一个基本的脚本,只是起飞,悬停和降落。我遇到了一些问题, - 起飞方向相反 - 起飞不是垂直的 - 应控制海拔高度。它不应超过一米。 - 速度很快。我该如何减少它?
另外, 在布防电机时,我在示例代码中看到我们将YAW设置为最大值(2000)并将其恢复到空档(1500)。为什么? 以下是我对RC的理解, RC1 - ROLL RC2- PITCH RC3 - THROTTLE RC4 - YAW RC5 - 用于更改模式。
有人可以帮我解决这些问题吗?我在下面附上了我的示例代码。
谢谢!
import time
takeoff_throttle = 1700
def setup_rc():
print("Set up all RCs to neutral")
for chan in range(1,9):
Script.SendRC(chan, 1500, False)
SendRC(3, Script.GetParam('RC3_MIN'), True)
Script.Sleep(5000)
print("Done")
return True
def arm_motors():
"Arming motors"
print('APM: ARMING MOTORS')
print("Setting mode to Stabilize")
Script.ChangeMode("STABILIZE") # STABILIZE MODE
Script.SendRC(5, 1750, True)
print("Done")
print('Setting Throttle to minimum')
Script.SendRC(3,1000,True)
print("Done")
print('Set Yaw')
Script.SendRC(4,2000,True)
print("Done")
print('Waiting for Arming Motors')
cs.messages.Clear()
Script.WaitFor('ARMING MOTORS',20000) #30000(30sec)
print("Done")
print('Reset Yaw')
Script.SendRC(4,1500,True)
print("Done")
return True
def wait_altitude(alt_min, alt_max, timeout=30):
climb_rate = 0
previous_alt = 0
'''wait for a given altitude range'''
tstart = time.time()
print("Waiting for altitude between %u and %u" % (alt_min, alt_max))
while time.time() < tstart + timeout:
#m = mav.recv_match(type='VFR_HUD', blocking=True)
climb_rate = cs.alt - previous_alt
previous_alt = cs.alt
#print("Wait Altitude: Cur:%u, min_alt:%u, climb_rate: %u" % (cs.alt, alt_min , climb_rate))
if cs.alt >= alt_min and cs.alt <= alt_max:
print("Attained altitude:%u"%(cs.alt))
print("Altitude OK")
return True
print("Failed to attain altitude range")
return False
def takeoff(alt_min=0.5):
print("Entered takeoff")
print("About to takeoff")
failed_status = False
print("Make sure we are in stabilise mode")
Script.ChangeMode("STABILIZE")
Script.SendRC(5, 1750, True)
print("Done")
print("Increase the throttle")
Script.SendRC(3, takeoff_throttle, True)
print("Processing altitude control")
found_alt = False
if (cs.alt < alt_min):
found_alt = wait_altitude(alt_min, alt_min + 0.5)
#Now we have our altitude we want to hold it
if found_alt:
Script.ChangeMode("AltHold")
Script.SendRC(5, 1000, True)
print("Set the throttle between 40-60% to hold altitude")
Script.SendRC(3, 1450, True)
print("Takeoff complete")
else:
print("Takeoff failed to reach adequate height")
print("Initiate error control procedure")
failed_status = True
return failed_status
def hover(hover_throttle = 1500):
print("Entering Hover mode")
print("Setting hover throttle")
Script.SendRC(3, hover_throttle, True)
print("Done")
print("Hovering for 3 seconds")
Script.Sleep(3000)
print("Hover Complete")
def land():
'''land the quad'''
print("STARTING LANDING")
print("Changing Mode to LAND")
Script.ChangeMode("LAND") # land mode
Script.SendRC(5, 1300, True)
print("Done")
Script.WaitFor('LAND', 5000)
print("Entered Landing Mode")
ret = wait_altitude(-5, 1)
print("LANDING: ok= %s" % ret)
print("Landing complete")
return ret
def disarm_motors():
'''disarm motors'''
print("Disarming motors")
print("Change mode to stabilize")
Script.ChangeMode("STABILIZE") # stabilize mode
print("Done")
Script.WaitFor('STABILIZE', 5000)
Script.SendRC(3, 1000, True)
Script.SendRC(4, 1000, True)
Script.WaitFor('DISARMING MOTORS',15000)
Script.SendRC(4, 1500, True)
#mav.motors_disarmed_wait()
print("MOTORS DISARMED OK")
return True
'''Main'''
setup_rc()
while cs.lat == 0:
print 'Waiting for GPS'
Script.Sleep(1000)
print 'Got GPS'
arm_motors()
takeoff()
land()
disarm_motors()
setup_rc()