LOCO定位系统入门教程-使用python脚本改变飞行高度
说明:
- 介绍如何使用python脚本,改变飞行高度
步骤:
新建python脚本motion_flying.py
代码如下
import logging
import sys
import time
from threading import Event
import cflib.crtp
from cflib.crazyflie import Crazyflie
from cflib.crazyflie.syncCrazyflie import SyncCrazyflie
from cflib.positioning.motion_commander import MotionCommander
from cflib.utils import uri_helper
URI = uri_helper.uri_from_env(default='radio://0/80/2M/E7E7E7E7E7')
DEFAULT_HEIGHT = 0.5
deck_attached_event = Event()
logging.basicConfig(level=logging.ERROR)
def take_off_simple(scf):
with MotionCommander(scf) as mc:
mc.up(0.3)
time.sleep(3)
mc.stop()
def param_deck_flow(name, value_str):
...
if __name__ == '__main__':
cflib.crtp.init_drivers()
with SyncCrazyflie(URI, cf=Crazyflie(rw_cache='./cache')) as scf:
scf.cf.param.add_update_callback(group='deck', name='bcFlow2',
cb=param_deck_flow)
time.sleep(1)
if not deck_attached_event.wait(timeout=5):
print('No flow deck detected!')
sys.exit(1)
take_off_simple(scf)
- 运行脚本
python3 motion_flying.py
- crazyflie会先起飞到0.3米,然后再上升0.3米
获取最新文章: 扫一扫右上角的二维码加入“创客智造”公众号