Crazyswarm2

repository·main·Indexed 42 days ago

https://github.com/imrclab/crazyswarm2

A ROS 2-based control stack for Bitcraze Crazyflie multirotor robots, enabling swarm coordination and management. It provides infrastructure for controlling drones via ROS 2 services and topics, including support for full state setpoints, trajectory uploads, and firmware parameter mapping. The stack includes a simulator with Blender visualization for synthetic image generation and robot perspective monitoring.

Tokens
21.9K
Snippets
49
Records
84
Agent score
54%

What's inside Crazyswarm2

  1. Overview of Crazyswarm2

    main
    Crazyswarm2 is a ROS 2-based software stack designed for controlling Bitcraze Crazyflie multirotor robots. It provides the necessary infrastructure to manage and coordinate swarms of these robots within a ROS 2 ecosystem.
  2. What is Crazyswarm2?

    main

    Crazyswarm2 is a ROS 2 stack designed for controlling aerial robot teams. It is a ROS 2 port of the original Crazyswarm project and supports Bitcraze AB flight computers, including:

    • Crazyflie 2.1(+)
    • Crazyflie 2.1 Brushless
    • Flapper Nimble+
    • Custom drones built using Crazyflie Bolt

    It is open-source under the MIT license.

  3. Understand the Crazyswarm2 package structure

    main

    The Crazyswarm2 (Crazyflie ROS 2) project is organized into several specialized packages:

    • crazyflie/: Contains the Crazyflie server nodes and the crazyflies.yaml configuration file.
    • crazyflie_py/: A Python library that wraps ROS 2 services and topics to facilitate connection with the Crazyflie server nodes.
    • crazyflie_examples/: Contains practical examples of using the Crazyflie ROS 2 package.
    • crazyflie_interfaces/: Defines all custom ROS 2 messages (msgs) and services (srvs) used in the project.
    • crazyflie_sim/: Contains the simulator for software-in-the-loop (SIL) testing.
  4. Use the pycrazyswarm Python API

    main

    The pycrazyswarm module (located in /ros_ws/src/crazyswarm/scripts) is the primary high-level interface for the Crazyswarm platform. Most research projects can be implemented by writing pycrazyswarm scripts and modifying configuration files without needing to modify the underlying Crazyswarm codebase.

    The API is designed to be hardware-agnostic. For every class in pycrazyswarm.crazyflie, there is an identically named class in pycrazyswarm.crazyflieSim. Because the APIs are identical, you can write your logic once and switch between real hardware and simulation seamlessly.

  5. What is a Setpoint?

    main

    A setpoint is a collection of desired values for some or all of a quadrotor's states that the feedback controller is tasked to achieve.

    Depending on the application, a setpoint might include:

    • Position only (e.g., x, y, z)
    • Position, velocity, and acceleration
    • Other state combinations required for specific maneuvers.
  6. Understand Piecewise Polynomials in Crazyswarm

    main

    Crazyswarm uses piecewise polynomials for quadrotor trajectory planning. A piecewise polynomial is a function composed of multiple polynomial segments defined over specific time intervals.

    In Crazyswarm, these are specifically implemented as degree-7 polynomials with 4-dimensional vector-valued outputs:

    1. x (position)
    2. y (position)
    3. z (position)
    4. yaw angle

    Because quadrotors possess the property of differential flatness, computing these four values allows the system to derive all other necessary states, such as attitude, acceleration, and angular velocity. For trajectory planning, these polynomials must be smooth (continuous and differentiable) to ensure stable flight.

  7. Choose a Crazyflie server backend

    main

    The Crazyflie server supports three distinct backends depending on your hardware or simulation needs:

    1. cpp: Uses crazyflie-link-cpp at the lowest layer. Best for high-performance requirements.
    2. cflib: Based on crazyflie-lib-python. Handles logging, parameters, and command sending.
    3. sim: A software-in-the-loop (SIL) simulator that behaves like a regular backend, providing the same ROS 2 topics and services as the hardware backends.
  8. Differences between Crazyswarm2 and Crazyswarm1

    main

    Crazyswarm2 is a redesigned version of Crazyswarm with several architectural improvements:

    • Motion Capture: Unlike Crazyswarm1 (where MoCap was part of the crazyswarm_server), Crazyswarm2 uses a separate ROS 2 package (motion_capture_tracking) for abstraction and frame-by-frame tracking. It also supports Lighthouse and on-board localization.
    • Communication Backend: Crazyswarm2 uses crazyflie-link-cpp at the lowest layer, which supports priority queues (allowing trajectory uploads during flight) and improved robustness. It also has experimental support for crazyflie-lib-python.
    • UAV Task Support: Crazyswarm2 supports single-robot operations like teleoperation and arbitrary URIs, whereas Crazyswarm1 was focused primarily on swarm operations.
    • Simulation: Crazyswarm2 implements simulation as an alternative backend, supporting multiple physics/visualization backends (including aerodynamics), whereas Crazyswarm1 only provided simple setpoint visualization for high-level Python scripts.
    • Swarm Monitoring: Crazyswarm2 allows for common monitoring tasks (like checking battery voltage or enabling/disabling Crazyflies) without needing to restart ROS nodes or use external tools like chooser.py.
  9. How the Crazyflie server works

    main

    The Crazyflie server node acts as the bridge between multiple Crazyflies and one or more Crazyradio PA dongles. It manages low-level communication and exposes high-level ROS 2 interfaces.

    Key Responsibilities

    • Parameter Management: Transforms Crazyflie Parameter ToC into ROS 2 parameters and applies settings from crazyflies.yaml to the hardware.
    • Logging: Sets up logblocks for data streaming and converts received variables into ROS 2 topics.
    • Run-time Configuration: Allows real-time configuration of parameters and logging while connected.

    Flight Command Services

    Commands can be sent to all drones using the /all prefix or to specific drones using the /cf2 (or individual ID) prefix. Supported services include:

    • Takeoff / Land / GoTo: Execute takeoff, landing, or movement to specific coordinates/heights.
    • Upload / Start trajectory: Upload a predefined trajectory and trigger its execution.
    • Emergency: Immediately turn off the motors.
  10. How simulation and real hardware APIs relate

    main

    Crazyswarm uses a mirroring pattern to allow seamless testing. For every hardware-facing class in pycrazyswarm.crazyflie, there is a corresponding simulation class in pycrazyswarm.crazyflieSim with the exact same method signatures and properties.

    • pycrazyswarm.crazyflie.Crazyflie: Used for controlling real Crazyflie hardware.
    • pycrazyswarm.crazyflieSim.CrazyflieSim: Used for testing scripts in a 3D simulation environment.

    Because the APIs are identical, you can develop and debug your swarm logic in simulation before deploying to physical drones.

  11. Debug firmware modules via Python bindings

    main

    Crazyswarm exposes selected Crazyflie firmware modules to Python scripts via pycrazyswarm bindings. These bindings are generated from C header files using SWIG.

    If a firmware module's core functionality has no dependencies on ARM or FreeRTOS, it can be compiled for x86 and tested/debugged on a PC using these bindings. This is particularly useful for implementing and testing new firmware modules in a simulated environment.

  12. Differences between Crazyswarm2 and Bitcraze's cflib

    main

    While both allow controlling multiple Crazyflies via Python, Crazyswarm2 differs in the following ways:

    • Motion Capture: Crazyswarm2 integrates with MoCap hardware via the motion_capture_tracking ROS 2 package. While the Bitcraze API can send position measurements to a Crazyflie, it does not handle retrieving measurements from MoCap hardware. Crazyswarm2 also allows for identical or single MoCap markers.
    • Communication: Crazyswarm2 prioritizes broadcast communication to reduce the number of radios required per Crazyflie, whereas the official SDK uses unicast.
    • Simulation: Crazyswarm2 includes a simulation mode with 3D graphics for validating scripts before hardware deployment.
    • Firmware Bindings: The Crazyswarm2 simulator uses automatically generated Python bindings for Crazyflie firmware modules, which aids in developing and debugging complex firmware modules.
    • ROS 2 Foundation: The Crazyswarm2 server is a ROS 2 node, and the Python API acts as a thin wrapper around this ROS 2 interface.