Crazyflie firmware(2)-Commander Framework

The Commander module

具体在crazyflie firmware的代码参考src/modules/src/commander.c。Crazyflie无人机的setpoints可以

  1. set directly
  2. set by a python script using 电脑端的cflibcfclientor 手机端的app layer(下图中的蓝色blue pathways)
  3. set by the high-level commander module (下图中的紫色pathway)
General framework of the stabilization structure of the crazyflie with setpoint handling. * This part is takes place on the computer through the CFlib for python, so there is also communication protocol in between. It is left out of this schematics for easier understanding.

上图中可以发现,High-level commander可以can be controlled remotely from the python library(从off-board的手机或者电脑端) or from inside the Crazyflie(从onboard的firmware)。

需要指出的是, the commander module会检查上一次接收到的setpoint是多久以前。如果很长时间(时长有常量COMMANDER_WDT_TIMEOUT_STABILIZE定义在commander.c)没有收到新的setpoint,那么就会把参考姿态角设置为0,以防止飞机失控。如果等了超过COMMANDER_WDT_TIMEOUT_SHUTDOWN的时间,那么a null setpoint就会给出,使得无人机关掉电机并着陆。如果你使用的是high level commander,以上的事情不会发生。

Setpoint structure

setpoint的数据结构是定义在crazyflie firmware上的src/modules/interface/stabilizer_types.h中的变量setpoint_t。

struct {
    stab_mode_t x;
    stab_mode_t y;
    stab_mode_t z;
    stab_mode_t roll;
    stab_mode_t pitch;
    stab_mode_t yaw;
    stab_mode_t quat;
  } mode;
} setpoint_t;


  • Position(X,Y,Z)
  • Attitude(pitch, roll, yaw or in quaternions)


  • Absolute mode (modeAbs)
  • Velocity mode (modeVelocity)
  • Disabled (modeDisable)
Setpoint structures per controller level

如果需要absolute position control( =modeAbs, 例如要求go to point x=1,y=0,z=1),那么控制器就要控制在setpoint.position.xyz给出的值。如果你想要控制速度(, 例如要求x轴速度为0.5 m/s),那么控制器就要控制在setpoint.velocity.xyz给出的值。以上的情况,attitude setpoint modes will be set then to disabled (modeDisabled)。


typedef enum mode_e {
  modeDisable = 0,
} stab_mode_t;

High level commander


Structure of the high level commander

上图中从CFlib给出actions包括“take off”, “go to” or “land”, high-level commander接收到actions的指令后,会generate出7th order polynomials的smooth trajectories。而上图中从planner会给出一组setpoints,同样地,high-level commander会generate出7th order polynomials的smooth trajectories。然后high-level commander一个一个发送给commander。你也可以将自己customized trajectory存到Crazyflie的内存中,具体可以参见Creating trajectories for the High-level Commander with Bezier curves

Support in the python lib (CFLib)

有以下四种方式通过python library来与commander framework进行交互:

  • Send setpoints directly using the Commander class from the Crazyflie object, this can be seen in the example for instance.
  • Use the MotionCommander class, as in The MotionCommander class exposes a simplified API and sends velocity setpoints continuously based on the methods called.
  • Use the high level commander directly using the HighLevelCommander class on the Crazyflie object, see
  • Use the PositionHlCommander class for a simplified API to send commands to the high level commander, see the

Leave a Comment