Crazyflie firmware(2)-Commander Framework
The Commander module
具体在crazyflie firmware的代码参考src/modules/src/commander.c。Crazyflie无人机的setpoints可以
- set directly
- set by a python script using 电脑端的cflib/ cfclientor 手机端的app layer(下图中的蓝色blue pathways)
- set by the high-level commander module (下图中的紫色pathway)
上图中可以发现,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;
有2层需要去控制,即
- Position(X,Y,Z)
- Attitude(pitch, roll, yaw or in quaternions)
它们可以通过不同的模式进行控制,即
- Absolute mode (modeAbs)
- Velocity mode (modeVelocity)
- Disabled (modeDisable)
如果需要absolute position control(setpoint.mode.xyz =modeAbs, 例如要求go to point x=1,y=0,z=1),那么控制器就要控制在setpoint.position.xyz给出的值。如果你想要控制速度(setpoint.mode.xyz=modeVel, 例如要求x轴速度为0.5 m/s),那么控制器就要控制在setpoint.velocity.xyz给出的值。以上的情况,attitude setpoint modes will be set then to disabled (modeDisabled)。
如果只是想要控制姿态角(attitude),而不需要控制translational位置或者速度,那么setpoint.mode.xyz=modeDisabled。
typedef enum mode_e {
modeDisable = 0,
modeAbs,
modeVelocity
} stab_mode_t;
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 autonomousSequence.py example for instance.
- Use the MotionCommander class, as in motion_commander_demo.py. 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 autonomous_sequence_high_level.py.
- Use the PositionHlCommander class for a simplified API to send commands to the high level commander, see the position_commander_demo.py