无人机编程-Arducopter-通过任务规划器编写基本Python脚本
一些通过任务规划程序驾驶无人机的人能在下面帮助我吗 我是无人机的初学者。我正试图通过使用Python的任务规划器对四架直升机进行非常基本的导航,如起飞、悬停和着陆 我在基础上遇到了一些困难。我一直在浏览示例代码并编写一些脚本 我写了一个基本的脚本,包括起飞、悬停和着陆。我也遇到了一些问题, -起飞方向相反 -起飞不是垂直的 -应该控制高度。它不应该超过一米。 -速度很快。我如何减少它 而且, 当启动电机时,我在示例代码中看到,我们正在将偏航设置为最大值(2000),并将其恢复到空档(1500)。为什么? 以下是我对RCs的理解, RC1-滚动 RC2-俯仰 RC3-油门 RC4-偏航 RC5-用于改变模式 有人能帮我解决这些问题吗?我在下面附上了我的示例代码 谢谢大家!无人机编程-Arducopter-通过任务规划器编写基本Python脚本,python,Python,一些通过任务规划程序驾驶无人机的人能在下面帮助我吗 我是无人机的初学者。我正试图通过使用Python的任务规划器对四架直升机进行非常基本的导航,如起飞、悬停和着陆 我在基础上遇到了一些困难。我一直在浏览示例代码并编写一些脚本 我写了一个基本的脚本,包括起飞、悬停和着陆。我也遇到了一些问题, -起飞方向相反 -起飞不是垂直的 -应该控制高度。它不应该超过一米。 -速度很快。我如何减少它 而且, 当启动电机时,我在示例代码中看到,我们正在将偏航设置为最大值(2000),并将其恢复到空档(1500)。
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()
导入时间
起飞油门=1700
def设置_rc():
打印(“将所有RCs设置为空档”)
对于范围(1,9)内的chan:
脚本.SendRC(chan,1500,False)
SendRC(3,Script.GetParam('RC3_MIN'),True)
脚本。睡眠(5000)
打印(“完成”)
返回真值
def臂_电机():
“启动电机”
打印('APM:启动电机')
打印(“将模式设置为稳定”)
Script.ChangeMode(“稳定”)#稳定模式
Script.SendRC(51750,真)
打印(“完成”)
打印('将油门设置为最小值')
Script.SendRC(31000,True)
打印(“完成”)
打印('设置偏航')
Script.SendRC(42000,True)
打印(“完成”)
打印(“等待启动电机”)
cs.messages.Clear()
脚本。等待(“启动电机”,20000)#30000(30秒)
打印(“完成”)
打印(‘重置偏航’)
Script.SendRC(41500,True)
打印(“完成”)
返回真值
def等待高度(最低高度,最高高度,超时=30):
爬升率=0
上一个alt=0
''等待给定的高度范围''
tstart=time.time()
打印(“等待在%u和%u之间的高度%(最低高度,最高高度))
而time.time() 如果cs.alt>=alt\u min和cs.alt如果我不得不猜测-将偏航更改为最大值&重置可能有助于将其从之前的任何状态归零。只需注意:在起飞()
中,从Script.SendRC(51750,True)
开始的行中,看起来您从更高的油门(1750)开始,然后在起飞时降低油门(1700),与你的书面声明相反。