This package provides a basic interface to use low-level control (roll, pitch, yaw rate, thrust) to interface with the crazyflie 2.1. It is meant as the base package upon which more elaborate controllers can be built.
The template_controller.py file provides the template to inherit for creating one owns controller. It can be imported as follows: from crazyflie_interface_py.template_controller import TemplateController.
- We provide a basic
lqr_controller.pyto showcase how to inherit from theTemplateController. - The
template_controller.pyhas the following base functionality (which can be overridden) implemented:- Keeps track of
self.state(subscribed from thecf_interface/statetopic) - Provides a wrapper around
__call__(self, state);publish_control.pywhich converts the control commands to ROS2 message and publishes to thecf_interface/controltopic. - Sets the control rate & associated timer.
- Keeps track of
The base functionality (ros2 launch crazyflie_interface launch.py) does the following:
- Command line arguments: backend (currently:
sim,cflib), uri (the robot id, forcflibbackend) - Launches the
crazyflie launch.pylaunch file with the given backend and uri. This initiates:- Motion capture tracking (if
cflibbackend) - Connection to the crazyflie (if
cflibbackend) - Basic simulation engine (if
simbackend)
- Motion capture tracking (if
- Launches the
cf_interface.pynode which:- Subscribes to the relevant crazyflie state topic, converts to standard form (see below) and publishes it to
cf_interface/statetopic. - Subscribes to the
cf_interface/controltopic, converts to crazyflie format and publishes the low-level control commands to the crazyflie - Provides the
cf_interface/commandservice for high-level interface to crazyflie:takeoff,land- Example call:
ros2 service call /cf_interface/command crazyflie_interface/srv/Command "{command: 'takeoff'}"
- Example call:
- Subscribes to the relevant crazyflie state topic, converts to standard form (see below) and publishes it to
State message is as follows: [x, y, z, vx, vy, vz, q_x, q_y, q_z, q_w, wx, wy, wz]
- Linear velocities are in world frame
- Angular velocities are in body frame
Control message is as follows: [roll, pitch, yaw_rate, thrust]
- Roll, pitch are in radians
- Yaw rate is in radians per second
- Thrust is in Newtons per kilogram (same as gravity)
- UCSD SASLab's crazyswarm2 package.
- Tested on ROS2 Humble only.
colcon build --packages-select crazyflie_interfacefromros2_wsdirectory.source install/setup.bashfromros2_wsdirectory.
ros2 launch crazyflie_interface base_controller_launch.py backend:=simfor simulation backend.ros2 service call /cf_interface/command crazyflie_interface/srv/Command "{command: 'takeoff'}"to takeoff.- It will start flying to random position targets.
ros2 service call /cf_interface/command crazyflie_interface/srv/Command "{command: 'land'}"to land.
- Identify drone URI (# under drone)
ros2 launch crazyflie_interface base_controller_launch.py backend:=cflib uri:=urifor hardware backend.ros2 service call /cf_interface/command crazyflie_interface/srv/Command "{command: 'takeoff'}"to takeoff.- It will start flying to random targets
ros2 service call /cf_interface/command crazyflie_interface/srv/Command "{command: 'land'}"to land.
- Add GUI for command service.
- Add
gym_pybullet_dronesinterface for simulation backend. - Provide option for running rviz with
gym_pybullet_drones. - Add time to state message.
- Add calibration as part of command service in
cf_interface.py.