DroneKit教程(七):遥控信道覆盖
MAVLink支持一项有用却又非常危险的功能:遥控信道覆盖(Channel Override)。遥控信道覆盖可以将任一至全部通道的遥控输入信号改写为任意值。当前,DroneKit的开发者已经建议不再使用此功能。
在使用时,需要维持输出值在上下限之间、飞控与指令发送端的连接稳定可靠、有完备的故障保护手段。遥控信道覆盖可以用作虚拟摇杆操控、或者以最“直观”的方式执行一些自动化任务。但是一般情况下,我们还是建议使用MAVLink指令。
预先准备
根据“使用从源码编译的SITL测试DroneKit代码”中的要求,运行SITL和MAVProxy:
打开Cygwin Terminal,依次输入
.. -- -,,, --
新开一个cmd,运行
mavproxy.py --master tcp:127.0.0.1:5760 --sitl 127.0.0.1:5501 --out 127.0.0.1:14550 --out 127.0.0.1:14551
(可选)使用MissionPlanner地面站监控无人机的状态。运行MissionPlanner地面站,右上角选择UDP,点击connect连接。端口填写14550
在测试过程中,请保持SITL和MAVProxy运行。
编程示例
本示例改写自DroneKit的官方示例。
"""
© Copyright 2015-2016, 3D Robotics.
channel_overrides.py:
Demonstrates how set and clear channel-override information.
# NOTE:
Channel overrides (a.k.a "RC overrides") are highly discommended (they are primarily implemented
for simulating user input and when implementing certain types of joystick control).
"""
from dronekit import connect
connection_string = '127.0.0.1:14551'
print 'Connecting to vehicle on: %s' % connection_string
vehicle = connect(connection_string, wait_ready=True)
print "Read channels individually:"
print " Ch1: %s" % vehicle.channels['1']
print " Ch2: %s" % vehicle.channels['2']
print " Ch3: %s" % vehicle.channels['3']
print " Ch4: %s" % vehicle.channels['4']
print " Ch5: %s" % vehicle.channels['5']
print " Ch6: %s" % vehicle.channels['6']
print " Ch7: %s" % vehicle.channels['7']
print " Ch8: %s" % vehicle.channels['8']
print "Number of channels: %s" % len(vehicle.channels)
print "\nChannel overrides: %s" % vehicle.channels.overrides
print "Set Ch2 override to 200 (indexing syntax)"
vehicle.channels.overrides['2'] = 200
print " Channel overrides: %s" % vehicle.channels.overrides
print " Ch2 override: %s" % vehicle.channels.overrides['2']
print "Set Ch3 override to 300 (dictionary syntax)"
vehicle.channels.overrides = {'3':300}
print " Channel overrides: %s" % vehicle.channels.overrides
print "Set Ch1-Ch8 overrides to 110-810 respectively"
vehicle.channels.overrides = {'1': 110, '2': 210,'3': 310,'4':4100, '5':510,'6':610,'7':710,'8':810}
print " Channel overrides: %s" % vehicle.channels.overrides
print "\nCancel Ch2 override (indexing syntax)"
vehicle.channels.overrides['2'] = None
print " Channel overrides: %s" % vehicle.channels.overrides
print "Clear Ch3 override (del syntax)"
del vehicle.channels.overrides['3']
print " Channel overrides: %s" % vehicle.channels.overrides
print "Clear all overrides"
vehicle.channels.overrides = {}
print " Channel overrides: %s" % vehicle.channels.overrides
print "\nClose vehicle object"
vehicle.close()
print("Completed")
读取和设置信道
使用vehicle.channels读取信道
vehicle.channels
将返回一个字典元素,键值为通道的序数。
vehicle.channels['2']
vehicle.channels
使用vehicle.channels.overrides覆盖信道
vehicle.channels.overrides
与vehicle.channels
类似,也是一个字典。它将对其中存在的元素进行信道覆盖,不存在的元素保留现有输入。
vehicle.channels.overrides['2'] = 500
vehicle.channels.overrides['2'] = None
del vehicle.channels.overrides['2']
vehicle.channels.overrides = {'1': 500, '2': 500, '3': 1000, '4': 500}
vehicle.channels.overrides = {}
vehicle.channels.overrides = None
版本信息
1.0 20170916 initial commit
本作品采用知识共享署名-相同方式共享 3.0 未本地化版本许可协议进行许可。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)