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 move_linear_simple(scf):
with MotionCommander(scf, default_height=DEFAULT_HEIGHT) as mc:
time.sleep(1)
mc.forward(0.5)
time.sleep(1)
mc.turn_left(180)
time.sleep(1)
mc.forward(0.5)
time.sleep(1)
def take_off_simple(scf):
...
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)
move_linear_simple(scf)
- 运行脚本
python3 motion_flying.py
- crazyflie起飞,前进0.5米,左转180度,然后再次前进,到其初始位置
获取最新文章: 扫一扫右上角的二维码加入“创客智造”公众号