Get ardupilot output channels

こ雲淡風輕ζ 提交于 2019-12-25 01:07:05

问题


How do we get output channel values of an ardupilot from dronekit-python?

We can get input channels from vehicle.channels but I couldn't find anything similar for output channels.

EDIT:

from time import sleep
from dronekit import connect
import dronekit_sitl

sitl = dronekit_sitl.start_default()
connection_string = sitl.connection_string()

vehicle = connect(connection_string,wait_ready=True)

while not vehicle.is_armable:
    sleep(1)
    print"Initializing"

vehicle.armed = True
while not vehicle.armed:
    print "Arming"
    sleep(1)
print "Armed"

@vehicle.on_attribute('ch1out')
def ch1out_listener(self, name, msg):
    print '%s attribute is: %s' % (name, msg)

for i in range(1000,2000,100):
    vehicle.channels.overrides['3']=i
    sleep(1)

vehicle.close()

It should print ch1out everytime I update channel 3 but it is not.


回答1:


I assume what you mean output channels is this 'ch1out','ch2out' value and so on.

To get that value you can simply just using an attribute listener like this

@vehicle.on_attribute('ch1out')
def ch1out_listener(self, name, msg):
    print '%s attribute is: %s' % (name, msg)

This function essentially just print the 'ch1out' value everytime it changes, you can just modify it accordingly. You can read more about this at here Observing attribute changes.

But if you want to access the output channel value directly from the vehicle object like the input channel or other attribute.

(Ex: vehicle.channels, vehicle.mode)

You can add the output channel to the vehicle object by following this example provided by the Dronekit-Python documentation Create Attribute in App.



来源:https://stackoverflow.com/questions/53296288/get-ardupilot-output-channels

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!