What is the best approach to control CrazyFlies in a Vicon or Optitrack environment.

Discussions related to positioning systems where the position is calculated outside the Crazyflie and sent to the device using radio, including MoCap systems
Post Reply
Ahmad
Beginner
Posts: 2
Joined: Wed Mar 03, 2021 7:28 pm

What is the best approach to control CrazyFlies in a Vicon or Optitrack environment.

Post by Ahmad »

Hello everyone,

I am a graduate student, and I am currently running experiments for networked control on CrazyFlie quadcopters. I have seen many comments online and on the forum about controlling multiple CrazyFlie. However, as new tools and software versions update by Bitcraze and third parties were coming out over the years, I am getting confuses about which tools I should use. So far, I successfully ran an experiment in an Optitrack motion capture environment. I read Optitrack data using the Python NaTNetClient and then I send send_setpoint(roll, pitch, yaw, thrust) to the Crazyflie. However, I faced challenges with extending this to multiple quadcopters, and my Python code is a bit slow; I sped up the code using Numba.

My goal is to build a reliable CrazyFlie testbed to run networked control experiments in a Vicon or Optitrack motion capture environment. I have three radios and ten CrazyFlies. I need some help, as I got stuck, and I do not want to reinvent the wheel.

Below are my questionsl:

1) What is the best way to control multiple CrazyFlie?
a) is it via the Bitcraze Python library, i.e., individually controlling, Crazyflie() objects or using Swarm() object.
b) is it via the Crazyswarm? I see two github repos. What is the difference between them?
https://github.com/USC-ACTLab/crazyswarm
https://github.com/whoenig/crazyflie_ros?

2) Crazyflie specific questions
a) how many Crazyflies can I control with a single radio? I read somewhere it is 3-4 and how come Crazyswarm could control 15? is it simply that Crazyswarm has a better radio driver?
b) how can I quantify or know the delay between sending my setpoint command, via radio, to executing the command by the Crazyflie? this will effectively allow me to determine the control update rate for my control system.

3) Python code is typically slow. For example, in my experiment code, I used Numba to speed up my code. How do you guys deal with the slow execution time of Python? Do you use the Crazyswarm ROS C++ for example? I was also confused about that as well. The main page of Crazyswarm says they provide a python-based tool but Whoenig github repo provides c++ tools.

Many thanks, and I hope to hear back from you guys soon.

Ahmad
whoenig
Expert
Posts: 395
Joined: Mon Oct 27, 2014 2:55 am

Re: What is the best approach to control CrazyFlies in a Vicon or Optitrack environment.

Post by whoenig »

[I am one of the authors of the Crazyswarm, so I am biased.]

In general, I'd still recommend the Crazyswarm if you are planning to control more than 5 CFs. The Crazyswarm server is written in C++ and directly interfaces with the VICON/Optritrack libraries (in the same binary) to minimize latency. You can write your high-level commands as any ROS node - we use and provide examples in Python. Crazyswarm makes uses of broadcast communication heavily, which allows more CFs/radio, unless you need unicast communication in your use-case. With single-marker tracking, it should be possible to control about 25 CFs/radio this way. The Python library can maybe handle 3-4 CFs/radio and uses unicast, only.

To the other questions:
1a) That's a personal programming choice. There is no difference in performance I believe.
1b) crazyflie_ros will be discontinued and is currently the foundation of the Crazyswarm. For new projects, I do not recommend using crazyflie_ros directly.
2a) See above, depends on your communication use-case and software choice.
2b) We have latency test scripts for that. This is in the range of 2-5ms in general. Note that you can't do high-performance off-board attitude control due to sensor latencies over the radio.
3) See above. Another way is to write C++ code and generate Python bindings to speed up your code. Most code does not need to be fast, so this would only be required for motion planning or control code.
Ahmad
Beginner
Posts: 2
Joined: Wed Mar 03, 2021 7:28 pm

Re: What is the best approach to control CrazyFlies in a Vicon or Optitrack environment.

Post by Ahmad »

Thank you so much for the prompt and detailed response.

Sorry, for taking a long time to follow up.

I have already build my ROS software that controls Crazyflie and other quadcopter platforms, e.g. Parrot AR. I will have to stick with my implementation, as I have gui's that simplify experimentation and utilization.

My question is the following:
Is there an easy way for me to integrate the multicast radio software from Crazyswarm into the Crazyflie-Python-lib? I am primarily using the commander.send_setpoint(roll, pitch, yaw, thrust) method to control the Crazyflies. The values for roll, pitch, yaw, thrust come from my controller and trajectory generator. I like the convenience of using a single radio for 15 instead of 4 or 5 radios.

Many thanks in advance for your feedback.

Kind regards, and I look forward to hearing from you.

Ahmad
whoenig
Expert
Posts: 395
Joined: Mon Oct 27, 2014 2:55 am

Re: What is the best approach to control CrazyFlies in a Vicon or Optitrack environment.

Post by whoenig »

If you are already using ROS, you could just use the Crazyswarm. You are not forced to use its Python API - you can directly communicate with the server using publishers and subscribers via rospy.

For your question: this is unfortunately not easily possible, because the python-lib does not support broadcast communication yet. In your use-case, however, you will not benefit from that feature. From what I understand, you run the position controller off-board and only the attitude controller on-board. Thus, you do not need to send the motion capture feedback back to each Crazyflie. In that case, even the Crazyswarm would just rely on unicast communication and the number of drones per radio is limited (depending on the update frequency I guess perhaps 5 CFs/radio). The benefit of the Crazyswarm only comes into play if you use the on-board nonlinear controller and Kalman filter and need to send the motion capture data to the Crazyflie.
Post Reply