stateDiagram-v2
    direction LR

    init: 初始化
    app_loaded: 内置APP模式(通过SDK load_app接口选择要加载的APP)
    ext_ctrl: 外部控制模式(通过SDK switch_mode切换控制模式)

    self_check: 自检中
    calibration_needed: 需要零点标定
    offline_idle: 自检完毕,USB未连接
    offline_connected: USB已连接,等待控制服务
    state self_check_result <>
    failure: 初始化失败

    state init {
      direction LR
      self_check --> self_check_result: 自检完成
      self_check_result --> calibration_needed: 完成自检,需标定
      self_check_result --> offline_idle: 自检通过
      self_check_result --> failure: 不可恢复错误
      calibration_needed --> offline_idle: 标定完成
    }

    [*] --> self_check: 上电
    offline_idle --> offline_connected: USB连接
    offline_connected --> ext_ctrl: 控制服务启动
    ext_ctrl --> app_loaded: 底座按键 [长按]
    app_loaded --> ext_ctrl: SDK调用 [unload_app]
    app_loaded --> ext_ctrl: 底座按键 [长按]
    ext_ctrl --> app_loaded: SDK调用 [load_app]


    classDef cyan fill:#00FFFF,stroke:#007F7F,stroke-width:2px,color:#000;
    classDef blue fill:#7F7FFF,stroke:#3F3F7F,stroke-width:2px,color:#000;
    classDef red fill:#FF7F7F,stroke:#7F3F3F,stroke-width:2px,color:#000;
    classDef purple fill:#FF7FFF,stroke:#7F3F7F,stroke-width:2px,color:#000;
    classDef green fill:#7FFF7F,stroke:#3F7F3F,stroke-width:2px,color:#000;
    classDef yellow fill:#FFFF3F,stroke:#7F7F3F,stroke-width:2px,color:#000;
    classDef light_grey fill:#BBBBBB,stroke:#777777,stroke-width:2px,color:#000;

    class idle cyan
    class idle breathing
    class drag blue
    class recording blue
    class recording flowing
    class replay_waiting purple
    class replay_waiting flashing
    class replay_ready purple
    class replaying purple
    class replaying breathing
    class replay_paused purple
    class replay_paused flashing

    class planning_pos green
    class servo_pos_joint green
    class servo_pos_cart green
    class servo_vel_joint green
    class servo_vel_cart green
    class gravity_comp green

    class self_check yellow
    class calibration_needed yellow
    class calibration_needed flashing
    class offline_idle light_grey
    class offline_connected light_grey
    class offline_connected breathing
    class failure red