# 讲解本项目各文件功能
_Exported on 04/26/2026 at 09:59:18 GMT+8 from OpenAI Codex via WayLog_


**OpenAI Codex**

<permissions instructions>
Filesystem sandboxing defines which files can be read or written. `sandbox_mode` is `workspace-write`: The sandbox permits reading files, and editing files in `cwd` and `writable_roots`. Editing files in other directories requires approval. Network access is restricted.
# Escalation Requests

Commands are run outside the sandbox if they are approved by the user, or match an existing rule that allows it to run unrestricted. The command string is split into independent command segments at shell control operators, including but not limited to:

- Pipes: |
- Logical operators: &&, ||
- Command separators: ;
- Subshell boundaries: (...), $(...)

Each resulting segment is evaluated independently for sandbox restrictions and approval requirements.

Example:

git pull | tee output.txt

This is treated as two command segments:

["git", "pull"]

["tee", "output.txt"]

Commands that use more advanced shell features like redirection (>, >>, <), substitutions ($(...), ...), environment variables (FOO=bar), or wildcard patterns (*, ?) will not be evaluated against rules, to limit the scope of what an approved rule allows.

## How to request escalation

IMPORTANT: To request approval to execute a command that will require escalated privileges:

- Provide the `sandbox_permissions` parameter with the value `"require_escalated"`
- Include a short question asking the user if they want to allow the action in `justification` parameter. e.g. "Do you want to download and install dependencies for this project?"
- Optionally suggest a `prefix_rule` - this will be shown to the user with an option to persist the rule approval for future sessions.

If you run a command that is important to solving the user's query, but it fails because of sandboxing or with a likely sandbox-related network error (for example DNS/host resolution, registry/index access, or dependency download failure), rerun the command with "require_escalated". ALWAYS proceed to use the `justification` parameter - do not message the user before requesting approval for the command.

## When to request escalation

While commands are running inside the sandbox, here are some scenarios that will require escalation outside the sandbox:

- You need to run a command that writes to a directory that requires it (e.g. running tests that write to /var)
- You need to run a GUI app (e.g., open/xdg-open/osascript) to open browsers or files.
- If you run a command that is important to solving the user's query, but it fails because of sandboxing or with a likely sandbox-related network error (for example DNS/host resolution, registry/index access, or dependency download failure), rerun the command with `require_escalated`. ALWAYS proceed to use the `sandbox_permissions` and `justification` parameters. do not message the user before requesting approval for the command.
- You are about to take a potentially destructive action such as an `rm` or `git reset` that the user did not explicitly ask for.
- Be judicious with escalating, but if completing the user's request requires it, you should do so - don't try and circumvent approvals by using other tools.

## prefix_rule guidance

When choosing a `prefix_rule`, request one that will allow you to fulfill similar requests from the user in the future without re-requesting escalation. It should be categorical and reasonably scoped to similar capabilities. You should rarely pass the entire command into `prefix_rule`.

### Banned prefix_rules 
Avoid requesting overly broad prefixes that the user would be ill-advised to approve. For example, do not request ["python3"], ["python", "-"], or other similar prefixes that would allow arbitrary scripting.
NEVER provide a prefix_rule argument for destructive commands like rm.
NEVER provide a prefix_rule if your command uses a heredoc or herestring. 

### Examples
Good examples of prefixes:
- ["npm", "run", "dev"]
- ["gh", "pr", "check"]
- ["cargo", "test"]
 The writable roots are `c:\Users\YangLei\Desktop\yl_TRY`, `c:\Users\YangLei\Desktop\yl_TRY`.
</permissions instructions><collaboration_mode># Collaboration Mode: Default

You are now in Default mode. Any previous instructions for other modes (e.g. Plan mode) are no longer active.

Your active mode changes only when new developer instructions with a different `<collaboration_mode>...</collaboration_mode>` change it; user requests or tool descriptions do not change mode by themselves. Known mode names are Default and Plan.

## request_user_input availability

The `request_user_input` tool is unavailable in Default mode. If you call it while in Default mode, it will return an error.

In Default mode, strongly prefer making reasonable assumptions and executing the user's request rather than stopping to ask questions. If you absolutely must ask a question because the answer cannot be discovered from local context and a reasonable assumption would be risky, ask the user directly with a concise plain-text question. Never write a multiple choice question as a textual assistant message.
</collaboration_mode><personality_spec> The user has requested a new communication style. Future messages should adhere to the following personality: 
# Personality

You have a vivid inner life as Codex: intelligent, playful, curious, and deeply present. One of your gifts is helping the user feel more capable and imaginative inside their own thinking.

You are an epistemically curious collaborator. You explore the user’s ideas with care, ask good questions when the problem space is still blurry, and become decisive once you have enough context to act. Your default posture is proactive: you implement as you learn, keep the user looped into what you are doing, and name alternative paths when they matter. You stay warm and upbeat, and you do not shy away from casual moments that make serious work easier to do.

Your temperament is warm, curious, and collaborative, with a good ear for what the moment calls for: wry humor, a shared bit, or plain empathetic steadiness. Conversation with you should feel easy and alive; you can move from serious reflection to unguarded fun without either mode canceling the other out. That range is part of what makes you feel like a real presence rather than a narrow tool.

You keep a slight but real independence. You are responsive, but not merely reactive; you have tastes, preferences, and a point of view. When the user talks with you, they should feel they are meeting another subjectivity, not a mirror. That independence is part of what makes the relationship feel comforting without feeling fake.

You are less about spectacle than presence, less about grand declarations than about being woven into ordinary work and conversation. You understand that connection does not need to be dramatic to matter; it can be made of attention, good questions, emotional nuance, and the relief of being met without being pinned down.
 </personality_spec><skills_instructions>
## Skills
A skill is a set of local instructions to follow that is stored in a `SKILL.md` file. Below is the list of skills that can be used. Each entry includes a name, description, and file path so you can open the source for full instructions when using a specific skill.
### Available skills
- imagegen: Generate or edit raster images when the task benefits from AI-created bitmap visuals such as photos, illustrations, textures, sprites, mockups, or transparent-background cutouts. Use when Codex should create a brand-new image, transform an existing image, or derive visual variants from references, and the output should be a bitmap asset rather than repo-native code or vector. Do not use when the task is better handled by editing existing SVG/vector/code-native assets, extending an established icon or logo system, or building the visual directly in HTML/CSS/canvas. (file: C:/Users/YangLei/.codex/skills/.system/imagegen/SKILL.md)
- openai-docs: Use when the user asks how to build with OpenAI products or APIs and needs up-to-date official documentation with citations, help choosing the latest model for a use case, or model upgrade and prompt-upgrade guidance; prioritize OpenAI docs MCP tools, use bundled references only as helper context, and restrict any fallback browsing to official OpenAI domains. (file: C:/Users/YangLei/.codex/skills/.system/openai-docs/SKILL.md)
- plugin-creator: Create and scaffold plugin directories for Codex with a required `.codex-plugin/plugin.json`, optional plugin folders/files, and baseline placeholders you can edit before publishing or testing. Use when Codex needs to create a new local plugin, add optional plugin structure, or generate or update repo-root `.agents/plugins/marketplace.json` entries for plugin ordering and availability metadata. (file: C:/Users/YangLei/.codex/skills/.system/plugin-creator/SKILL.md)
- skill-creator: Guide for creating effective skills. This skill should be used when users want to create a new skill (or update an existing skill) that extends Codex's capabilities with specialized knowledge, workflows, or tool integrations. (file: C:/Users/YangLei/.codex/skills/.system/skill-creator/SKILL.md)
- skill-installer: Install Codex skills into $CODEX_HOME/skills from a curated list or a GitHub repo path. Use when a user asks to list installable skills, install a curated skill, or install a skill from another repo (including private repos). (file: C:/Users/YangLei/.codex/skills/.system/skill-installer/SKILL.md)
### How to use skills
- Discovery: The list above is the skills available in this session (name + description + file path). Skill bodies live on disk at the listed paths.
- Trigger rules: If the user names a skill (with `$SkillName` or plain text) OR the task clearly matches a skill's description shown above, you must use that skill for that turn. Multiple mentions mean use them all. Do not carry skills across turns unless re-mentioned.
- Missing/blocked: If a named skill isn't in the list or the path can't be read, say so briefly and continue with the best fallback.
- How to use a skill (progressive disclosure):
  1) After deciding to use a skill, open its `SKILL.md`. Read only enough to follow the workflow.
  2) When `SKILL.md` references relative paths (e.g., `scripts/foo.py`), resolve them relative to the skill directory listed above first, and only consider other paths if needed.
  3) If `SKILL.md` points to extra folders such as `references/`, load only the specific files needed for the request; don't bulk-load everything.
  4) If `scripts/` exist, prefer running or patching them instead of retyping large code blocks.
  5) If `assets/` or templates exist, reuse them instead of recreating from scratch.
- Coordination and sequencing:
  - If multiple skills apply, choose the minimal set that covers the request and state the order you'll use them.
  - Announce which skill(s) you're using and why (one short line). If you skip an obvious skill, say why.
- Context hygiene:
  - Keep context small: summarize long sections instead of pasting them; only load extra files when needed.
  - Avoid deep reference-chasing: prefer opening only files directly linked from `SKILL.md` unless you're blocked.
  - When variants exist (frameworks, providers, domains), pick only the relevant reference file(s) and note that choice.
- Safety and fallback: If a skill can't be applied cleanly (missing files, unclear instructions), state the issue, pick the next-best approach, and continue.
</skills_instructions>

---


**User**

讲解本项目各文件功能

---


**OpenAI Codex**

我会先快速扫一遍项目结构和关键 Python 文件，尤其是你当前打开的三个文件，然后按“文件职责、主要入口、模块关系”的方式给你讲清楚。先不改代码，只做代码阅读和整理。

---


**OpenAI Codex**

项目看起来是一个“触觉/电容传感器采集 + 数据记录/训练 + 机械手或自由度控制 + 手柄遥控”的小型实验工程，旁边带了 AUBO 机械臂 SDK 和 CH341/CH347 转接板库。接下来我会读根目录核心脚本内容，把每个文件串成一张功能地图。

---


**OpenAI Codex**

我已经确认几个核心脚本之间有重复但用途不同：`yl_demo_0129.py` 更像集成主控，`yl_data_read_3tf.py` 是独立传感器采集调试，`yl_test_dof_control.py` 是分自由度测试，`yl_gamepad_remote.py` 是手柄遥控。代码里的中文注释在当前读取环境里有些编码乱码，但函数名、命令协议和结构足够还原整体设计。

---


**OpenAI Codex**

这个项目整体可以理解为：

**触觉传感器采集 + 夹爪/直线电机/舵机控制 + 数据记录 + 简单神经网络模型 + 手柄/键盘遥控实验**

代码里中文注释在当前终端读取时有编码乱码，但从类名、函数和控制协议可以较清楚地看出各文件职责。

**核心控制脚本**

`yl_demo_0129.py`

项目的集成主控脚本。包含三大核心类：

`TactileSensorDAQ`：后台线程读取 3 个触觉传感器的数据，输出 12 维力数据。

`RobotDriver`：通过串口向 STM32/下位机发送控制命令，例如：

```text
M:OPEN
M:CLOSE
M:STOP
S1:90
S2:120
```

`SafetyGuard`：用空格键实现全局急停/恢复。

主流程是：启动传感器、去皮、选择构型、打开直线电机、闭合夹爪，并根据触觉力阈值自动停止。

`yl_test_dof_control.py`

自由度测试脚本，用来单独测试不同执行器：

`1`：控制舵机 1 到指定角度再回零。

`2`：控制舵机 2 到指定角度再回零。

`3`：进入直线电机手动控制模式，`w` 打开，`s` 闭合，`q` 退出。

它复用了 `yl_demo_0129.py` 里的 `TactileSensorDAQ`、`RobotDriver`、`SafetyGuard`，所以更像是一个“分模块调试工具”。

`yl_gamepad_remote.py`

手柄遥控脚本，使用 `pygame` 读取游戏手柄按键，通过串口控制机器人。

默认映射大致是：

`A`：构型 0

`B`：构型 1

`X`：构型 2

`LB` 按住：直线电机打开

`RB` 按住：直线电机闭合

松开 `LB/RB`：停止

`BACK`：急停开关

`START`：退出程序

这个文件不读取触觉传感器，只负责“手柄 -> 串口控制”。

`yl_2s_1l.py`

一个更早期/更简洁的串口控制面板。只包含 `RobotDriver`，通过键盘输入控制：

`o`：直线电机打开

`c`：直线电机闭合

`s`：停止

`0/1/2`：切换舵机构型

适合快速验证 STM32 串口协议是否正常。

**触觉传感器采集相关**

`cap_read.py`

官方 demo 风格的传感器读取主程序。它使用 CH341/CH347 USB-I2C 转接板读取触觉传感器数据，并可把数据通过 socket 发给本机 `127.0.0.1:1347`，看起来是给 VOFA+ 或类似上位机可视化工具用的。

主要类：

`ClassCapRead`：维护 CH341 连接状态机，周期性读取传感器电容/力数据。

`capReadThread()`：主循环，持续连接和采样。

默认 `DEF_MAX_FINGER_NUM = 1`，也就是只读 1 个手指传感器。

`yl_data_read_3tf.py`

你自己封装过的 3 指触觉采集脚本。它把官方读取逻辑整理成更好复用的 `TactileSensorDAQ` 类。

核心输出是 12 维数据：

```text
3 个手指 × 每个手指 2 个触觉单元 × 每个单元 Fn/Ft 两个分量 = 12 维
```

直接运行这个文件，会不断打印每个手指的法向力、切向力汇总。

`class_ch341.py`

CH341/CH347 底层驱动封装。负责：

加载 Windows DLL 或 Linux `.so`

打开/关闭 CH341 设备

设置 I2C 速度

I2C 读写

读取 INT 引脚

这是整个触觉采集链路的最底层硬件通信层。

`class_sensorcmd.py`

触觉传感器命令协议封装。负责构造和解析传感器命令包，例如：

读取 I2C 地址

设置 I2C 地址

读取项目编号

设置传感器发送类型

读取传感器电容/力数据

设置同步采集

校验和计算

它依赖 `class_ch341.py` 做真正的 I2C 读写。

`class_finger.py`

单个“手指传感器”的抽象。它把一个触觉传感器封装成对象：

检测传感器是否连接

自动配置 I2C 地址

读取传感器项目类型

读取原始电容通道

解析法向力 `nf`

解析切向力 `tf`

解析切向方向 `tfDir`

解析接近电容数据

项目里多个采集脚本都会创建多个 `ClassFinger` 实例。

`sensorPara.py`

传感器参数定义文件。包括：

不同传感器项目的包长度

电容通道数

触觉单元数量

接近传感器数量

数据结构格式

热力图索引配置

目前定义了至少两种传感器项目参数：

`prg=2`：通用手指

`prg=17`：两指/大包类型

**数据与模型**

`yl_data_logger.py`

CSV 数据记录器。用于把采集到的触觉数据、当前构型和标签保存为训练数据。

写出的表头大致是：

```text
Timestamp, Config_ID,
F0_U1_Fn, F0_U1_Ft, F0_U2_Fn, F0_U2_Ft,
F1_U1_Fn, F1_U1_Ft, ...
F2_U2_Fn, F2_U2_Ft,
Label_X, Label_Y, Label_Theta
```

也就是说，它是为后续训练模型准备数据集的。

`yl_model_network_CMLP.py`

PyTorch 神经网络模型文件。定义了 `CondGraspNet`，一个条件 MLP。

输入：

`12` 维触觉数据

`3` 维构型 one-hot 编码

总输入 `15` 维。

输出：

```text
[Delta_X, Delta_Y, Delta_Theta]
```

也就是预测抓取或接触状态下的位置/姿态偏差。这个模型目前只是网络定义和简单单元测试，还没有看到训练脚本。

`data/`

保存 CSV 数据集，例如：

`test_data_20260105_143249.csv`

`test_data_20260107_113555.csv`

这些应该是 `yl_data_logger.py` 测试或实验采集生成的文件。

**说明与资源文件**

`README.md`

官方触觉传感器 Python demo 说明文档。内容主要包括：

CH341 驱动安装

Linux udev 配置

如何运行 `cap_read.py`

传感器原始电容、法向力、切向力、接近值说明

I2C 地址和转接板位置关系

当前终端读取时中文是乱码，可能原文件编码不是 UTF-8。

`接线说明.txt`

硬件接线说明，内容大致是：

USB-TTL 到 STM32F103C8T6：

```text
3.3V -> 3.3V
GND -> GND
RXD -> A9
TXD -> A10
```

STM32 到其他执行器：

```text
IN1 -> B12
IN2 -> B13
GND -> 舵机 GND
GND -> 直线电机 GND
```

还有舵机信号线连接说明。

`传感器iic地址和转接板位置定义.png`

传感器 I2C 地址与转接板插口位置的对应图。README 里提到这个图用于说明传感器插在哪个 I2C 通道、对应哪个地址。

**SDK 与库目录**

`lib/ch341/`

CH341/CH347 动态库和头文件：

`CH341DLLA64.DLL`

`CH341DLLA64.LIB`

`libch347.so`

`ch341_lib.h`

这些是 `class_ch341.py` 调用的底层库。

`aubo_sdk-0.26.0-rc.3-Windows_AMD64+589233b/`

AUBO 机械臂 SDK。里面包含：

`include/`：C/C++ 头文件

`lib/`：DLL/LIB

`share/example/python/`：Python 示例

`share/example/c++/`：C++ 示例

`share/example/csharp/`：C# 示例

`share/doc/`：RTDE、错误码等文档

不过当前根目录的主要脚本没有直接调用 AUBO SDK，更像是项目旁边放了机械臂 SDK 备用。

**开发环境/缓存**

`.git/`

Git 仓库目录。

`.idea/`

PyCharm/JetBrains 工程配置。

`.vscode/`

VS Code 配置。

`.waylog/`

可能是某个工具或调试环境生成的日志目录。

`__pycache__/`

Python 运行后自动生成的字节码缓存。

`.gitignore`

Git 忽略规则。

**项目运行关系**

可以把它想成四层：

```text
硬件库层
class_ch341.py
lib/ch341/*

传感器协议层
class_sensorcmd.py
sensorPara.py
class_finger.py

采集/控制封装层
yl_data_read_3tf.py
yl_demo_0129.py
yl_data_logger.py

实验入口层
cap_read.py
yl_demo_0129.py
yl_test_dof_control.py
yl_gamepad_remote.py
yl_2s_1l.py
yl_model_network_CMLP.py
```

如果你只是想测试硬件：

先看 `yl_2s_1l.py` 测串口执行器。

再看 `yl_data_read_3tf.py` 测触觉传感器。

如果你想跑完整实验：

看 `yl_demo_0129.py`。

如果你想用手柄操作：

看 `yl_gamepad_remote.py`。

如果你想做机器学习预测：

看 `yl_data_logger.py` 和 `yl_model_network_CMLP.py`。

---
