< >
Home » LOCO定位系统入门教程 » LOCO定位系统入门教程-使用python脚本检查甲板是否连接到crazyflie

LOCO定位系统入门教程-使用python脚本检查甲板是否连接到crazyflie

说明:

  • 介绍如何使用python脚本,检查甲板是否连接到crazyflie

步骤:

  • 新建一个python脚本motion_flying.py

  • 使用loco定位系统和甲板:deck.bcLoco

  • 代码如下:

import logging
import sys
import time
from threading import Event

import cflib.crtp
from cflib.crazyflie import Crazyflie
from cflib.crazyflie.log import LogConfig
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')

deck_attached_event = Event()

logging.basicConfig(level=logging.ERROR)

def param_deck_flow(_, value_str):
    value = int(value_str)
    print(value)
    if value:
        deck_attached_event.set()
        print('Deck is attached!')
    else:
        print('Deck is NOT attached!')


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='bcLoco',
                                         cb=param_deck_flow)
        time.sleep(1)
  • 执行脚本
python3 motion_flying.py
  • 结果如下
1
Deck is attached!
  • 现在能够检测到甲板,已正确连接

纠错,疑问,交流: 请进入讨论区点击加入Q群

获取最新文章: 扫一扫右上角的二维码加入“创客智造”公众号


标签: loco定位系统入门教程