crazyswarm下载编译和使用问题整理

24 篇文章 4 订阅
3 篇文章 0 订阅

本文写于2021.12.6 最近一次更新为2023.1.5

目录

项目简介

安装步骤

编译报错解决

使用注意


项目简介

crazyswarm版本对应commit为 4d6ca47b085227fbc893479894001d1c7ceab5cc

crazyswarm项目地址

GitHub - USC-ACTLab/crazyswarm: A Large Quadcopter SwarmA Large Quadcopter Swarm. Contribute to USC-ACTLab/crazyswarm development by creating an account on GitHub.https://github.com/USC-ACTLab/crazyswarm.git

crazyswarm wiki

Welcome to Crazyswarm’s documentation! — Crazyswarm 0.3 documentationhttps://crazyswarm.readthedocs.io/en/latest/

安装步骤

 在ubuntu18.04上下载编译crazyswarm仿真和实物代码。按照wiki中的installation来就行。

不用严格按照这个一字一句来,理解即可。比如安装libpython-dev,还有安装pip(一般已经有了不需要安装)。还有用pip安装功能包直接pip install就行。安装依赖包的时候尽量一个一个装,确保每个都装成功了。

要注意的是crazyswarm中包含很多submodule子模块,比如crazyflie_firmware, crazyflie_cpp,  libmotioncapture, libobjecttracker等。这些子模块是其他的git仓库,在crazyswarm被git clone下来时不会自动下载,只会留一个空目录在那

./build.sh的作用就是git submodule update下载这些子模块,并编译ros程序:

由于网络原因,这些gitub子仓库未必下载成功或者完整。因此我建议手动一行一行在命令行里输入build.sh里面的命令,确认这些子模块都下载了,目录里都有文件了,再进行编译。

编译就是倒数第二行catkin_make 那一行,建议手动输入这行命令。(不然运行build.sh又把前面完成的工作重做一遍,容易出问题)

编译报错解决

1、如果报错找不到crazyflie_cpp之类的包,或者找不到什么Cmakelist.txt文件。大概率是上一步某个子模块没下载下来。重新去git submodule update确保子模块目录下都有文件了。

2、如果报错cmake error at ..... 可能是由于cmake版本问题。

ros-melodic自带cmake-3.10.0,可以改用cmake-3.21.0版本。不能通过sudo apt upgrade或者install, 也不要sudo apt remove cmake,否则会把ros也卸载。需要从官网下载高版本cmake,然后强制软链接。教程:

ubuntu 16.04 + cmake 升级 - 知乎ubuntu 16.04 默认安装的 cmake 版本为 3.5,但有时编译一些包时需要更高的版本,所以需要升级一下 cmake。 若用 cmake 编译过 ros ,千万别傻乎乎地随便找个帖子执行下面的命令: sudo apt-get autoremove cmake…https://zhuanlan.zhihu.com/p/93480024注意把其中的版本都改成3.21.0

不需要删除ros的cmake文件夹。

3、编译成功 了,下面运行pytest检查的时候报错找不到vispy

那么就用pip装一下就行:

pip install vispy

4、安装了vispy,继续运行pytest的时候,报错

这是由于python3.5以后gcd(求公约数)已经从fractions(分数)包转移到了math,但是我们这里仍然使用的是python2.7。因此需要根据报错py文件路径找到torusknot.py文件,把里面from math import gcd改成from fractions import gcd即可。

使用注意

1、新的crazyradio在使用前需要先设置usb口权限,windows还需要装驱动:

windows用zadig更新usb驱动:Installing USB driver on Windows | Bitcraze

ubuntu开启usb权限:USB permissions | Bitcraze

sudo groupadd plugdev
sudo usermod -a -G plugdev $USER
# log out and log in again in order to be a member of the plugdev group.

#Copy-paste the following in your console, this will create the file /etc/udev/rules.d/99-bitcraze.rules:
cat <<EOF | sudo tee /etc/udev/rules.d/99-bitcraze.rules > /dev/null
# Crazyradio (normal operation)
SUBSYSTEM=="usb", ATTRS{idVendor}=="1915", ATTRS{idProduct}=="7777", MODE="0664", GROUP="plugdev"
# Bootloader
SUBSYSTEM=="usb", ATTRS{idVendor}=="1915", ATTRS{idProduct}=="0101", MODE="0664", GROUP="plugdev"
# Crazyflie (over USB)
SUBSYSTEM=="usb", ATTRS{idVendor}=="0483", ATTRS{idProduct}=="5740", MODE="0664", GROUP="plugdev"
EOF

# You can reload the udev-rules using the following:
sudo udevadm control --reload-rules
sudo udevadm trigger

2、新的crazyflie一定要用cfclient先更新一下它的固件,注意选择cf2而不是bolt的固件。

如果更新过程失败导致飞机无法连接了,可以用cfclient中的cold boot恢复模式重新刷固件:Recovery firmware flashing | Bitcraze

To update the firmware in the Crazyflie 2.X do the following:

  • Make sure that the Crazyflie is disconnected from the client and powered off.
  • Go to the menu Crazyflie->Bootloader
  • Select the "Cold boot (recovery)" tab in the dialog.
  • Press and hold the power button on the Crazyflie for about 3 seconds. The blue LED (M2) starts to blink to indicate the Crazyflie is in bootloader mode. If a wrong nRF51 firmware has been flashed you might have to start from an un-powered state. Then hold the button and connect power.
  • Click "Initiate bootloader cold boot" in the client
  • Select the latest release from the drop down menu or the file if you have downloaded it from the Github release page.
  • Press "Program" and wait (do not restart the crazyflie until it is finished.)
  • Press "Restart in firmware mode"

Be aware that no deck firmware be updated in this mode, so please use the the cfclient userguide after you have recovered crazyflie.

3、一定要按照crazyswarm的wiki更新crazyradio的固件!固件的二进制文件在prebuilt文件夹下。否则通信会有问题,定位数据无法正常发送到飞机。

git clone https://github.com/bitcraze/crazyradio-firmware.git

python crazyradio-firmware/usbtools/launchBootloader.py

sudo python3 crazyradio-firmware/usbtools/nrfbootload.py flash prebuilt/cradio.bin 

# change prebuilt/cradio.bin into the cradio.bin path in your crazyswarm! 
# remember to use python3 even on ubuntu 18.04

# Now unplug and re-plug the radio. You can check the version using 

rosrun crazyflie_tools scan -v

# which should report Found Crazyradio with version 99.55.

如果烧写固件时报错

ModuleNotFoundError: No module named 'usb'

那么用apt安装一下就行,不是用pip装:

sudo apt install python3-usb # ubuntu 20.04

sudo apt install python-usb # ubuntu 18.04

4、如果使用usb而非crazyradio连接crazyflie时,cfclient和cflib无法连接上crazyflie,可以考虑升级cflib到最新版0.1.21。

但是实测ubuntu18只能安装0.1.16版本的cflib(因为python3是3.6版本的,不支持cflib0.1.16以后版本的一些库)

0.1.16版本的cflib其实可以用于usb连接2021.6版本的crazyflie,但也还存在usb多次连接容易失败的问题,见https://github.com/bitcraze/crazyflie-lib-python/issues/264 。这个问题在cflib0.1.17.1版本中被解决(针对crazyflie 2021.6版本),见Fix USB connection to CF by ataffanel · Pull Request #312 · bitcraze/crazyflie-lib-python · GitHub。后续针对2022.6版本的crazylie,这个问题又被cflib0.1.20版本中的https://github.com/bitcraze/crazyflie-lib-python/pull/338 进一步改进。

综上,如果只能使用cflib0.1.16,可以借鉴上面第二个PR#338中的改进,手动修改crazyfie-lib-python 0.1.16版本源码中的文件,再pip源码安装:

git clone https://github.com/bitcraze/crazyflie-lib-python.git
cd crazyflie-lib-python
git checkout 0.1.16
# in "crazyflie-lib-python/cflib/drivers/cfusb.py" line 98-109

#        if self.dev:
#            if (pyusb1 is True):
#                self.dev.set_configuration(1)
#                self.handle = self.dev
#                self.version = float(
#                   '{0:x}.{1:x}'.format(self.dev.bcdDevice >> 8,
#                                         self.dev.bcdDevice & 0x0FF))
#            else:
#                self.handle = self.dev.open()
#                self.handle.setConfiguration(1)
#                self.handle.claimInterface(0)
#                self.version = float(self.dev.deviceVersion)
        try:  # configuration might already be confgiured by composite VCP, try claim interface
            usb.util.claim_interface(self.dev, 0)
        except Exception:
            try:
                self.dev.set_configuration()  # it was not, then set configuration
            except Exception:
                if self.dev:
                    if platform.system() == 'Linux':
                        self.dev.reset()
                        self.dev.set_configuration()

        self.handle = self.dev
        self.version = float(
            '{0:x}.{1:x}'.format(self.dev.bcdDevice >> 8,
                                 self.dev.bcdDevice & 0x0FF))

pip uninstall cflib
cd crazyflie-lib-python
pip install -e .
  • 4
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值