From aec50ffb35736efd0a39c5977b7fdb00c3e2c98d Mon Sep 17 00:00:00 2001 From: gitee-bot Date: Mon, 23 Mar 2026 02:21:42 +0000 Subject: [PATCH] Add README.md --- README.en.md | 114 +++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 118 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 232 insertions(+) create mode 100644 README.en.md create mode 100644 README.md diff --git a/README.en.md b/README.en.md new file mode 100644 index 0000000..68655ce --- /dev/null +++ b/README.en.md @@ -0,0 +1,114 @@ +# Peripheral Driver Library (WaiSheQuDong) + +## Project Overview + +This project is an embedded peripheral driver library, primarily containing the **SEGGER RTT** debugging communication component and a **PID controller** implementation. It is suitable for debugging output and motor control applications in embedded real-time systems. + +## Directory Structure + +``` +├── SEGGER_RTT/ # SEGGER RTT Debugging Communication Component +│ ├── SEGGER_RTT.c # RTT Core Implementation +│ ├── SEGGER_RTT.h # RTT Header File +│ ├── SEGGER_RTT_Conf.c # RTT Configuration and _printf Implementation +│ ├── SEGGER_RTT_Conf.h # RTT Configuration Header +│ ├── log.c # Logging Function Implementation +│ └── log.h # Logging Function Header +│ +└── pid/ # PID Controller Module + ├── pid.c # PID Control Implementation + └── pid.h # PID Header File +``` + +## Module Description + +### 1. SEGGER RTT Debugging Component + +SEGGER RTT (Real Time Transfer) is an efficient debugging communication solution that allows the target MCU to send data to the debugger at runtime without impacting real-time performance. + +**Main Functions:** +- `SEGGER_RTT_Init` - Initialize RTT +- `SEGGER_RTT_Write` / `SEGGER_RTT_WriteNoLock` - Write data +- `SEGGER_RTT_Read` - Read data +- `SEGGER_RTT_printf` - Formatted output +- `SEGGER_RTT_PutChar` - Single character output +- `SEGGER_RTT_HasKey` / `SEGGER_RTT_GetKey` - Keyboard input detection +- `SEGGER_RTT_SetTerminal` - Terminal switching + +**Features:** +- Bidirectional communication (uplink/downlink buffers) +- Blocking and non-blocking write modes +- Support for multiple buffers +- Zero-copy operations + +### 2. PID Controller + +Implements multiple PID controllers for motor control: + +- **PID_current_q** - q-axis current PID +- **PID_current_d** - d-axis current PID +- **PID_velocity** - Velocity PID +- **PID_angle** - Angle PID +- **PID_power** - Power PID + +**Main Functions:** +- `PID_init` - Initialize all PID controllers +- `PIDoperator` - Perform PID calculation; input error value, output control signal + +## Usage Instructions + +### SEGGER RTT Usage + +```c +// Initialize +SEGGER_RTT_Init(); + +// String output +SEGGER_RTT_Write(0, "Hello World\r\n", 13); + +// Formatted output +SEGGER_RTT_printf(0, "Value: %d\r\n", 100); + +// Single character output +SEGGER_RTT_PutChar(0, 'A'); +``` + +### PID Controller Usage + +```c +// Initialize PID parameters +PID_init(); + +// Calculate PID output +float error = target - current; +float output = PIDoperator(&PID_velocity, error); +``` + +## Configuration Details + +### RTT Buffer Configuration + +In `SEGGER_RTT_Conf.h`, you can configure: +- Buffer sizes +- Number of terminals +- Output modes (left-aligned, zero-padded, sign printing, etc.) + +### PID Parameter Configuration + +PID controller parameters are defined in `pid/pid.c`: +- `kp` - Proportional gain +- `ki` - Integral gain +- `kd` - Derivative gain +- `outLimit` - Output limit +- `ErrintegralLimit` - Integral windup limit + +## License + +The SEGGER RTT code included in this project is subject to the SEGGER license terms. + +## Application Scenarios + +- Motor drive control (FOC vector control) +- UAV flight control +- Robotic joint control +- Embedded real-time system debugging \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..208ad80 --- /dev/null +++ b/README.md @@ -0,0 +1,118 @@ + + +Based on the provided code map, I can see this is a motor control project using SEGGER RTT for debugging/logging and PID controllers. Let me create a comprehensive README for this project. + +# 外设驱动库 (WaiSheQuDong) + +## 项目简介 + +本项目是一个嵌入式外设驱动库,主要包含 **SEGGER RTT** 调试通信组件和 **PID 控制器** 实现。适用于嵌入式实时系统的调试输出和电机控制应用场景。 + +## 目录结构 + +``` +├── SEGGER_RTT/ # SEGGER RTT 调试通信组件 +│ ├── SEGGER_RTT.c # RTT 核心实现 +│ ├── SEGGER_RTT.h # RTT 头文件 +│ ├── SEGGER_RTT_Conf.c # RTT 配置与_printf实现 +│ ├── SEGGER_RTT_Conf.h # RTT 配置头文件 +│ ├── log.c # 日志功能实现 +│ └── log.h # 日志功能头文件 +│ +└── pid/ # PID 控制器模块 + ├── pid.c # PID 控制实现 + └── pid.h # PID 头文件 +``` + +## 模块说明 + +### 1. SEGGER RTT 调试组件 + +SEGGER RTT (Real Time Transfer) 是一种高效的调试通信方案,允许目标MCU在运行时向调试器发送数据,而不影响实时性能。 + +**主要功能:** +- `SEGGER_RTT_Init` - 初始化 RTT +- `SEGGER_RTT_Write` / `SEGGER_RTT_WriteNoLock` - 写入数据 +- `SEGGER_RTT_Read` - 读取数据 +- `SEGGER_RTT_printf` - 格式化输出 +- `SEGGER_RTT_PutChar` - 单字符输出 +- `SEGGER_RTT_HasKey` / `SEGGER_RTT_GetKey` - 键盘输入检测 +- `SEGGER_RTT_SetTerminal` - 终端切换 + +**特性:** +- 双向通信(上行/下行缓冲区) +- 阻塞与非阻塞写入模式 +- 支持多个缓冲区 +- 零拷贝操作 + +### 2. PID 控制器 + +实现多个 PID 控制器,用于电机控制: + +- **PID_current_q** - q轴电流PID +- **PID_current_d** - d轴电流PID +- **PID_velocity** - 速度PID +- **PID_angle** - 角度PID +- **PID_power** - 功率PID + +**主要函数:** +- `PID_init` - 初始化所有PID控制器 +- `PIDoperator` - PID运算,输入误差值,输出控制量 + +## 使用说明 + +### SEGGER RTT 使用 + +```c +// 初始化 +SEGGER_RTT_Init(); + +// 字符串输出 +SEGGER_RTT_Write(0, "Hello World\r\n", 13); + +// 格式化输出 +SEGGER_RTT_printf(0, "Value: %d\r\n", 100); + +// 单字符输出 +SEGGER_RTT_PutChar(0, 'A'); +``` + +### PID 控制器使用 + +```c +// 初始化PID参数 +PID_init(); + +// 计算PID输出 +float error = target - current; +float output = PIDoperator(&PID_velocity, error); +``` + +## 配置说明 + +### RTT 缓冲区配置 + +在 `SEGGER_RTT_Conf.h` 中可以配置: +- 缓冲区大小 +- 终端数量 +- 输出模式(左对齐、零填充、符号打印等) + +### PID 参数配置 + +PID 控制器参数在 `pid/pid.c` 中定义: +- `kp` - 比例系数 +- `ki` - 积分系数 +- `kd` - 微分系数 +- `outLimit` - 输出限制 +- `ErrintegralLimit` - 积分限幅 + +## 许可证 + +本项目包含的 SEGGER RTT 代码遵循 SEGGER 许可证条款。 + +## 适用场景 + +- 电机驱动控制(FOC矢量控制) +- 无人机飞控 +- 机器人关节控制 +- 嵌入式实时系统调试 \ No newline at end of file -- Gitee