学习Crazyflie 2.X平台(4)

STEM drone bundle

  1. 包含了3个东西
  2. 安装flow deck: 拿到按照学习Crazyflie 2.X平台(1)安装好的无人机,将flow deck安装在下面[必须在下面],用long pin-headers将deck别上去。
  3. 安装python和cflib(以下只讲Ubuntu系统下的情况,tested on Ubuntu 16.04):
    • 安装python3和pip: sudo apt-get install python3 python3-pip python3-usb idle3
    • 安装Crazyflie Library: pip3 install cflib
    • 为了可以使用Crazyradio,需要USB devices的access权限。那么我们需要跑以下命令来获取access权限。并且在跑完以下命令之后,需要将Crazyradio重插一下。
sudo groupadd plugdev
sudo usermod -a -G plugdev $USER
echo 'SUBSYSTEM=="usb", ATTRS{idVendor}=="1915", ATTRS{idProduct}=="7777", MODE="0664", GROUP="plugdev"' | sudo tee /etc/udev/rules.d/99-crazyradio.rules

跑第一个飞行实验

我们需要跑以下的Python script要飞Crazyflie。一定要注意的就是如果python client是打开的,一定要与Crazyflie断开连接,因为Crazyradio只能支持同时跟一个program对话。如果python client还开着,刚跑python script是没作用的。

"""
This script shows a simple scripted flight path using the MotionCommander class.

Simple example that connects to the crazyflie at `URI` and runs a
sequence. Change the URI variable to your Crazyflie configuration.
"""
import logging
import time

import cflib.crtp
from cflib.crazyflie.syncCrazyflie import SyncCrazyflie
from cflib.positioning.motion_commander import MotionCommander

URI = 'radio://0/80/250K'

# Only output errors from the logging framework
logging.basicConfig(level=logging.ERROR)


if __name__ == '__main__':
    # Initialize the low-level drivers (don't list the debug drivers)
    cflib.crtp.init_drivers(enable_debug_driver=False)

    with SyncCrazyflie(URI) as scf:
        # We take off when the commander is created
        with MotionCommander(scf) as mc:
            print('Taking off!')
            time.sleep(1)

            # There is a set of functions that move a specific distance
            # We can move in all directions
            print('Moving forward 0.5m')
            mc.forward(0.5)
            # Wait a bit
            time.sleep(1)

            print('Moving up 0.2m')
            mc.up(0.2)
            # Wait a bit
            time.sleep(1)

            print('Doing a 270deg circle');
            mc.circle_right(0.5, velocity=0.5, angle_degrees=270)

            print('Moving down 0.2m')
            mc.down(0.2)
            # Wait a bit
            time.sleep(1)

            print('Rolling left 0.2m at 0.6m/s')
            mc.left(0.2, velocity=0.6)
            # Wait a bit
            time.sleep(1)

            print('Moving forward 0.5m')
            mc.forward(0.5)

            # We land when the MotionCommander goes out of scope
            print('Landing!')

跑完以上代码,crazyflie会按照以上script的描述飞行,期望的输出应该是:

Connecting to radio://0/80/250K
Connected to radio://0/80/250K
Taking off!
Moving forward 0.5m
Moving up 0.2m
Doing a 270deg circle
Moving down 0.2m
Rolling left 0.2m at 0.6m/s
Moving forward 0.5m
Landing!

STEM ranging bundle:基本跟刚才的bundle一样,就不翻译了

1 Comment

Leave a Comment