# heartpain-kong/dm02_control architecture

> Architecture diagram of the GitHub repository heartpain-kong/dm02_control, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/heartpain-kong/dm02_control
- Repository: https://github.com/heartpain-kong/dm02_control

## Overview

This is STM32H7 firmware for a motor-control development board, providing drivers for DJI, Unitree, Lingzu and Damiao motors, a DJI remote-control example, and mecanum/steering chassis control. The evidenced startup initializes peripherals and calls control-task initialization; the sampled motor task dispatches motor commands and receives some CAN feedback. The README documents additional capabilities, but their detailed runtime wiring is not shown in the excerpts, so those connections are left out.

Main entry points: [`dm02_motor/User_File/task/motor_task.cpp`](https://github.com/heartpain-kong/dm02_control/blob/main/dm02_motor/User_File/task/motor_task.cpp) (Motor task), [`dm02_motor/User_File/motor/motor_DJ/motor_DJ.cpp`](https://github.com/heartpain-kong/dm02_control/blob/main/dm02_motor/User_File/motor/motor_DJ/motor_DJ.cpp) (DJI motor), [`dm02_motor/User_File/motor/motor_LZ/motor_LZ.cpp`](https://github.com/heartpain-kong/dm02_control/blob/main/dm02_motor/User_File/motor/motor_LZ/motor_LZ.cpp) (Lingzu motor), [`dm02_motor/Core/Src/main.c`](https://github.com/heartpain-kong/dm02_control/blob/main/dm02_motor/Core/Src/main.c) (Firmware startup)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["Control application"]
  node_control["Control task<br/>[control_task.cpp]"]
  node_chassis["Chassis control<br/>[chassis.cpp]"]
  node_pid["PID algorithm<br/>[alg_pid.cpp]"]
  node_slope["Slope algorithm<br/>[alg_slope.cpp]"]
end

subgraph group_motor["Motor control"]
  node_motor_task["Motor task<br/>[motor_task.cpp]"]
  node_dj["DJI motor<br/>[motor_DJ.cpp]"]
  node_lz["Lingzu motor<br/>[motor_LZ.cpp]"]
  node_ys["Unitree motor<br/>[motor_YS.cpp]"]
  node_dm["Damiao motor<br/>[motor_DM.cpp]"]
end

subgraph group_io["Board interfaces"]
  node_remote_driver["Remote parser<br/>[remote_control.cpp]"]
  node_can_bsp["FDCAN interface<br/>[bsp_fdcan.cpp]"]
  node_uart_bsp["UART interface<br/>[UART.cpp]"]
  node_usb["USB CDC<br/>[usb_device.c]"]
end

subgraph group_platform["STM32 platform"]
  node_main["Firmware startup<br/>[main.c]"]
  node_peripherals["Peripheral setup"]
end

node_remote(("DJI remote"))
node_motors{{"Motor hardware"}}

node_main -->|"initializes"| node_peripherals
node_main -->|"initializes"| node_control
node_remote -.->|"sends input"| node_remote_driver
node_motor_task -->|"sets and sends"| node_lz
node_motor_task -->|"sets and sends"| node_dj
node_motor_task -->|"sets and sends"| node_dm
node_motor_task -->|"sets and sends"| node_ys
node_motor_task -->|"routes feedback"| node_dj
node_motor_task -->|"routes feedback"| node_lz
node_dj -->|"motor commands"| node_motors
node_lz -->|"motor commands"| node_motors
node_dm -->|"motor commands"| node_motors
node_ys -->|"motor commands"| node_motors

click node_main "https://github.com/heartpain-kong/dm02_control/blob/main/dm02_motor/Core/Src/main.c"
click node_peripherals "https://github.com/heartpain-kong/dm02_control/tree/main/dm02_motor/Core/Src"
click node_control "https://github.com/heartpain-kong/dm02_control/blob/main/dm02_motor/User_File/task/control_task.cpp"
click node_chassis "https://github.com/heartpain-kong/dm02_control/blob/main/dm02_motor/User_File/algorithm/chassis/chassis.cpp"
click node_pid "https://github.com/heartpain-kong/dm02_control/blob/main/dm02_motor/User_File/algorithm/PID/alg_pid.cpp"
click node_slope "https://github.com/heartpain-kong/dm02_control/blob/main/dm02_motor/User_File/algorithm/Slope/alg_slope.cpp"
click node_remote_driver "https://github.com/heartpain-kong/dm02_control/blob/main/dm02_motor/User_File/Driver/remote_control/remote_control.cpp"
click node_motor_task "https://github.com/heartpain-kong/dm02_control/blob/main/dm02_motor/User_File/task/motor_task.cpp"
click node_dj "https://github.com/heartpain-kong/dm02_control/blob/main/dm02_motor/User_File/motor/motor_DJ/motor_DJ.cpp"
click node_lz "https://github.com/heartpain-kong/dm02_control/blob/main/dm02_motor/User_File/motor/motor_LZ/motor_LZ.cpp"
click node_ys "https://github.com/heartpain-kong/dm02_control/blob/main/dm02_motor/User_File/motor/motor_YS/motor_YS.cpp"
click node_dm "https://github.com/heartpain-kong/dm02_control/blob/main/dm02_motor/User_File/motor/motor_DM/motor_DM.cpp"
click node_can_bsp "https://github.com/heartpain-kong/dm02_control/blob/main/dm02_motor/User_File/BSP/CAN/bsp_fdcan.cpp"
click node_uart_bsp "https://github.com/heartpain-kong/dm02_control/blob/main/dm02_motor/User_File/BSP/UART/UART.cpp"
click node_usb "https://github.com/heartpain-kong/dm02_control/blob/main/dm02_motor/USB_DEVICE/App/usb_device.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_control,node_chassis,node_pid,node_slope toneBlue
class node_motor_task,node_dj,node_lz,node_ys,node_dm toneAmber
class node_remote_driver,node_can_bsp,node_uart_bsp,node_usb toneMint
class node_main,node_peripherals toneRose
class node_remote,node_motors toneIndigo
```

## Components

### Control application

- [Control task](https://github.com/heartpain-kong/dm02_control/blob/main/dm02_motor/User_File/task/control_task.cpp): `dm02_motor/User_File/task/control_task.cpp`
- [Chassis control](https://github.com/heartpain-kong/dm02_control/blob/main/dm02_motor/User_File/algorithm/chassis/chassis.cpp): `dm02_motor/User_File/algorithm/chassis/chassis.cpp`
- [PID algorithm](https://github.com/heartpain-kong/dm02_control/blob/main/dm02_motor/User_File/algorithm/PID/alg_pid.cpp): `dm02_motor/User_File/algorithm/PID/alg_pid.cpp`
- [Slope algorithm](https://github.com/heartpain-kong/dm02_control/blob/main/dm02_motor/User_File/algorithm/Slope/alg_slope.cpp): `dm02_motor/User_File/algorithm/Slope/alg_slope.cpp`

### Motor control

- [Motor task](https://github.com/heartpain-kong/dm02_control/blob/main/dm02_motor/User_File/task/motor_task.cpp): `dm02_motor/User_File/task/motor_task.cpp`
- [DJI motor](https://github.com/heartpain-kong/dm02_control/blob/main/dm02_motor/User_File/motor/motor_DJ/motor_DJ.cpp): `dm02_motor/User_File/motor/motor_DJ/motor_DJ.cpp`
- [Lingzu motor](https://github.com/heartpain-kong/dm02_control/blob/main/dm02_motor/User_File/motor/motor_LZ/motor_LZ.cpp): `dm02_motor/User_File/motor/motor_LZ/motor_LZ.cpp`
- [Unitree motor](https://github.com/heartpain-kong/dm02_control/blob/main/dm02_motor/User_File/motor/motor_YS/motor_YS.cpp): `dm02_motor/User_File/motor/motor_YS/motor_YS.cpp`
- [Damiao motor](https://github.com/heartpain-kong/dm02_control/blob/main/dm02_motor/User_File/motor/motor_DM/motor_DM.cpp): `dm02_motor/User_File/motor/motor_DM/motor_DM.cpp`

### Board interfaces

- [Remote parser](https://github.com/heartpain-kong/dm02_control/blob/main/dm02_motor/User_File/Driver/remote_control/remote_control.cpp): `dm02_motor/User_File/Driver/remote_control/remote_control.cpp`
- [FDCAN interface](https://github.com/heartpain-kong/dm02_control/blob/main/dm02_motor/User_File/BSP/CAN/bsp_fdcan.cpp): `dm02_motor/User_File/BSP/CAN/bsp_fdcan.cpp`
- [UART interface](https://github.com/heartpain-kong/dm02_control/blob/main/dm02_motor/User_File/BSP/UART/UART.cpp): `dm02_motor/User_File/BSP/UART/UART.cpp`
- [USB CDC](https://github.com/heartpain-kong/dm02_control/blob/main/dm02_motor/USB_DEVICE/App/usb_device.c): `dm02_motor/USB_DEVICE/App/usb_device.c`

### STM32 platform

- [Firmware startup](https://github.com/heartpain-kong/dm02_control/blob/main/dm02_motor/Core/Src/main.c): `dm02_motor/Core/Src/main.c`
- [Peripheral setup](https://github.com/heartpain-kong/dm02_control/tree/main/dm02_motor/Core/Src): `dm02_motor/Core/Src`

### Other components

- **DJI remote**
- **Motor hardware**

## Connections

- Firmware startup → Peripheral setup: initializes
- Firmware startup → Control task: initializes
- DJI remote → Remote parser: sends input
- Motor task → Lingzu motor: sets and sends
- Motor task → DJI motor: sets and sends
- Motor task → Damiao motor: sets and sends
- Motor task → Unitree motor: sets and sends
- Motor task → DJI motor: routes feedback
- Motor task → Lingzu motor: routes feedback
- DJI motor → Motor hardware: motor commands
- Lingzu motor → Motor hardware: motor commands
- Damiao motor → Motor hardware: motor commands
- Unitree motor → Motor hardware: motor commands
