# sguan-zhouqing/sguanfoc_library architecture

> Architecture diagram of the GitHub repository sguan-zhouqing/sguanfoc_library, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sguan-zhouqing/sguanfoc_library
- Repository: https://github.com/sguan-zhouqing/sguanfoc_library

## Overview

SguanFOC is a pure-C motor-control library for MCU-based brushless-motor field-oriented control. The documented workflow configures a control mode and motor parameters, then application main-loop and interrupt hooks run initialization/communications, high-frequency current/angle/PWM work, and low-frequency status and fault handling. The repository preserves several float/Q31 and sensored/sensorless releases plus a v4 modular redesign. The v3.1.0 algorithm branches are documented in the README; where their internal call wiring was not excerpted, edges are documented or left unasserted.

Main entry points: [`SguanFOC库v3.1.0(无感foc，浮点运算，进阶)/SguanFOC.c`](https://github.com/sguan-zhouqing/sguanfoc_library/blob/main/SguanFOC%E5%BA%93v3.1.0(%E6%97%A0%E6%84%9Ffoc%EF%BC%8C%E6%B5%AE%E7%82%B9%E8%BF%90%E7%AE%97%EF%BC%8C%E8%BF%9B%E9%98%B6)/SguanFOC.c) (FOC Core), [`SguanFOC库v4.0.0(高度自由模块化foc，终阶)/Sguan_Transfer.c`](https://github.com/sguan-zhouqing/sguanfoc_library/blob/main/SguanFOC%E5%BA%93v4.0.0(%E9%AB%98%E5%BA%A6%E8%87%AA%E7%94%B1%E6%A8%A1%E5%9D%97%E5%8C%96foc%EF%BC%8C%E7%BB%88%E9%98%B6)/Sguan_Transfer.c) (Transfer Modules), [`SguanFOC库v3.1.0(无感foc，浮点运算，进阶)/Sguan_printf.c`](https://github.com/sguan-zhouqing/sguanfoc_library/blob/main/SguanFOC%E5%BA%93v3.1.0(%E6%97%A0%E6%84%9Ffoc%EF%BC%8C%E6%B5%AE%E7%82%B9%E8%BF%90%E7%AE%97%EF%BC%8C%E8%BF%9B%E9%98%B6)/Sguan_printf.c) (JustFloat Serial), [`SguanFOC库v3.1.0(无感foc，浮点运算，进阶)/UserData_Parameter.h`](https://github.com/sguan-zhouqing/sguanfoc_library/blob/main/SguanFOC%E5%BA%93v3.1.0(%E6%97%A0%E6%84%9Ffoc%EF%BC%8C%E6%B5%AE%E7%82%B9%E8%BF%90%E7%AE%97%EF%BC%8C%E8%BF%9B%E9%98%B6)/UserData_Parameter.h) (Motor Parameters)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["FOC Runtime"]
  node_v310core["FOC Core<br/>[SguanFOC.c]"]
  node_status["Motor State"]
  node_math["Transforms Math<br/>[Sguan_math.c]"]
  node_q31sensored["Sensored Q31<br/>[SguanFOC.c]"]
  node_q31sensorless["Sensorless Q31<br/>[SguanFOC.c]"]
end

subgraph group_control["Control Algorithms"]
  node_modulation["PWM Modulation<br/>[Sguan_SVPWM.c]"]
  node_controllers["Loop Controllers<br/>[Sguan_PID.c]"]
  node_advancedcontrol["Advanced Control"]
  node_optimize["Motor Optimization<br/>[Sguan_Optimize.c]"]
  node_filter["Signal Filters<br/>[Sguan_Filter.c]"]
end

subgraph group_sensing["Sensing And Estimation"]
  node_hfi["HFI Injection<br/>[Sguan_HFI.c]"]
  node_smo["SMO Observer<br/>[Sguan_SMO.c]"]
  node_nlfo["NLFO Observer<br/>[Sguan_NLFO.c]"]
  node_sensingextras["Hall And Identify"]
end

subgraph group_interfaces["Configuration And Interfaces"]
  node_parameters["Motor Parameters"]
  node_hardwarehooks["Hardware Hooks"]
  node_serial["JustFloat Serial<br/>[Sguan_printf.c]"]
end

subgraph group_modular["Modular v4"]
  node_v4transfer["Transfer Modules<br/>[Sguan_Transfer.c]"]
  node_v4math["Math Services"]
  node_v4status["State Management"]
  node_v4communications["Modbus Transfer"]
  node_v4units["Unit Integration"]
end

node_application(("MCU Application"))

node_application -->|"calls task loops"| node_v310core
node_application -->|"implements hooks"| node_hardwarehooks
node_application -->|"feeds serial data"| node_serial
node_parameters -->|"configures modes"| node_v310core
node_v310core -->|"runs low loop"| node_status
node_v310core -->|"runs current control"| node_controllers
node_v310core -->|"generates PWM"| node_modulation
node_v310core -->|"supports HFI"| node_hfi
node_v310core -->|"supports SMO"| node_smo
node_v310core -->|"supports NLFO"| node_nlfo
node_v310core -->|"supports sensing"| node_sensingextras
node_v310core -->|"supports optimization"| node_optimize
node_v310core -->|"supports advanced control"| node_advancedcontrol
node_v310core -->|"supports filtering"| node_filter
node_v310core -.->|"uses transforms"| node_math
node_v310core -->|"provides serial loop"| node_serial
node_v4units -.->|"integrates modules"| node_v4transfer
node_v4transfer -->|"uses math services"| node_v4math
node_v4status -->|"uses situation unit"| node_v4units
node_v4transfer -->|"uses patch unit"| node_v4units
node_application -.->|"selects release"| node_q31sensored
node_application -.->|"selects release"| node_q31sensorless
node_v4units -.->|"integrates communications"| node_v4communications

click node_v310core "https://github.com/sguan-zhouqing/sguanfoc_library/blob/main/SguanFOC%E5%BA%93v3.1.0(%E6%97%A0%E6%84%9Ffoc%EF%BC%8C%E6%B5%AE%E7%82%B9%E8%BF%90%E7%AE%97%EF%BC%8C%E8%BF%9B%E9%98%B6)/SguanFOC.c"
click node_status "https://github.com/sguan-zhouqing/sguanfoc_library/blob/main/SguanFOC%E5%BA%93v3.1.0(%E6%97%A0%E6%84%9Ffoc%EF%BC%8C%E6%B5%AE%E7%82%B9%E8%BF%90%E7%AE%97%EF%BC%8C%E8%BF%9B%E9%98%B6)/Sguan_MotorStatus.c"
click node_math "https://github.com/sguan-zhouqing/sguanfoc_library/blob/main/SguanFOC%E5%BA%93v3.0.0(%E6%9C%89%E6%84%9Ffoc%EF%BC%8C%E6%B5%AE%E7%82%B9%E8%BF%90%E7%AE%97%EF%BC%8C%E5%88%9D%E9%98%B6)/Sguan_math.c"
click node_modulation "https://github.com/sguan-zhouqing/sguanfoc_library/blob/main/SguanFOC%E5%BA%93v3.1.0(%E6%97%A0%E6%84%9Ffoc%EF%BC%8C%E6%B5%AE%E7%82%B9%E8%BF%90%E7%AE%97%EF%BC%8C%E8%BF%9B%E9%98%B6)/Sguan_SVPWM.c"
click node_controllers "https://github.com/sguan-zhouqing/sguanfoc_library/blob/main/SguanFOC%E5%BA%93v3.1.0(%E6%97%A0%E6%84%9Ffoc%EF%BC%8C%E6%B5%AE%E7%82%B9%E8%BF%90%E7%AE%97%EF%BC%8C%E8%BF%9B%E9%98%B6)/Sguan_PID.c"
click node_advancedcontrol "https://github.com/sguan-zhouqing/sguanfoc_library/tree/main/SguanFOC%E5%BA%93v3.1.0(%E6%97%A0%E6%84%9Ffoc%EF%BC%8C%E6%B5%AE%E7%82%B9%E8%BF%90%E7%AE%97%EF%BC%8C%E8%BF%9B%E9%98%B6)"
click node_hfi "https://github.com/sguan-zhouqing/sguanfoc_library/blob/main/SguanFOC%E5%BA%93v3.1.0(%E6%97%A0%E6%84%9Ffoc%EF%BC%8C%E6%B5%AE%E7%82%B9%E8%BF%90%E7%AE%97%EF%BC%8C%E8%BF%9B%E9%98%B6)/Sguan_HFI.c"
click node_smo "https://github.com/sguan-zhouqing/sguanfoc_library/blob/main/SguanFOC%E5%BA%93v3.1.0(%E6%97%A0%E6%84%9Ffoc%EF%BC%8C%E6%B5%AE%E7%82%B9%E8%BF%90%E7%AE%97%EF%BC%8C%E8%BF%9B%E9%98%B6)/Sguan_SMO.c"
click node_nlfo "https://github.com/sguan-zhouqing/sguanfoc_library/blob/main/SguanFOC%E5%BA%93v3.1.0(%E6%97%A0%E6%84%9Ffoc%EF%BC%8C%E6%B5%AE%E7%82%B9%E8%BF%90%E7%AE%97%EF%BC%8C%E8%BF%9B%E9%98%B6)/Sguan_NLFO.c"
click node_sensingextras "https://github.com/sguan-zhouqing/sguanfoc_library/tree/main/SguanFOC%E5%BA%93v3.1.0(%E6%97%A0%E6%84%9Ffoc%EF%BC%8C%E6%B5%AE%E7%82%B9%E8%BF%90%E7%AE%97%EF%BC%8C%E8%BF%9B%E9%98%B6)"
click node_optimize "https://github.com/sguan-zhouqing/sguanfoc_library/blob/main/SguanFOC%E5%BA%93v3.1.0(%E6%97%A0%E6%84%9Ffoc%EF%BC%8C%E6%B5%AE%E7%82%B9%E8%BF%90%E7%AE%97%EF%BC%8C%E8%BF%9B%E9%98%B6)/Sguan_Optimize.c"
click node_filter "https://github.com/sguan-zhouqing/sguanfoc_library/blob/main/SguanFOC%E5%BA%93v3.1.0(%E6%97%A0%E6%84%9Ffoc%EF%BC%8C%E6%B5%AE%E7%82%B9%E8%BF%90%E7%AE%97%EF%BC%8C%E8%BF%9B%E9%98%B6)/Sguan_Filter.c"
click node_parameters "https://github.com/sguan-zhouqing/sguanfoc_library/blob/main/SguanFOC%E5%BA%93v3.1.0(%E6%97%A0%E6%84%9Ffoc%EF%BC%8C%E6%B5%AE%E7%82%B9%E8%BF%90%E7%AE%97%EF%BC%8C%E8%BF%9B%E9%98%B6)/UserData_Parameter.h"
click node_hardwarehooks "https://github.com/sguan-zhouqing/sguanfoc_library/blob/main/SguanFOC%E5%BA%93v3.1.0(%E6%97%A0%E6%84%9Ffoc%EF%BC%8C%E6%B5%AE%E7%82%B9%E8%BF%90%E7%AE%97%EF%BC%8C%E8%BF%9B%E9%98%B6)/UserData_Function.h"
click node_serial "https://github.com/sguan-zhouqing/sguanfoc_library/blob/main/SguanFOC%E5%BA%93v3.1.0(%E6%97%A0%E6%84%9Ffoc%EF%BC%8C%E6%B5%AE%E7%82%B9%E8%BF%90%E7%AE%97%EF%BC%8C%E8%BF%9B%E9%98%B6)/Sguan_printf.c"
click node_v4transfer "https://github.com/sguan-zhouqing/sguanfoc_library/blob/main/SguanFOC%E5%BA%93v4.0.0(%E9%AB%98%E5%BA%A6%E8%87%AA%E7%94%B1%E6%A8%A1%E5%9D%97%E5%8C%96foc%EF%BC%8C%E7%BB%88%E9%98%B6)/Sguan_Transfer.c"
click node_q31sensored "https://github.com/sguan-zhouqing/sguanfoc_library/blob/main/SguanFOC%E5%BA%93v3.0.1(%E6%9C%89%E6%84%9Ffoc%EF%BC%8CQ31%E5%AE%9A%E7%82%B9%EF%BC%8C%E5%88%9D%E9%98%B6)/SguanFOC.c"
click node_q31sensorless "https://github.com/sguan-zhouqing/sguanfoc_library/blob/main/SguanFOC%E5%BA%93v3.1.1(%E6%97%A0%E6%84%9Ffoc%EF%BC%8CQ31%E5%AE%9A%E7%82%B9%EF%BC%8C%E8%BF%9B%E9%98%B6)/SguanFOC.c"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_v310core,node_status,node_math,node_q31sensored,node_q31sensorless toneBlue
class node_modulation,node_controllers,node_advancedcontrol,node_optimize,node_filter toneAmber
class node_hfi,node_smo,node_nlfo,node_sensingextras toneMint
class node_parameters,node_hardwarehooks,node_serial toneRose
class node_v4transfer,node_v4math,node_v4status,node_v4communications,node_v4units,node_application toneIndigo
```

## Components

### FOC Runtime

- [FOC Core](https://github.com/sguan-zhouqing/sguanfoc_library/blob/main/SguanFOC%E5%BA%93v3.1.0(%E6%97%A0%E6%84%9Ffoc%EF%BC%8C%E6%B5%AE%E7%82%B9%E8%BF%90%E7%AE%97%EF%BC%8C%E8%BF%9B%E9%98%B6)/SguanFOC.c): `SguanFOC库v3.1.0(无感foc，浮点运算，进阶)/SguanFOC.c`
- [Motor State](https://github.com/sguan-zhouqing/sguanfoc_library/blob/main/SguanFOC%E5%BA%93v3.1.0(%E6%97%A0%E6%84%9Ffoc%EF%BC%8C%E6%B5%AE%E7%82%B9%E8%BF%90%E7%AE%97%EF%BC%8C%E8%BF%9B%E9%98%B6)/Sguan_MotorStatus.c): `SguanFOC库v3.1.0(无感foc，浮点运算，进阶)/Sguan_MotorStatus.c`
- [Transforms Math](https://github.com/sguan-zhouqing/sguanfoc_library/blob/main/SguanFOC%E5%BA%93v3.0.0(%E6%9C%89%E6%84%9Ffoc%EF%BC%8C%E6%B5%AE%E7%82%B9%E8%BF%90%E7%AE%97%EF%BC%8C%E5%88%9D%E9%98%B6)/Sguan_math.c): `SguanFOC库v3.0.0(有感foc，浮点运算，初阶)/Sguan_math.c`
- [Sensored Q31](https://github.com/sguan-zhouqing/sguanfoc_library/blob/main/SguanFOC%E5%BA%93v3.0.1(%E6%9C%89%E6%84%9Ffoc%EF%BC%8CQ31%E5%AE%9A%E7%82%B9%EF%BC%8C%E5%88%9D%E9%98%B6)/SguanFOC.c): `SguanFOC库v3.0.1(有感foc，Q31定点，初阶)/SguanFOC.c`
- [Sensorless Q31](https://github.com/sguan-zhouqing/sguanfoc_library/blob/main/SguanFOC%E5%BA%93v3.1.1(%E6%97%A0%E6%84%9Ffoc%EF%BC%8CQ31%E5%AE%9A%E7%82%B9%EF%BC%8C%E8%BF%9B%E9%98%B6)/SguanFOC.c): `SguanFOC库v3.1.1(无感foc，Q31定点，进阶)/SguanFOC.c`

### Control Algorithms

- [PWM Modulation](https://github.com/sguan-zhouqing/sguanfoc_library/blob/main/SguanFOC%E5%BA%93v3.1.0(%E6%97%A0%E6%84%9Ffoc%EF%BC%8C%E6%B5%AE%E7%82%B9%E8%BF%90%E7%AE%97%EF%BC%8C%E8%BF%9B%E9%98%B6)/Sguan_SVPWM.c): `SguanFOC库v3.1.0(无感foc，浮点运算，进阶)/Sguan_SVPWM.c`
- [Loop Controllers](https://github.com/sguan-zhouqing/sguanfoc_library/blob/main/SguanFOC%E5%BA%93v3.1.0(%E6%97%A0%E6%84%9Ffoc%EF%BC%8C%E6%B5%AE%E7%82%B9%E8%BF%90%E7%AE%97%EF%BC%8C%E8%BF%9B%E9%98%B6)/Sguan_PID.c): `SguanFOC库v3.1.0(无感foc，浮点运算，进阶)/Sguan_PID.c`
- [Advanced Control](https://github.com/sguan-zhouqing/sguanfoc_library/tree/main/SguanFOC%E5%BA%93v3.1.0(%E6%97%A0%E6%84%9Ffoc%EF%BC%8C%E6%B5%AE%E7%82%B9%E8%BF%90%E7%AE%97%EF%BC%8C%E8%BF%9B%E9%98%B6)): `SguanFOC库v3.1.0(无感foc，浮点运算，进阶)`
- [Motor Optimization](https://github.com/sguan-zhouqing/sguanfoc_library/blob/main/SguanFOC%E5%BA%93v3.1.0(%E6%97%A0%E6%84%9Ffoc%EF%BC%8C%E6%B5%AE%E7%82%B9%E8%BF%90%E7%AE%97%EF%BC%8C%E8%BF%9B%E9%98%B6)/Sguan_Optimize.c): `SguanFOC库v3.1.0(无感foc，浮点运算，进阶)/Sguan_Optimize.c`
- [Signal Filters](https://github.com/sguan-zhouqing/sguanfoc_library/blob/main/SguanFOC%E5%BA%93v3.1.0(%E6%97%A0%E6%84%9Ffoc%EF%BC%8C%E6%B5%AE%E7%82%B9%E8%BF%90%E7%AE%97%EF%BC%8C%E8%BF%9B%E9%98%B6)/Sguan_Filter.c): `SguanFOC库v3.1.0(无感foc，浮点运算，进阶)/Sguan_Filter.c`

### Sensing And Estimation

- [HFI Injection](https://github.com/sguan-zhouqing/sguanfoc_library/blob/main/SguanFOC%E5%BA%93v3.1.0(%E6%97%A0%E6%84%9Ffoc%EF%BC%8C%E6%B5%AE%E7%82%B9%E8%BF%90%E7%AE%97%EF%BC%8C%E8%BF%9B%E9%98%B6)/Sguan_HFI.c): `SguanFOC库v3.1.0(无感foc，浮点运算，进阶)/Sguan_HFI.c`
- [SMO Observer](https://github.com/sguan-zhouqing/sguanfoc_library/blob/main/SguanFOC%E5%BA%93v3.1.0(%E6%97%A0%E6%84%9Ffoc%EF%BC%8C%E6%B5%AE%E7%82%B9%E8%BF%90%E7%AE%97%EF%BC%8C%E8%BF%9B%E9%98%B6)/Sguan_SMO.c): `SguanFOC库v3.1.0(无感foc，浮点运算，进阶)/Sguan_SMO.c`
- [NLFO Observer](https://github.com/sguan-zhouqing/sguanfoc_library/blob/main/SguanFOC%E5%BA%93v3.1.0(%E6%97%A0%E6%84%9Ffoc%EF%BC%8C%E6%B5%AE%E7%82%B9%E8%BF%90%E7%AE%97%EF%BC%8C%E8%BF%9B%E9%98%B6)/Sguan_NLFO.c): `SguanFOC库v3.1.0(无感foc，浮点运算，进阶)/Sguan_NLFO.c`
- [Hall And Identify](https://github.com/sguan-zhouqing/sguanfoc_library/tree/main/SguanFOC%E5%BA%93v3.1.0(%E6%97%A0%E6%84%9Ffoc%EF%BC%8C%E6%B5%AE%E7%82%B9%E8%BF%90%E7%AE%97%EF%BC%8C%E8%BF%9B%E9%98%B6)): `SguanFOC库v3.1.0(无感foc，浮点运算，进阶)`

### Configuration And Interfaces

- [Motor Parameters](https://github.com/sguan-zhouqing/sguanfoc_library/blob/main/SguanFOC%E5%BA%93v3.1.0(%E6%97%A0%E6%84%9Ffoc%EF%BC%8C%E6%B5%AE%E7%82%B9%E8%BF%90%E7%AE%97%EF%BC%8C%E8%BF%9B%E9%98%B6)/UserData_Parameter.h): `SguanFOC库v3.1.0(无感foc，浮点运算，进阶)/UserData_Parameter.h`
- [Hardware Hooks](https://github.com/sguan-zhouqing/sguanfoc_library/blob/main/SguanFOC%E5%BA%93v3.1.0(%E6%97%A0%E6%84%9Ffoc%EF%BC%8C%E6%B5%AE%E7%82%B9%E8%BF%90%E7%AE%97%EF%BC%8C%E8%BF%9B%E9%98%B6)/UserData_Function.h): `SguanFOC库v3.1.0(无感foc，浮点运算，进阶)/UserData_Function.h`
- [JustFloat Serial](https://github.com/sguan-zhouqing/sguanfoc_library/blob/main/SguanFOC%E5%BA%93v3.1.0(%E6%97%A0%E6%84%9Ffoc%EF%BC%8C%E6%B5%AE%E7%82%B9%E8%BF%90%E7%AE%97%EF%BC%8C%E8%BF%9B%E9%98%B6)/Sguan_printf.c): `SguanFOC库v3.1.0(无感foc，浮点运算，进阶)/Sguan_printf.c`

### Modular v4

- [Transfer Modules](https://github.com/sguan-zhouqing/sguanfoc_library/blob/main/SguanFOC%E5%BA%93v4.0.0(%E9%AB%98%E5%BA%A6%E8%87%AA%E7%94%B1%E6%A8%A1%E5%9D%97%E5%8C%96foc%EF%BC%8C%E7%BB%88%E9%98%B6)/Sguan_Transfer.c): `SguanFOC库v4.0.0(高度自由模块化foc，终阶)/Sguan_Transfer.c`
- **Math Services**
- **State Management**
- **Modbus Transfer**
- **Unit Integration**

### Other components

- **MCU Application**

## Connections

- MCU Application → FOC Core: calls task loops
- MCU Application → Hardware Hooks: implements hooks
- MCU Application → JustFloat Serial: feeds serial data
- Motor Parameters → FOC Core: configures modes (evidence: `SguanFOC库v3.1.0(无感foc，浮点运算，进阶)/SguanFOC.c`)
- FOC Core → Motor State: runs low loop
- FOC Core → Loop Controllers: runs current control
- FOC Core → PWM Modulation: generates PWM
- FOC Core → HFI Injection: supports HFI
- FOC Core → SMO Observer: supports SMO
- FOC Core → NLFO Observer: supports NLFO
- FOC Core → Hall And Identify: supports sensing (evidence: `SguanFOC库v3.1.0(无感foc，浮点运算，进阶)/SguanFOC.c`)
- FOC Core → Motor Optimization: supports optimization
- FOC Core → Advanced Control: supports advanced control (evidence: `SguanFOC库v3.1.0(无感foc，浮点运算，进阶)/SguanFOC.c`)
- FOC Core → Signal Filters: supports filtering
- FOC Core → Transforms Math: uses transforms
- FOC Core → JustFloat Serial: provides serial loop
- Unit Integration → Transfer Modules: integrates modules
- Transfer Modules → Math Services: uses math services (evidence: `SguanFOC库v4.0.0(高度自由模块化foc，终阶)/Sguan_Transfer.c`)
- State Management → Unit Integration: uses situation unit
- Transfer Modules → Unit Integration: uses patch unit
- MCU Application → Sensored Q31: selects release
- MCU Application → Sensorless Q31: selects release
- Unit Integration → Modbus Transfer: integrates communications
