chore(build): unify scripts and add build/install entrypoint
Add a Debug-default build script with Release and RelWithDebInfo support and automatic output installation. Run bundled protobuf tools without requiring a prior install. Consolidate scripts/, remove unused tools and meshes, and update documentation and test commands. Include the TCHL profile-position test target adjustment to 3 rad.
This commit is contained in:
parent
b93e482b6a
commit
08d9a393be
@ -67,7 +67,7 @@ find_package(protobuf REQUIRED)
|
|||||||
find_package(gRPC REQUIRED)
|
find_package(gRPC REQUIRED)
|
||||||
|
|
||||||
############################################################
|
############################################################
|
||||||
# PROTO , 遇到proto 的生成问题,现在build 目录执行 cmake --install . --verbose ,然后编译即可
|
# PROTO
|
||||||
############################################################
|
############################################################
|
||||||
|
|
||||||
set(PROTO_IMPORT_DIR ${PROJECT_SOURCE_DIR}/protos)
|
set(PROTO_IMPORT_DIR ${PROJECT_SOURCE_DIR}/protos)
|
||||||
@ -76,9 +76,10 @@ file(MAKE_DIRECTORY ${PROTO_BINARY_DIR})
|
|||||||
file(GLOB_RECURSE PROTO_FILES ${PROTO_IMPORT_DIR}/*.proto)
|
file(GLOB_RECURSE PROTO_FILES ${PROTO_IMPORT_DIR}/*.proto)
|
||||||
|
|
||||||
|
|
||||||
set(Protobuf_PROTOC_EXECUTABLE "${CMAKE_INSTALL_PREFIX}/bin/protoc" CACHE FILEPATH "" FORCE)
|
# Run bundled tools with their libraries, without requiring output/bin first.
|
||||||
set_property(TARGET gRPC::grpc_cpp_plugin
|
set(PROTOC_COMMAND_OPTIONS -E env
|
||||||
PROPERTY IMPORTED_LOCATION "${CMAKE_INSTALL_PREFIX}/bin/grpc_cpp_plugin"
|
"LD_LIBRARY_PATH=$<TARGET_FILE_DIR:protobuf::libprotobuf>"
|
||||||
|
"$<TARGET_FILE:protobuf::protoc>"
|
||||||
)
|
)
|
||||||
|
|
||||||
# 1) 先做 OBJECT:只负责生成/编译 pb.cc
|
# 1) 先做 OBJECT:只负责生成/编译 pb.cc
|
||||||
@ -88,12 +89,16 @@ set_target_properties(proto-objects PROPERTIES POSITION_INDEPENDENT_CODE ON)
|
|||||||
|
|
||||||
protobuf_generate(
|
protobuf_generate(
|
||||||
TARGET proto-objects
|
TARGET proto-objects
|
||||||
|
PROTOC_EXE "${CMAKE_COMMAND}"
|
||||||
|
PROTOC_OPTIONS ${PROTOC_COMMAND_OPTIONS}
|
||||||
IMPORT_DIRS ${PROTO_IMPORT_DIR}
|
IMPORT_DIRS ${PROTO_IMPORT_DIR}
|
||||||
PROTOC_OUT_DIR ${PROTO_BINARY_DIR}
|
PROTOC_OUT_DIR ${PROTO_BINARY_DIR}
|
||||||
USAGE_REQUIREMENT PRIVATE
|
USAGE_REQUIREMENT PRIVATE
|
||||||
)
|
)
|
||||||
protobuf_generate(
|
protobuf_generate(
|
||||||
TARGET proto-objects
|
TARGET proto-objects
|
||||||
|
PROTOC_EXE "${CMAKE_COMMAND}"
|
||||||
|
PROTOC_OPTIONS ${PROTOC_COMMAND_OPTIONS}
|
||||||
LANGUAGE grpc
|
LANGUAGE grpc
|
||||||
GENERATE_EXTENSIONS .grpc.pb.h .grpc.pb.cc
|
GENERATE_EXTENSIONS .grpc.pb.h .grpc.pb.cc
|
||||||
PLUGIN "protoc-gen-grpc=$<TARGET_FILE:gRPC::grpc_cpp_plugin>"
|
PLUGIN "protoc-gen-grpc=$<TARGET_FILE:gRPC::grpc_cpp_plugin>"
|
||||||
|
|||||||
35
README.md
35
README.md
@ -149,7 +149,7 @@ objdump -d "/lib/modules/$(uname -r)/ethercat/master/ec_master.ko" \
|
|||||||
启动 EtherCAT。`eno1` 换成实际连接 EtherCAT 从站的网卡:
|
启动 EtherCAT。`eno1` 换成实际连接 EtherCAT 从站的网卡:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
sudo script/ethercat/start_ethercat.sh eno1
|
sudo scripts/ethercat/start_ethercat.sh eno1
|
||||||
```
|
```
|
||||||
|
|
||||||
脚本会写入内置 IgH 配置文件:
|
脚本会写入内置 IgH 配置文件:
|
||||||
@ -163,7 +163,7 @@ $IGH_ETHERCAT_ROOT/etc/ethercat.conf
|
|||||||
查看状态:
|
查看状态:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
script/ethercat/status_ethercat.sh
|
scripts/ethercat/status_ethercat.sh
|
||||||
|
|
||||||
$IGH_ETHERCAT_ROOT/bin/ethercat master
|
$IGH_ETHERCAT_ROOT/bin/ethercat master
|
||||||
$IGH_ETHERCAT_ROOT/bin/ethercat slaves
|
$IGH_ETHERCAT_ROOT/bin/ethercat slaves
|
||||||
@ -173,6 +173,33 @@ $IGH_ETHERCAT_ROOT/bin/ethercat pdos
|
|||||||
停止 EtherCAT:
|
停止 EtherCAT:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
sudo script/ethercat/stop_ethercat.sh eno1
|
sudo scripts/ethercat/stop_ethercat.sh eno1
|
||||||
sudo script/ethercat/stop_ethercat.sh eno1 --restore-network
|
sudo scripts/ethercat/stop_ethercat.sh eno1 --restore-network
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### 4. 编译并安装
|
||||||
|
|
||||||
|
项目脚本统一位于 `scripts/`,用途见 [脚本索引](scripts/README.md)。
|
||||||
|
|
||||||
|
在项目根目录执行,不传参数默认使用 `Debug`,也可显式选择构建类型:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
./scripts/build.sh
|
||||||
|
./scripts/build.sh Debug
|
||||||
|
./scripts/build.sh Release
|
||||||
|
./scripts/build.sh RelWithDebInfo
|
||||||
|
```
|
||||||
|
|
||||||
|
三种类型分别使用 `build/Debug`、`build/Release`、`build/RelWithDebInfo`,
|
||||||
|
重复执行会增量编译。编译成功后自动安装到 `output`;编译失败不会执行安装。
|
||||||
|
日常运行和性能测试建议使用 `RelWithDebInfo`,保留调试信息并开启优化。
|
||||||
|
预编译的第三方库直接复用,不会随构建类型重新编译。
|
||||||
|
|
||||||
|
默认使用 4 个编译任务,可通过环境变量调整:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
CMAKE_BUILD_PARALLEL_LEVEL=2 ./scripts/build.sh RelWithDebInfo
|
||||||
|
```
|
||||||
|
|
||||||
|
安装会更新 `output/bin`、`output/lib`,并用源码目录的配置和模型替换
|
||||||
|
`output/bin/config`、`output/bin/model`;需要保留的配置应修改在源码目录中。
|
||||||
|
|||||||
@ -59,29 +59,33 @@ touch {
|
|||||||
|
|
||||||
先 MoveJ 到已有运动测试姿态,然后调用 `speedL(vy=+0.08)`,运动过程中直接调用 `speedL(vy=-0.08)`。默认 Base 坐标系,`--tool-frame true` 可验证 Tool 坐标系。测量来自 MuJoCo `R_FINGER_TIP_SITE` 的位置和雅可比乘实际 qvel;不是规划速度的积分。
|
先 MoveJ 到已有运动测试姿态,然后调用 `speedL(vy=+0.08)`,运动过程中直接调用 `speedL(vy=-0.08)`。默认 Base 坐标系,`--tool-frame true` 可验证 Tool 坐标系。测量来自 MuJoCo `R_FINGER_TIP_SITE` 的位置和雅可比乘实际 qvel;不是规划速度的积分。
|
||||||
|
|
||||||
在仓库根目录运行(需要已配置 `cmake-build-debug`;可用 `CMVR_BUILD_DIR` 覆盖):
|
在仓库根目录先完成构建和安装,再直接运行测试程序:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
./scripts/build.sh Debug
|
||||||
|
export LD_LIBRARY_PATH="$PWD/output/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
|
||||||
|
speedl_test="$PWD/build/Debug/cmvr-es/devices/arm/motor_robot_arm/speedl_reversal_mujoco_test"
|
||||||
|
|
||||||
# 匀速阶段换向:接近加速度 5,回撤加速度 3,jerk 均为 10。
|
# 匀速阶段换向:接近加速度 5,回撤加速度 3,jerk 均为 10。
|
||||||
./script/test_speedl_reversal_mujoco.sh --csv /tmp/reversal-new.csv
|
"$speedl_test" --csv /tmp/reversal-new.csv
|
||||||
|
|
||||||
# 同一新版本中选择旧换向策略,比较算法本身。
|
# 同一新版本中选择旧换向策略,比较算法本身。
|
||||||
./script/test_speedl_reversal_mujoco.sh --legacy true --csv /tmp/reversal-legacy.csv
|
"$speedl_test" --legacy true --csv /tmp/reversal-legacy.csv
|
||||||
|
|
||||||
# 仍在加速时,命令 vy 首次达到 0.032 m/s 即反向。
|
# 仍在加速时,命令 vy 首次达到 0.032 m/s 即反向。
|
||||||
./script/test_speedl_reversal_mujoco.sh --trigger-speed 0.032 --csv /tmp/reversal-accelerating.csv
|
"$speedl_test" --trigger-speed 0.032 --csv /tmp/reversal-accelerating.csv
|
||||||
|
|
||||||
# 上限仍为 10,回撤请求 60 将被限制为 10。
|
# 上限仍为 10,回撤请求 60 将被限制为 10。
|
||||||
./script/test_speedl_reversal_mujoco.sh --reverse-jerk 60 --reverse-acceleration 60 \
|
"$speedl_test" --reverse-jerk 60 --reverse-acceleration 60 \
|
||||||
--capture-reference true --csv /tmp/reversal-capped.csv
|
--capture-reference true --csv /tmp/reversal-capped.csv
|
||||||
|
|
||||||
# 将仿真机械臂 jerk 上限设为 60;接近请求 10,回撤请求 60。
|
# 将仿真机械臂 jerk 上限设为 60;接近请求 10,回撤请求 60。
|
||||||
./script/test_speedl_reversal_mujoco.sh --jerk 60 --approach-jerk 10 \
|
"$speedl_test" --jerk 60 --approach-jerk 10 \
|
||||||
--reverse-jerk 60 --capture-reference true \
|
--reverse-jerk 60 --capture-reference true \
|
||||||
--csv /tmp/reversal-jerk60.csv
|
--csv /tmp/reversal-jerk60.csv
|
||||||
|
|
||||||
# Tool 坐标系和触屏任务使用的参数接口。
|
# Tool 坐标系和触屏任务使用的参数接口。
|
||||||
./script/test_speedl_reversal_mujoco.sh --tool-frame true --jerk 60 --approach-jerk 10 --reverse-jerk 60 \
|
"$speedl_test" --tool-frame true --jerk 60 --approach-jerk 10 --reverse-jerk 60 \
|
||||||
--capture-reference true --csv /tmp/reversal-tool.csv
|
--capture-reference true --csv /tmp/reversal-tool.csv
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -101,4 +105,4 @@ touch {
|
|||||||
|
|
||||||
对齐回归覆盖每 20 ms 小幅更新方向、单拍 0.01 rad 方向变化、持续旋转 Tool 目标和速度恰在上限的情况,直接对最终速度命令差分检查 a/j 模长,并验证没有周期性降零。另覆盖拒绝不兼容降限后未来轨迹不变、角限值失败不部分更新线限值,以及停止恢复只重试一次。同轴连续换向过零仍保留加速度。
|
对齐回归覆盖每 20 ms 小幅更新方向、单拍 0.01 rad 方向变化、持续旋转 Tool 目标和速度恰在上限的情况,直接对最终速度命令差分检查 a/j 模长,并验证没有周期性降零。另覆盖拒绝不兼容降限后未来轨迹不变、角限值失败不部分更新线限值,以及停止恢复只重试一次。同轴连续换向过零仍保留加速度。
|
||||||
|
|
||||||
运行时应优先加载当前构建的项目动态库,测试脚本已处理;不要把新可执行文件与 `output/lib` 的旧项目库混用。
|
运行前应确认构建和安装成功,确保 `output/lib` 中的项目动态库与测试程序属于同一次构建。
|
||||||
|
|||||||
@ -5,18 +5,22 @@
|
|||||||
在仓库根目录运行:
|
在仓库根目录运行:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
./scripts/build.sh Debug
|
||||||
|
export LD_LIBRARY_PATH="$PWD/output/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
|
||||||
|
px6_test="$PWD/build/Debug/cmvr-es/devices/dexhand/px_6ax_gen3/px_6ax_gen3_real_test"
|
||||||
|
|
||||||
# 每次读取都发起一个真实请求:检查串口应答耗时和按压力值。
|
# 每次读取都发起一个真实请求:检查串口应答耗时和按压力值。
|
||||||
./script/test_px_6ax_gen3.sh --port /dev/ttyACM0 --module-id 2 \
|
"$px6_test" --port /dev/ttyACM0 --module-id 2 \
|
||||||
--mode sync --duration-s 30 --csv /tmp/paxini-sync.csv --raw-log /tmp/paxini-frames.log
|
--mode sync --duration-s 30 --csv /tmp/paxini-sync.csv --raw-log /tmp/paxini-frames.log
|
||||||
|
|
||||||
# 与触屏任务相同:后台轮询,前台读取最新有效缓存。
|
# 与触屏任务相同:后台轮询,前台读取最新有效缓存。
|
||||||
./script/test_px_6ax_gen3.sh --port /dev/ttyACM0 --module-id 2 \
|
"$px6_test" --port /dev/ttyACM0 --module-id 2 \
|
||||||
--mode stream --duration-s 30 --csv /tmp/paxini-stream.csv
|
--mode stream --duration-s 30 --csv /tmp/paxini-stream.csv
|
||||||
```
|
```
|
||||||
|
|
||||||
也可把 `--port` 指定为 `/dev/serial/by-id/` 下的稳定设备链接。设备端口取决于连接顺序;测试参数不会更改机器人部署配置里的串口。`module-id=2` 对应协议设备地址 3。
|
也可把 `--port` 指定为 `/dev/serial/by-id/` 下的稳定设备链接。设备端口取决于连接顺序;测试参数不会更改机器人部署配置里的串口。`module-id=2` 对应协议设备地址 3。
|
||||||
|
|
||||||
脚本会构建真实测试并优先加载本次构建的驱动和 protobuf。默认构建目录为 `cmake-build-debug`,可用 `CMVR_BUILD_DIR` 覆盖;构建目录须已完成 CMake 配置。串口应可读写,运行测试前退出占用同一串口的程序。
|
先确认构建和安装成功,再运行测试,确保 `output/lib` 中的驱动和 protobuf 与测试程序属于同一次构建。串口应可读写,运行测试前退出占用同一串口的程序。
|
||||||
|
|
||||||
测试期间可用手轻按、松开传感器,终端每 100 ms 显示一次力值,CSV 记录每次 getter 调用。按 Ctrl-C 可结束。CSV 的无效读数留空,不能当作零力。进程在初始化失败、没有有效数据或存在读取失败时返回非零退出码。
|
测试期间可用手轻按、松开传感器,终端每 100 ms 显示一次力值,CSV 记录每次 getter 调用。按 Ctrl-C 可结束。CSV 的无效读数留空,不能当作零力。进程在初始化失败、没有有效数据或存在读取失败时返回非零退出码。
|
||||||
|
|
||||||
|
|||||||
@ -77,7 +77,7 @@ TEST(TchlMotorRealTest, ProfilePosition)
|
|||||||
auto motor = initMotor(manager);
|
auto motor = initMotor(manager);
|
||||||
motor->calibrateZeroQ();
|
motor->calibrateZeroQ();
|
||||||
if (!motor->setMode(msgs::RUN_MODE_PROFILE_POSITION) || !motor->torqueOn() ||
|
if (!motor->setMode(msgs::RUN_MODE_PROFILE_POSITION) || !motor->torqueOn() ||
|
||||||
!motor->commandProfilePosition(-6, -1, kAccelerationRadS2)) {
|
!motor->commandProfilePosition(3, -1, kAccelerationRadS2)) {
|
||||||
throw std::runtime_error("Profile position command failed");
|
throw std::runtime_error("Profile position command failed");
|
||||||
}
|
}
|
||||||
std::cout << "target=" << kTargetPositionRad << " rad" << std::endl;
|
std::cout << "target=" << kTargetPositionRad << " rad" << std::endl;
|
||||||
|
|||||||
@ -25,8 +25,8 @@ dependency/x86/third_party/ethercat/v1.7.0
|
|||||||
真机运行前,系统里还需要安装/加载 IgH master 内核模块。使用仓库脚本启动 EtherCAT master:
|
真机运行前,系统里还需要安装/加载 IgH master 内核模块。使用仓库脚本启动 EtherCAT master:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
sudo script/ethercat/start_ethercat.sh eno1
|
sudo scripts/ethercat/start_ethercat.sh eno1
|
||||||
script/ethercat/status_ethercat.sh
|
scripts/ethercat/status_ethercat.sh
|
||||||
```
|
```
|
||||||
|
|
||||||
其中 `eno1` 是连接 EtherCAT 从站的网卡。脚本会读取该网卡 MAC,写入:
|
其中 `eno1` 是连接 EtherCAT 从站的网卡。脚本会读取该网卡 MAC,写入:
|
||||||
@ -40,13 +40,13 @@ dependency/x86/third_party/ethercat/v1.7.0/etc/ethercat.conf
|
|||||||
停止 EtherCAT:
|
停止 EtherCAT:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
sudo script/ethercat/stop_ethercat.sh eno1
|
sudo scripts/ethercat/stop_ethercat.sh eno1
|
||||||
```
|
```
|
||||||
|
|
||||||
如果这张网卡要恢复给普通网络使用:
|
如果这张网卡要恢复给普通网络使用:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
sudo script/ethercat/stop_ethercat.sh eno1 --restore-network
|
sudo scripts/ethercat/stop_ethercat.sh eno1 --restore-network
|
||||||
```
|
```
|
||||||
|
|
||||||
## 2. 电机配置
|
## 2. 电机配置
|
||||||
@ -420,8 +420,8 @@ cmake --build cmake-build-debug --target motor_manager
|
|||||||
真机验证顺序:
|
真机验证顺序:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
sudo script/ethercat/start_ethercat.sh eno1
|
sudo scripts/ethercat/start_ethercat.sh eno1
|
||||||
script/ethercat/status_ethercat.sh
|
scripts/ethercat/status_ethercat.sh
|
||||||
cmake --build cmake-build-debug --target cmvr_es
|
cmake --build cmake-build-debug --target cmvr_es
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@ -25,11 +25,14 @@ participate in edge-node registration or heartbeat.
|
|||||||
|
|
||||||
## Build and host-safe defaults
|
## Build and host-safe defaults
|
||||||
|
|
||||||
|
The source-build workflow below is historical: `build_msquic.sh` is not
|
||||||
|
included in the current repository.
|
||||||
|
|
||||||
cmvr-es pins MsQuic v2.5.9 and builds it from source into the repository
|
cmvr-es pins MsQuic v2.5.9 and builds it from source into the repository
|
||||||
dependency tree. It is not installed system-wide:
|
dependency tree. It is not installed system-wide:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
script/build_msquic.sh \
|
scripts/build_msquic.sh \
|
||||||
--arch x86 \
|
--arch x86 \
|
||||||
--version 2.5.9 \
|
--version 2.5.9 \
|
||||||
--jobs 2 \
|
--jobs 2 \
|
||||||
|
|||||||
383
script/USB_UI.py
383
script/USB_UI.py
@ -1,383 +0,0 @@
|
|||||||
import serial
|
|
||||||
import time
|
|
||||||
import serial.tools.list_ports
|
|
||||||
from typing import Optional, Dict, List
|
|
||||||
import logging
|
|
||||||
import tkinter as tk
|
|
||||||
from tkinter import ttk, messagebox, scrolledtext
|
|
||||||
|
|
||||||
# 配置日志系统
|
|
||||||
logging.basicConfig(
|
|
||||||
level=logging.INFO,
|
|
||||||
format='%(asctime)s - %(levelname)s - %(message)s'
|
|
||||||
)
|
|
||||||
logger = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
# 传感器型号与分布力数据长度的映射(单位:字节)
|
|
||||||
SENSOR_DISTRIBUTED_LENGTH = {
|
|
||||||
"S1813_elite": 93,
|
|
||||||
"S2015_elite": 156,
|
|
||||||
"S1813_core": 153,
|
|
||||||
"S2716_core": 348,
|
|
||||||
"S3013_core": 288,
|
|
||||||
"M2826_omega": 381,
|
|
||||||
"L3530_omega": 405,
|
|
||||||
"S1610_elite": 75,
|
|
||||||
"M2324_core": 204,
|
|
||||||
"M3025_core": 231,
|
|
||||||
"L5325_omega": 717,
|
|
||||||
"M2020_elite": 27
|
|
||||||
}
|
|
||||||
|
|
||||||
class SensorUI:
|
|
||||||
def __init__(self, root):
|
|
||||||
self.root = root
|
|
||||||
self.root.title("传感器数据采集系统")
|
|
||||||
self.root.geometry("900x700")
|
|
||||||
self.root.resizable(True, True)
|
|
||||||
|
|
||||||
self.ser = None # 串口对象
|
|
||||||
self.running = False # 数据采集状态
|
|
||||||
self.init_ui()
|
|
||||||
|
|
||||||
def init_ui(self):
|
|
||||||
# ===== 配置区域 =====
|
|
||||||
config_frame = ttk.LabelFrame(self.root, text="设备配置")
|
|
||||||
config_frame.pack(fill=tk.X, padx=10, pady=5)
|
|
||||||
|
|
||||||
# COM口选择
|
|
||||||
ttk.Label(config_frame, text="COM口:").grid(row=0, column=0, padx=5, pady=5, sticky=tk.W)
|
|
||||||
self.com_var = tk.StringVar()
|
|
||||||
self.com_combo = ttk.Combobox(config_frame, textvariable=self.com_var, width=10)
|
|
||||||
self.com_combo.grid(row=0, column=1, padx=5, pady=5)
|
|
||||||
ttk.Button(config_frame, text="刷新", command=self.refresh_com_ports).grid(row=0, column=2, padx=5, pady=5)
|
|
||||||
|
|
||||||
# 传感器型号选择(联动数据长度)
|
|
||||||
ttk.Label(config_frame, text="传感器型号:").grid(row=0, column=3, padx=5, pady=5, sticky=tk.W)
|
|
||||||
self.sensor_model = tk.StringVar(value="S1813_elite")
|
|
||||||
self.sensor_combo = ttk.Combobox(config_frame, textvariable=self.sensor_model, width=15)
|
|
||||||
self.sensor_combo['values'] = list(SENSOR_DISTRIBUTED_LENGTH.keys())
|
|
||||||
self.sensor_combo.bind("<<ComboboxSelected>>", self.update_length_by_model) # 选择型号时更新长度
|
|
||||||
self.sensor_combo.grid(row=0, column=4, padx=5, pady=5)
|
|
||||||
|
|
||||||
# 模组号选择(联动设备地址)
|
|
||||||
ttk.Label(config_frame, text="模组号:").grid(row=0, column=5, padx=5, pady=5, sticky=tk.W)
|
|
||||||
self.module_id = tk.StringVar(value="00") # 默认模组号00
|
|
||||||
self.module_combo = ttk.Combobox(config_frame, textvariable=self.module_id, width=5)
|
|
||||||
self.module_combo['values'] = ["00", "01", "02", "03", "04", "05", "06", "07"]
|
|
||||||
self.module_combo.bind("<<ComboboxSelected>>", self.update_device_addr) # 选择模组号时更新设备地址
|
|
||||||
self.module_combo.grid(row=0, column=6, padx=5, pady=5)
|
|
||||||
|
|
||||||
# 设备地址显示(只读,由模组号计算得出)
|
|
||||||
ttk.Label(config_frame, text="设备地址:").grid(row=0, column=7, padx=5, pady=5, sticky=tk.W)
|
|
||||||
self.device_addr_var = tk.StringVar(value="01") # 模组号00对应设备地址01
|
|
||||||
ttk.Label(config_frame, textvariable=self.device_addr_var, width=5).grid(row=0, column=8, padx=5, pady=5)
|
|
||||||
|
|
||||||
# 数据长度设置(可手动修改)
|
|
||||||
ttk.Label(config_frame, text="分布力数据长度(字节):").grid(row=1, column=0, padx=5, pady=5, sticky=tk.W)
|
|
||||||
self.dist_length = tk.StringVar(value=str(SENSOR_DISTRIBUTED_LENGTH["S1813_elite"]))
|
|
||||||
self.dist_entry = ttk.Entry(config_frame, textvariable=self.dist_length, width=10)
|
|
||||||
self.dist_entry.grid(row=1, column=1, padx=5, pady=5)
|
|
||||||
|
|
||||||
ttk.Label(config_frame, text="合力数据长度(字节):").grid(row=1, column=2, padx=5, pady=5, sticky=tk.W)
|
|
||||||
self.result_length = tk.StringVar(value="3")
|
|
||||||
ttk.Entry(config_frame, textvariable=self.result_length, width=10).grid(row=1, column=3, padx=5, pady=5)
|
|
||||||
|
|
||||||
# 控制按钮
|
|
||||||
btn_frame = ttk.Frame(config_frame)
|
|
||||||
btn_frame.grid(row=1, column=4, columnspan=5, padx=5, pady=5)
|
|
||||||
ttk.Button(btn_frame, text="连接设备", command=self.connect_device).pack(side=tk.LEFT, padx=5)
|
|
||||||
ttk.Button(btn_frame, text="传感器标定", command=self.calibrate_sensor).pack(side=tk.LEFT, padx=5)
|
|
||||||
ttk.Button(btn_frame, text="开始采集", command=self.start_collection).pack(side=tk.LEFT, padx=5)
|
|
||||||
ttk.Button(btn_frame, text="停止采集", command=self.stop_collection).pack(side=tk.LEFT, padx=5)
|
|
||||||
|
|
||||||
# ===== 日志显示区域 =====
|
|
||||||
log_frame = ttk.LabelFrame(self.root, text="数据日志")
|
|
||||||
log_frame.pack(fill=tk.BOTH, expand=True, padx=10, pady=5)
|
|
||||||
|
|
||||||
self.log_text = scrolledtext.ScrolledText(log_frame, wrap=tk.WORD, state=tk.DISABLED)
|
|
||||||
self.log_text.pack(fill=tk.BOTH, expand=True, padx=5, pady=5)
|
|
||||||
|
|
||||||
# 初始化COM口列表和设备地址
|
|
||||||
self.refresh_com_ports()
|
|
||||||
self.update_device_addr()
|
|
||||||
|
|
||||||
def refresh_com_ports(self):
|
|
||||||
"""刷新COM口列表"""
|
|
||||||
ports = [port.device for port in serial.tools.list_ports.comports()]
|
|
||||||
self.com_combo['values'] = ports
|
|
||||||
if ports:
|
|
||||||
self.com_var.set(ports[0])
|
|
||||||
|
|
||||||
def update_device_addr(self, event=None):
|
|
||||||
"""根据模组号计算设备地址(设备地址 = 模组号 + 1,转为十六进制)"""
|
|
||||||
try:
|
|
||||||
module_dec = int(self.module_id.get(), 16) # 模组号转为十进制
|
|
||||||
device_dec = module_dec + 1 # 设备地址 = 模组号 + 1
|
|
||||||
device_hex = f"{device_dec:02X}" # 转为2位十六进制(大写)
|
|
||||||
self.device_addr_var.set(device_hex)
|
|
||||||
self.log(f"模组号{self.module_id.get()} → 设备地址{device_hex}")
|
|
||||||
except ValueError:
|
|
||||||
self.log("模组号格式错误,无法计算设备地址")
|
|
||||||
|
|
||||||
def update_length_by_model(self, event=None):
|
|
||||||
"""根据选择的传感器型号自动更新分布力数据长度"""
|
|
||||||
model = self.sensor_model.get()
|
|
||||||
if model in SENSOR_DISTRIBUTED_LENGTH:
|
|
||||||
self.dist_length.set(str(SENSOR_DISTRIBUTED_LENGTH[model]))
|
|
||||||
self.log(f"自动更新{model}的分布力数据长度为: {SENSOR_DISTRIBUTED_LENGTH[model]}字节")
|
|
||||||
|
|
||||||
def log(self, message: str):
|
|
||||||
"""在UI中显示日志"""
|
|
||||||
self.log_text.config(state=tk.NORMAL)
|
|
||||||
self.log_text.insert(tk.END, message + "\n")
|
|
||||||
self.log_text.see(tk.END)
|
|
||||||
self.log_text.config(state=tk.DISABLED)
|
|
||||||
|
|
||||||
def connect_device(self):
|
|
||||||
"""连接串口设备"""
|
|
||||||
if self.ser and self.ser.is_open:
|
|
||||||
self.ser.close()
|
|
||||||
|
|
||||||
com_port = self.com_var.get()
|
|
||||||
if not com_port:
|
|
||||||
messagebox.showerror("错误", "请选择COM口")
|
|
||||||
return
|
|
||||||
|
|
||||||
try:
|
|
||||||
self.ser = serial.Serial(
|
|
||||||
port=com_port,
|
|
||||||
baudrate=921600,
|
|
||||||
bytesize=serial.EIGHTBITS,
|
|
||||||
parity=serial.PARITY_NONE,
|
|
||||||
stopbits=serial.STOPBITS_ONE,
|
|
||||||
timeout=0.1, # 读取超时缩短至0.1秒
|
|
||||||
write_timeout=0.1, # 写入超时缩短
|
|
||||||
inter_byte_timeout=0.0005, # 字节间隔超时缩短
|
|
||||||
xonxoff=False,
|
|
||||||
rtscts=False
|
|
||||||
)
|
|
||||||
if self.ser.is_open:
|
|
||||||
self.log(f"串口连接成功: {com_port}(波特率921600)")
|
|
||||||
logger.info(f"串口连接成功: {com_port}")
|
|
||||||
except serial.SerialException as e:
|
|
||||||
self.log(f"串口连接失败: {str(e)}")
|
|
||||||
logger.error(f"串口连接失败: {str(e)}")
|
|
||||||
messagebox.showerror("连接失败", str(e))
|
|
||||||
|
|
||||||
def get_commands(self) -> Dict[str, str]:
|
|
||||||
"""生成命令帧"""
|
|
||||||
model = self.sensor_model.get()
|
|
||||||
device_addr = self.device_addr_var.get() # 设备地址(十六进制,如"01")
|
|
||||||
dist_len = int(self.dist_length.get()) # 分布力数据长度(十进制)
|
|
||||||
|
|
||||||
# 1. 分布力命令帧:
|
|
||||||
# 命令帧格式:55 AA 09 00 [设备地址] 00 FB 0E 04 00 00 [长度低8位] [长度高8位]
|
|
||||||
len_low = dist_len & 0xFF # 数据长度低8位
|
|
||||||
len_high = (dist_len >> 8) & 0xFF # 数据长度高8位
|
|
||||||
len_hex = f"{len_low:02X}{len_high:02X}" # 小端格式(低位+高位)
|
|
||||||
distributed_frame = f"55 AA 09 00 {device_addr} 00 FB 0E 04 00 00 {len_hex[0:2]} {len_hex[2:4]}"
|
|
||||||
|
|
||||||
# 2. 标定命令帧:
|
|
||||||
# 格式:55 AA 0A 00 [设备地址] 00 79 03 00 00 00 01 00 01
|
|
||||||
calibration_frame = f"55 AA 0A 00 {device_addr} 00 79 03 00 00 00 01 00 01"
|
|
||||||
|
|
||||||
# 3. 合力命令帧:
|
|
||||||
# 格式:55 AA 09 00 [设备地址] 00 FB F0 03 00 00 03 00
|
|
||||||
resultant_frame = f"55 AA 09 00 {device_addr} 00 FB F0 03 00 00 03 00"
|
|
||||||
|
|
||||||
return {
|
|
||||||
"calibration": calibration_frame,
|
|
||||||
"resultant_force": resultant_frame,
|
|
||||||
"distributed_force": distributed_frame
|
|
||||||
}
|
|
||||||
|
|
||||||
def calculate_lrc(self, data: bytes) -> int:
|
|
||||||
"""计算LRC校验值"""
|
|
||||||
lrc = 0
|
|
||||||
for byte in data:
|
|
||||||
lrc = (lrc + byte) & 0xFF
|
|
||||||
lrc = ((~lrc) + 1) & 0xFF
|
|
||||||
return lrc
|
|
||||||
|
|
||||||
def send_command(self, command_type: str) -> Optional[bytes]:
|
|
||||||
"""发送命令并返回响应"""
|
|
||||||
if not self.ser or not self.ser.is_open:
|
|
||||||
self.log("未连接设备,请先连接")
|
|
||||||
return None
|
|
||||||
|
|
||||||
commands = self.get_commands()
|
|
||||||
if command_type not in commands:
|
|
||||||
self.log(f"未知命令类型: {command_type}")
|
|
||||||
return None
|
|
||||||
|
|
||||||
# 生成带LRC的命令帧
|
|
||||||
frame = commands[command_type].replace(" ", "") # 移除空格
|
|
||||||
try:
|
|
||||||
frame_bytes = bytes.fromhex(frame)
|
|
||||||
lrc = self.calculate_lrc(frame_bytes)
|
|
||||||
frame_with_lrc = frame + f"{lrc:02X}" # 追加LRC
|
|
||||||
except ValueError as e:
|
|
||||||
self.log(f"生成命令帧失败: {str(e)}")
|
|
||||||
return None
|
|
||||||
|
|
||||||
# 发送命令并打印详情(含设备地址和数据长度)
|
|
||||||
try:
|
|
||||||
data_bytes = bytes.fromhex(frame_with_lrc)
|
|
||||||
self.ser.write(data_bytes)
|
|
||||||
print(f"发送{command_type}命令(设备地址={self.device_addr_var.get()}): {frame_with_lrc}")
|
|
||||||
except serial.SerialException as e:
|
|
||||||
self.log(f"命令发送失败: {str(e)}")
|
|
||||||
return None
|
|
||||||
|
|
||||||
# 读取响应
|
|
||||||
time.sleep(0.01)
|
|
||||||
response = b""
|
|
||||||
start_time = time.time()
|
|
||||||
while time.time() - start_time < 0.2: # 1.5秒超时
|
|
||||||
if self.ser.in_waiting > 0:
|
|
||||||
response += self.ser.read(self.ser.in_waiting) # 一次性读取所有等待的数据,减少循环次数
|
|
||||||
# 若已读取到预期长度(根据命令类型),提前退出
|
|
||||||
if command_type == "resultant_force" and len(response) >= 14 + 3:
|
|
||||||
break
|
|
||||||
if command_type == "distributed_force" and len(response) >= 14 + int(self.dist_length.get()):
|
|
||||||
break
|
|
||||||
# 极短延迟
|
|
||||||
time.sleep(0.0001)
|
|
||||||
|
|
||||||
if response:
|
|
||||||
print(f"收到响应({len(response)}字节): {response.hex()}")
|
|
||||||
return response
|
|
||||||
print("未收到响应")
|
|
||||||
return None
|
|
||||||
|
|
||||||
def calibrate_sensor(self):
|
|
||||||
"""标定"""
|
|
||||||
response = self.send_command("calibration")
|
|
||||||
if response:
|
|
||||||
# 校验帧头
|
|
||||||
if response[:2].hex() == "aa55":
|
|
||||||
self.log(f"{self.sensor_model.get()} 标定成功")
|
|
||||||
else:
|
|
||||||
self.log("标定响应格式错误")
|
|
||||||
else:
|
|
||||||
self.log("标定失败")
|
|
||||||
|
|
||||||
def parse_resultant_force(self, data: bytes) -> Optional[Dict]:
|
|
||||||
"""解析合力数据"""
|
|
||||||
if len(data) != int(self.result_length.get()):
|
|
||||||
print(f"合力数据长度错误(预期{self.result_length.get()}字节,实际{len(data)}字节)")
|
|
||||||
return None
|
|
||||||
|
|
||||||
byte1, byte2, byte3 = data[0], data[1], data[2]
|
|
||||||
val1 = byte1 if byte1 <= 127 else byte1 - 256
|
|
||||||
val2 = byte2 if byte2 <= 127 else byte2 - 256
|
|
||||||
val3 = byte3
|
|
||||||
|
|
||||||
# 转换为物理单位
|
|
||||||
force_x = val1 * 0.1
|
|
||||||
force_y = val2 * 0.1
|
|
||||||
force_z = val3 * 0.1
|
|
||||||
|
|
||||||
return {
|
|
||||||
"raw": (byte1, byte2, byte3),
|
|
||||||
"parsed": (val1, val2, val3),
|
|
||||||
"force_N": (force_x, force_y, force_z)
|
|
||||||
}
|
|
||||||
|
|
||||||
def parse_distributed_force(self, data: bytes) -> List[Dict]:
|
|
||||||
"""解析分布力数据"""
|
|
||||||
parsed = []
|
|
||||||
total_len = int(self.dist_length.get())
|
|
||||||
if len(data) < total_len:
|
|
||||||
print(f"分布力数据长度不足(预期{total_len}字节,实际{len(data)}字节)")
|
|
||||||
total_len = len(data)
|
|
||||||
|
|
||||||
group_count = total_len // 3 # 每3字节一组
|
|
||||||
for i in range(group_count):
|
|
||||||
byte1 = data[i*3]
|
|
||||||
byte2 = data[i*3 + 1]
|
|
||||||
byte3 = data[i*3 + 2]
|
|
||||||
|
|
||||||
val1 = byte1 if byte1 <= 127 else byte1 - 256
|
|
||||||
val2 = byte2 if byte2 <= 127 else byte2 - 256
|
|
||||||
val3 = byte3
|
|
||||||
|
|
||||||
force_x = val1 * 0.1
|
|
||||||
force_y = val2 * 0.1
|
|
||||||
force_z = val3 * 0.1
|
|
||||||
|
|
||||||
parsed.append({
|
|
||||||
"index": i,
|
|
||||||
"raw": (byte1, byte2, byte3),
|
|
||||||
"parsed": (val1, val2, val3),
|
|
||||||
"force_N": (force_x, force_y, force_z)
|
|
||||||
})
|
|
||||||
return parsed
|
|
||||||
|
|
||||||
def collect_data(self):
|
|
||||||
"""循环采集数据"""
|
|
||||||
if not self.running or not self.ser or not self.ser.is_open:
|
|
||||||
return
|
|
||||||
|
|
||||||
# 读取合力数据
|
|
||||||
result_response = self.send_command("resultant_force")
|
|
||||||
if result_response and len(result_response) > 14:
|
|
||||||
result_data = result_response[14:14 + int(self.result_length.get())]
|
|
||||||
result_parsed = self.parse_resultant_force(result_data)
|
|
||||||
if result_parsed:
|
|
||||||
print("\n===== 合力数据 =====")
|
|
||||||
print(f"合力数据原始字节: 0x{result_parsed['raw'][0]:02X}, 0x{result_parsed['raw'][1]:02X}, 0x{result_parsed['raw'][2]:02X}")
|
|
||||||
print(f"合力数据解析值: X={result_parsed['parsed'][0]}, Y={result_parsed['parsed'][1]}, Z={result_parsed['parsed'][2]}")
|
|
||||||
self.log(f"合力数据: X={result_parsed['force_N'][0]:.1f}N, Y={result_parsed['force_N'][1]:.1f}N, Z={result_parsed['force_N'][2]:.1f}N")
|
|
||||||
self.log(f"")
|
|
||||||
|
|
||||||
# 读取分布力数据
|
|
||||||
dist_response = self.send_command("distributed_force")
|
|
||||||
if dist_response and len(dist_response) > 14:
|
|
||||||
dist_data = dist_response[14:14 + int(self.dist_length.get())]
|
|
||||||
dist_parsed = self.parse_distributed_force(dist_data)
|
|
||||||
if dist_parsed:
|
|
||||||
print("\n===== 分布力数据 =====")
|
|
||||||
print(f"总测点: {len(dist_parsed)}")
|
|
||||||
for point in dist_parsed:
|
|
||||||
print(f"测点{point['index']:02d} | 物理值: X={point['force_N'][0]:.1f}N, Y={point['force_N'][1]:.1f}N, Z={point['force_N'][2]:.1f}N")
|
|
||||||
print(f"------------------------------------------")
|
|
||||||
|
|
||||||
# 继续循环采集,10ms间隔
|
|
||||||
self.root.after(10, self.collect_data)
|
|
||||||
|
|
||||||
def start_collection(self):
|
|
||||||
"""开始数据采集"""
|
|
||||||
if self.running:
|
|
||||||
self.log("已在采集数据中")
|
|
||||||
return
|
|
||||||
|
|
||||||
if not self.ser or not self.ser.is_open:
|
|
||||||
messagebox.showwarning("警告", "请先连接设备")
|
|
||||||
return
|
|
||||||
|
|
||||||
self.running = True
|
|
||||||
self.log("开始数据采集...")
|
|
||||||
self.collect_data()
|
|
||||||
|
|
||||||
def stop_collection(self):
|
|
||||||
"""停止数据采集"""
|
|
||||||
self.running = False
|
|
||||||
self.log("已停止数据采集")
|
|
||||||
|
|
||||||
def on_close(self):
|
|
||||||
"""关闭窗口时释放资源"""
|
|
||||||
self.running = False
|
|
||||||
if self.ser and self.ser.is_open:
|
|
||||||
self.ser.close()
|
|
||||||
self.root.destroy()
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
root = tk.Tk()
|
|
||||||
app = SensorUI(root)
|
|
||||||
root.protocol("WM_DELETE_WINDOW", app.on_close)
|
|
||||||
root.mainloop()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -1,62 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
set -euo pipefail
|
|
||||||
|
|
||||||
# Build the same portable x86-64 OMPL core used by this project's dependency
|
|
||||||
# bundle. No system installation or sudo is required.
|
|
||||||
cmvr_root=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." && pwd)
|
|
||||||
cmvr_ompl_version=2.0.2
|
|
||||||
cmvr_ompl_sha256=d867190a46a7f730923475a68af2e09fc9e796017a59be395a4bf3900d0c3ae4
|
|
||||||
if [[ $(uname -m) != x86_64 ]]; then
|
|
||||||
echo 'This dependency recipe targets x86-64; ARM needs a separate toolchain build.' >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
cmvr_ompl_prefix="$cmvr_root/dependency/x86/third_party/ompl/v$cmvr_ompl_version"
|
|
||||||
cmvr_eigen_prefix="$cmvr_root/dependency/x86/third_party/Eigen3/v3.4.0"
|
|
||||||
cmvr_ompl_work=$(mktemp -d "${TMPDIR:-/tmp}/cmvr-ompl.XXXXXXXX")
|
|
||||||
trap 'rm -rf -- "$cmvr_ompl_work"' EXIT
|
|
||||||
cmvr_ompl_archive="$cmvr_ompl_work/ompl.tar.gz"
|
|
||||||
if [[ -n ${CMVR_OMPL_ARCHIVE:-} ]]; then
|
|
||||||
cp -- "$CMVR_OMPL_ARCHIVE" "$cmvr_ompl_archive"
|
|
||||||
else
|
|
||||||
curl --fail --location --retry 3 --connect-timeout 15 --max-time 300 \
|
|
||||||
"https://codeload.github.com/ompl/ompl/tar.gz/refs/tags/$cmvr_ompl_version" \
|
|
||||||
-o "$cmvr_ompl_archive"
|
|
||||||
fi
|
|
||||||
printf '%s %s\n' "$cmvr_ompl_sha256" "$cmvr_ompl_archive" | sha256sum --check -
|
|
||||||
tar -xzf "$cmvr_ompl_archive" -C "$cmvr_ompl_work"
|
|
||||||
cmvr_ompl_source="$cmvr_ompl_work/ompl-$cmvr_ompl_version"
|
|
||||||
|
|
||||||
cmake -S "$cmvr_ompl_source" -B "$cmvr_ompl_work/build" \
|
|
||||||
-DCMAKE_BUILD_TYPE=Release \
|
|
||||||
-DCMAKE_INSTALL_PREFIX="$cmvr_ompl_prefix" \
|
|
||||||
-DCMAKE_INSTALL_LIBDIR=lib \
|
|
||||||
-DCMAKE_PREFIX_PATH="$cmvr_eigen_prefix" \
|
|
||||||
'-DCMAKE_INSTALL_RPATH=$ORIGIN' \
|
|
||||||
-DOMPL_SKIP_RPATH=ON \
|
|
||||||
-DOMPL_VERSIONED_INSTALL=OFF \
|
|
||||||
-DOMPL_BUILD_SHARED=ON \
|
|
||||||
-DOMPL_BUILD_VAMP=OFF \
|
|
||||||
-DOMPL_BUILD_PYTHON_BINDINGS=OFF \
|
|
||||||
-DOMPL_BUILD_DEMOS=OFF \
|
|
||||||
-DOMPL_BUILD_TESTS=OFF \
|
|
||||||
-DCMAKE_DISABLE_FIND_PACKAGE_flann=ON \
|
|
||||||
-DCMAKE_DISABLE_FIND_PACKAGE_Triangle=ON \
|
|
||||||
-DCMAKE_DISABLE_FIND_PACKAGE_spot=ON \
|
|
||||||
-DCMAKE_DISABLE_FIND_PACKAGE_Doxygen=ON \
|
|
||||||
-DCMAKE_DISABLE_FIND_PACKAGE_Python=ON
|
|
||||||
cmake --build "$cmvr_ompl_work/build" --target ompl --parallel "${CMVR_OMPL_JOBS:-4}"
|
|
||||||
# Upstream's exported CMake targets use the default install component. Stage a
|
|
||||||
# full install, then retain just the headers, library, and package metadata.
|
|
||||||
cmake --install "$cmvr_ompl_work/build" --prefix "$cmvr_ompl_work/install" --strip
|
|
||||||
# Resolve Eigen's deprecated include variable on the consumer's machine instead
|
|
||||||
# of retaining the absolute path of the machine that built this bundle.
|
|
||||||
sed -i \
|
|
||||||
's@^list(APPEND OMPL_INCLUDE_DIRS .*Eigen3/v3\.4\.0)@list(APPEND OMPL_INCLUDE_DIRS "${EIGEN3_INCLUDE_DIRS}")@' \
|
|
||||||
"$cmvr_ompl_work/install/share/ompl/cmake/omplConfig.cmake"
|
|
||||||
mkdir -p "$cmvr_ompl_prefix/lib" "$cmvr_ompl_prefix/share/ompl"
|
|
||||||
cp -a "$cmvr_ompl_work/install/include" "$cmvr_ompl_prefix/"
|
|
||||||
# Remove headers left by an earlier build using OMPL's versioned layout.
|
|
||||||
rm -rf -- "$cmvr_ompl_prefix/include/ompl-2.0"
|
|
||||||
cp -a "$cmvr_ompl_work/install/lib/"libompl.so* "$cmvr_ompl_prefix/lib/"
|
|
||||||
cp -a "$cmvr_ompl_work/install/share/ompl/cmake" "$cmvr_ompl_prefix/share/ompl/"
|
|
||||||
printf 'Installed OMPL %s to %s\n' "$cmvr_ompl_version" "$cmvr_ompl_prefix"
|
|
||||||
168
script/test.py
168
script/test.py
@ -1,168 +0,0 @@
|
|||||||
#!/usr/bin/env python3
|
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
"""
|
|
||||||
text_dgceshi.py — 写死 5 组表情(已按 XML 限位约束),每 5 秒切换,循环发送到 ESP32
|
|
||||||
依赖:pip install pyserial
|
|
||||||
用法:
|
|
||||||
python text_dgceshi.py /dev/ttyUSB0 [baudrate]
|
|
||||||
|
|
||||||
帧格式(与你现有固件一致):
|
|
||||||
[0] 0xAA
|
|
||||||
[1] count = 指令条数(每条是5字节:addr, ch, ang, durL, durH)
|
|
||||||
[2..] 指令序列,共 count*5 字节
|
|
||||||
[end] XOR 校验(对前面所有字节异或)
|
|
||||||
"""
|
|
||||||
|
|
||||||
import sys
|
|
||||||
import time
|
|
||||||
import serial
|
|
||||||
|
|
||||||
FRAME_HEADER = 0xAA
|
|
||||||
|
|
||||||
def calc_checksum(data: bytearray) -> int:
|
|
||||||
"""XOR 校验"""
|
|
||||||
cs = 0
|
|
||||||
for b in data:
|
|
||||||
cs ^= b
|
|
||||||
return cs & 0xFF
|
|
||||||
|
|
||||||
def pack_pose(raw_list):
|
|
||||||
"""
|
|
||||||
raw_list: [addr, ch, ang, durL, durH, addr, ch, ang, durL, durH, ...]
|
|
||||||
返回带帧头/数量/校验的完整数据包 bytes
|
|
||||||
"""
|
|
||||||
assert len(raw_list) % 5 == 0, "原始列表长度必须是 5 的倍数"
|
|
||||||
count = len(raw_list) // 5
|
|
||||||
pkt = bytearray([FRAME_HEADER, count & 0xFF])
|
|
||||||
pkt.extend(int(x) & 0xFF for x in raw_list)
|
|
||||||
pkt.append(calc_checksum(pkt))
|
|
||||||
return bytes(pkt)
|
|
||||||
|
|
||||||
def print_packet(pkt):
|
|
||||||
print("发送数据包:", ' '.join(f"0x{b:02X}" for b in pkt))
|
|
||||||
|
|
||||||
def wakeup_esp32(port, baud=115200):
|
|
||||||
"""通过 RTS/DTR 尝试唤醒 ESP32(可选)"""
|
|
||||||
try:
|
|
||||||
ser = serial.Serial(port, baud, timeout=1)
|
|
||||||
ser.setDTR(False)
|
|
||||||
ser.setRTS(False)
|
|
||||||
time.sleep(0.02)
|
|
||||||
ser.setDTR(True)
|
|
||||||
ser.setRTS(True)
|
|
||||||
ser.write(b"\r\n")
|
|
||||||
time.sleep(0.2)
|
|
||||||
except Exception as e:
|
|
||||||
print(f"[WARN] 唤醒失败:{e}")
|
|
||||||
finally:
|
|
||||||
try:
|
|
||||||
ser.close()
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
|
|
||||||
def open_serial(port, baud):
|
|
||||||
try:
|
|
||||||
ser = serial.Serial(port, baud, timeout=1)
|
|
||||||
print(f"已打开串口: {port} @ {baud}bps")
|
|
||||||
return ser
|
|
||||||
except Exception as e:
|
|
||||||
print(f"打开串口失败: {e}")
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
# =======================
|
|
||||||
# 五组“写死”的表情数据(严格遵守你的 XML 安全限位)
|
|
||||||
# 64:0~3 眉(offset 90/90/90/90,限位 45~120/…/50~120)
|
|
||||||
# 64:4~9 眼(offset 90..,限位 [90~170, 10~90, 10~90, 90~170, 10~170, 10~170])
|
|
||||||
# 65:0~9 嘴(offset 90..,限位 [60~130, 60~130, 50~120, 50~130, 50~100, 50~130, 50~130, 90~120, 91~120, 60~89])
|
|
||||||
# duration 全部为 0(立即执行);如需时长,可把毫秒拆成 durL/durH 小端写入
|
|
||||||
# =======================
|
|
||||||
|
|
||||||
POSES_RAW = [
|
|
||||||
# # Pose 1 — 中性位置(全部 offset)
|
|
||||||
[
|
|
||||||
# 板 64 — 眼眉 0~3
|
|
||||||
64,0,90,0,0, 64,1,90,0,0, 64,2,90,0,0, 64,3,90,0,0,
|
|
||||||
# 板 64 — 眼睛 4~9(选在各自安全范围内的中值/视觉舒适值)
|
|
||||||
64,4,160,0,0, 64,5,20,0,0, 64,6,20,0,0, 64,7,160,0,0, 64,8,150,0,0, 64,9,150,0,0,
|
|
||||||
# 板 65 — 嘴巴 0~9
|
|
||||||
65,0,90,0,0, 65,1,90,0,0, 65,2,85,0,0, 65,3,90,0,0, 65,4,90,0,0,
|
|
||||||
65,5,90,0,0, 65,6,90,0,0, 65,7,90,0,0, 65,8,90,0,0, 65,9,90,0,0
|
|
||||||
],
|
|
||||||
|
|
||||||
# Pose 5 — 大笑(接近上限但不越界)
|
|
||||||
[
|
|
||||||
64,0,115,0,0, 64,1,75,0,0, 64,2,75,0,0, 64,3,115,0,0,
|
|
||||||
64,4,160,0,0, 64,5,20,0,0, 64,6,20,0,0, 64,7,160,0,0, 64,8,50,0,0, 64,9,40,0,0,
|
|
||||||
65,0,50,0,0, 65,1,110,0,0, 65,2,70,0,0, 65,3,50,0,0, 65,4,100,0,0,
|
|
||||||
65,5,110,0,0, 65,6,130,0,0, 65,7,90,0,0, 65,8,110,0,0, 65,9,70,0,0
|
|
||||||
],
|
|
||||||
|
|
||||||
|
|
||||||
[
|
|
||||||
64,0,115,0,0, 64,1,75,0,0, 64,2,75,0,0, 64,3,115,0,0,
|
|
||||||
64,4,160,0,0, 64,5,20,0,0, 64,6,20,0,0, 64,7,160,0,0, 64,8,50,0,0, 64,9,130,0,0,
|
|
||||||
65,0,50,0,0, 65,1,110,0,0, 65,2,70,0,0, 65,3,50,0,0, 65,4,90,0,0,
|
|
||||||
65,5,110,0,0, 65,6,130,0,0, 65,7,90,0,0, 65,8,90,0,0, 65,9,90,0,0
|
|
||||||
],
|
|
||||||
[
|
|
||||||
64,0,115,0,0, 64,1,75,0,0, 64,2,75,0,0, 64,3,115,0,0,
|
|
||||||
64,4,160,0,0, 64,5,20,0,0, 64,6,20,0,0, 64,7,160,0,0, 64,8,50,0,0, 64,9,40,0,0,
|
|
||||||
65,0,50,0,0, 65,1,110,0,0, 65,2,70,0,0, 65,3,50,0,0, 65,4,90,0,0,
|
|
||||||
65,5,110,0,0, 65,6,130,0,0, 65,7,90,0,0, 65,8,110,0,0, 65,9,70,0,0
|
|
||||||
]
|
|
||||||
]
|
|
||||||
|
|
||||||
POSES_RAW1 = [[
|
|
||||||
# 板 64 — 眼眉 0~3
|
|
||||||
64,0,90,0,0, 64,1,90,0,0, 64,2,90,0,0, 64,3,90,0,0,
|
|
||||||
# 板 64 — 眼睛 4~9(选在各自安全范围内的中值/视觉舒适值)
|
|
||||||
64,4,90,0,0, 64,5,90,0,0, 64,6,90,0,0, 64,7,90,0,0, 64,8,150,0,0, 64,9,150,0,0,
|
|
||||||
# 板 65 — 嘴巴 0~9
|
|
||||||
65,0,90,0,0, 65,1,90,0,0, 65,2,85,0,0, 65,3,90,0,0, 65,4,90,0,0,
|
|
||||||
65,5,90,0,0, 65,6,90,0,0, 65,7,90,0,0, 65,8,90,0,0, 65,9,90,0,0
|
|
||||||
],
|
|
||||||
|
|
||||||
# Pose 5 — 大笑(接近上限但不越界)
|
|
||||||
[
|
|
||||||
64,0,115,0,0, 64,1,75,0,0, 64,2,75,0,0, 64,3,115,0,0,
|
|
||||||
64,4,160,0,0, 64,5,20,0,0, 64,6,20,0,0, 64,7,160,0,0, 64,8,50,0,0, 64,9,40,0,0,
|
|
||||||
65,0,50,0,0, 65,1,110,0,0, 65,2,70,0,0, 65,3,50,0,0, 65,4,100,0,0,
|
|
||||||
65,5,110,0,0, 65,6,130,0,0, 65,7,90,0,0, 65,8,110,0,0, 65,9,70,0,0
|
|
||||||
],
|
|
||||||
|
|
||||||
|
|
||||||
]
|
|
||||||
|
|
||||||
def main():
|
|
||||||
if len(sys.argv) < 2:
|
|
||||||
print(f"用法: {sys.argv[0]} /dev/ttyUSB0 [baudrate]")
|
|
||||||
sys.exit(1)
|
|
||||||
port = sys.argv[1]
|
|
||||||
baud = int(sys.argv[2]) if len(sys.argv) > 2 else 115200
|
|
||||||
|
|
||||||
# 可选:尝试唤醒 ESP32
|
|
||||||
wakeup_esp32(port, baud)
|
|
||||||
|
|
||||||
ser = open_serial(port, baud)
|
|
||||||
|
|
||||||
try:
|
|
||||||
pose_idx = 0
|
|
||||||
hold_seconds = 5
|
|
||||||
print(f"开始循环播放 5 组表情,每组间隔 {hold_seconds} 秒...")
|
|
||||||
while True:
|
|
||||||
pose = POSES_RAW[pose_idx]
|
|
||||||
pkt = pack_pose(pose)
|
|
||||||
print(f"\n→ 发送 Pose {pose_idx+1}/{len(POSES_RAW)}")
|
|
||||||
print_packet(pkt)
|
|
||||||
ser.write(pkt)
|
|
||||||
ser.flush()
|
|
||||||
time.sleep(hold_seconds)
|
|
||||||
pose_idx = (pose_idx + 1) % len(POSES_RAW)
|
|
||||||
except KeyboardInterrupt:
|
|
||||||
print("\n用户中断,退出")
|
|
||||||
finally:
|
|
||||||
ser.close()
|
|
||||||
print("串口已关闭")
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
main()
|
|
||||||
@ -1,12 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
set -euo pipefail
|
|
||||||
|
|
||||||
# Real USB sensor test. The executable only sends force-read requests.
|
|
||||||
# Example: ./script/test_px_6ax_gen3.sh --port /dev/ttyACM0 --duration-s 20 --mode sync
|
|
||||||
repo_root="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
||||||
build_dir="${CMVR_BUILD_DIR:-${repo_root}/cmake-build-debug}"
|
|
||||||
cmake --build "$build_dir" --target px_6ax_gen3_real_test -j 4
|
|
||||||
sensor_build_dir="$build_dir/cmvr-es/devices/dexhand/px_6ax_gen3"
|
|
||||||
# Put build libraries ahead of installed ones so this tests the current driver/proto.
|
|
||||||
exec env LD_LIBRARY_PATH="$build_dir:$sensor_build_dir:$build_dir/cmvr-es/hardware:$repo_root/output/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}" \
|
|
||||||
"$sensor_build_dir/px_6ax_gen3_real_test" "$@"
|
|
||||||
@ -1,22 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
set -euo pipefail
|
|
||||||
|
|
||||||
# Headless MuJoCo only. Never initializes the physical robot.
|
|
||||||
repo_root="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
||||||
build_dir="${CMVR_BUILD_DIR:-${repo_root}/cmake-build-debug}"
|
|
||||||
cmake --build "$build_dir" --target speedl_reversal_mujoco_test -j 8
|
|
||||||
cd "$repo_root"
|
|
||||||
python3 - "$build_dir" "$@" <<'PY'
|
|
||||||
from pathlib import Path
|
|
||||||
import os
|
|
||||||
import sys
|
|
||||||
|
|
||||||
build = Path(sys.argv[1]).resolve()
|
|
||||||
# Prefer every freshly built project library over output/lib's installed copy.
|
|
||||||
paths = sorted({str(path.parent) for path in build.rglob('*.so')})
|
|
||||||
paths.append(str(Path('output/lib').resolve()))
|
|
||||||
env = os.environ.copy()
|
|
||||||
env['LD_LIBRARY_PATH'] = ':'.join(paths + [env.get('LD_LIBRARY_PATH', '')])
|
|
||||||
binary = build / 'cmvr-es/devices/arm/motor_robot_arm/speedl_reversal_mujoco_test'
|
|
||||||
os.execve(str(binary), [str(binary), *sys.argv[2:]], env)
|
|
||||||
PY
|
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,22 +0,0 @@
|
|||||||
import trimesh
|
|
||||||
|
|
||||||
path = "R_WRIST_R_S.STL"
|
|
||||||
|
|
||||||
obj = trimesh.load(path)
|
|
||||||
|
|
||||||
if isinstance(obj, trimesh.Scene):
|
|
||||||
mesh = trimesh.util.concatenate(list(obj.geometry.values()))
|
|
||||||
else:
|
|
||||||
mesh = obj
|
|
||||||
|
|
||||||
print("原始面数:", len(mesh.faces))
|
|
||||||
|
|
||||||
# 想删掉 80% 的面(保留 20%)
|
|
||||||
target_reduction = 0.8 # 0~1 之间
|
|
||||||
|
|
||||||
mesh_simplified = mesh.simplify_quadric_decimation(target_reduction)
|
|
||||||
print("简化后面数:", len(mesh_simplified.faces))
|
|
||||||
|
|
||||||
out_path = "R_WRIST_R_S_low.STL"
|
|
||||||
mesh_simplified.export(out_path)
|
|
||||||
print("已导出:", out_path)
|
|
||||||
@ -1,243 +0,0 @@
|
|||||||
import time
|
|
||||||
from pymodbus.client import ModbusTcpClient
|
|
||||||
from pymodbus.pdu import ExceptionResponse
|
|
||||||
|
|
||||||
# 定义 Modbus TCP 相关参数
|
|
||||||
MODBUS_IP = "192.168.11.210"
|
|
||||||
MODBUS_PORT = 6000
|
|
||||||
|
|
||||||
# 定义各部分数据地址范围
|
|
||||||
TOUCH_SENSOR_BASE_ADDR_PINKY = 3000 # 小拇指
|
|
||||||
TOUCH_SENSOR_END_ADDR_PINKY = 3369
|
|
||||||
|
|
||||||
TOUCH_SENSOR_BASE_ADDR_RING = 3370 # 无名指
|
|
||||||
TOUCH_SENSOR_END_ADDR_RING = 3739
|
|
||||||
|
|
||||||
TOUCH_SENSOR_BASE_ADDR_MIDDLE = 3740 # 中指
|
|
||||||
TOUCH_SENSOR_END_ADDR_MIDDLE = 4109
|
|
||||||
|
|
||||||
TOUCH_SENSOR_BASE_ADDR_INDEX = 4110 # 食指
|
|
||||||
TOUCH_SENSOR_END_ADDR_INDEX = 4479
|
|
||||||
|
|
||||||
TOUCH_SENSOR_BASE_ADDR_THUMB = 4480 # 大拇指
|
|
||||||
TOUCH_SENSOR_END_ADDR_THUMB = 4899
|
|
||||||
|
|
||||||
TOUCH_SENSOR_BASE_ADDR_PALM = 4900 # 掌心
|
|
||||||
TOUCH_SENSOR_END_ADDR_PALM = 5123
|
|
||||||
|
|
||||||
# Modbus 每次最多读取寄存器的数量
|
|
||||||
MAX_REGISTERS_PER_READ = 125
|
|
||||||
|
|
||||||
|
|
||||||
def read_register_range(client, start_addr, end_addr):
|
|
||||||
"""
|
|
||||||
批量读取指定地址范围内的寄存器数据。
|
|
||||||
"""
|
|
||||||
register_values = []
|
|
||||||
# 分段读取寄存器
|
|
||||||
for addr in range(start_addr, end_addr + 1, MAX_REGISTERS_PER_READ * 2):
|
|
||||||
current_count = min(MAX_REGISTERS_PER_READ, (end_addr - addr) // 2 + 1)
|
|
||||||
response = client.read_holding_registers(address=addr, count=current_count)
|
|
||||||
|
|
||||||
if isinstance(response, ExceptionResponse) or response.isError():
|
|
||||||
print(f"读取寄存器 {addr} 失败: {response}")
|
|
||||||
register_values.extend([0] * current_count)
|
|
||||||
else:
|
|
||||||
register_values.extend(response.registers)
|
|
||||||
|
|
||||||
return register_values
|
|
||||||
|
|
||||||
def format_finger_data(finger_name, data):
|
|
||||||
"""
|
|
||||||
格式化四指触觉数据。
|
|
||||||
"""
|
|
||||||
result = {}
|
|
||||||
|
|
||||||
if finger_name != "大拇指":
|
|
||||||
# 四指格式
|
|
||||||
if len(data) < 185:
|
|
||||||
print(f"{finger_name} 数据长度不足,至少185个数据,实际:{len(data)}")
|
|
||||||
return None
|
|
||||||
|
|
||||||
idx = 0
|
|
||||||
# 指端数据 3x3
|
|
||||||
result['tip_end'] = [data[idx + i*3: idx + (i+1)*3] for i in range(3)]
|
|
||||||
idx += 9
|
|
||||||
|
|
||||||
# 指尖触觉数据 12x8
|
|
||||||
result['tip_touch'] = [data[idx + i*8: idx + (i+1)*8] for i in range(12)]
|
|
||||||
idx += 96
|
|
||||||
|
|
||||||
# 指腹触觉数据 10x8
|
|
||||||
result['finger_pad'] = [data[idx + i*8: idx + (i+1)*8] for i in range(10)]
|
|
||||||
idx += 80
|
|
||||||
else:
|
|
||||||
# 大拇指格式
|
|
||||||
if len(data) < 210:
|
|
||||||
print(f"{finger_name} 数据长度不足,至少210个数据,实际:{len(data)}")
|
|
||||||
return None
|
|
||||||
|
|
||||||
idx = 0
|
|
||||||
# 指端数据 3x3
|
|
||||||
result['tip_end'] = [data[idx + i*3: idx + (i+1)*3] for i in range(3)]
|
|
||||||
idx += 9
|
|
||||||
|
|
||||||
# 指尖触觉数据 12x8
|
|
||||||
result['tip_touch'] = [data[idx + i*8: idx + (i+1)*8] for i in range(12)]
|
|
||||||
idx += 96
|
|
||||||
|
|
||||||
# 指中触觉数据 3x3
|
|
||||||
result['middle_touch'] = [data[idx + i*3: idx + (i+1)*3] for i in range(3)]
|
|
||||||
idx += 9
|
|
||||||
|
|
||||||
# 指腹触觉数据 12x8
|
|
||||||
finger_pad = [data[idx + i*8: idx + (i+1)*8] for i in range(12)]
|
|
||||||
idx += 96
|
|
||||||
|
|
||||||
# 指腹触觉数据行元素反转
|
|
||||||
# finger_pad = [row[::-1] for row in finger_pad]
|
|
||||||
# 指腹触觉数据行顺序反转
|
|
||||||
#finger_pad.reverse()
|
|
||||||
|
|
||||||
result['finger_pad'] = finger_pad
|
|
||||||
|
|
||||||
return result
|
|
||||||
|
|
||||||
def format_palm_data(data):
|
|
||||||
"""
|
|
||||||
格式化掌心数据为14x8矩阵,然后转置为8x14矩阵。
|
|
||||||
"""
|
|
||||||
expected_len = 14 * 8
|
|
||||||
if len(data) < expected_len:
|
|
||||||
print(f"掌心数据长度不足,至少{expected_len}个数据,实际:{len(data)}")
|
|
||||||
return None
|
|
||||||
|
|
||||||
# 生成原始矩阵(14行8列)
|
|
||||||
palm_matrix = [data[i*8:(i+1)*8] for i in range(14)]
|
|
||||||
|
|
||||||
# 转置矩阵
|
|
||||||
transposed = list(map(list, zip(*palm_matrix)))
|
|
||||||
|
|
||||||
return transposed
|
|
||||||
|
|
||||||
|
|
||||||
def print_formatted_finger_data(finger_name, formatted_data):
|
|
||||||
if formatted_data is None:
|
|
||||||
print(f"{finger_name} 数据格式化失败")
|
|
||||||
return
|
|
||||||
|
|
||||||
print(f"--- {finger_name} 指端指端数据 (3x3) ---")
|
|
||||||
for row in formatted_data.get('tip_end', []):
|
|
||||||
print(row)
|
|
||||||
|
|
||||||
print(f"--- {finger_name} 指尖触觉数据 (12x8) ---")
|
|
||||||
for row in formatted_data.get('tip_touch', []):
|
|
||||||
print(row)
|
|
||||||
|
|
||||||
if finger_name == "大拇指":
|
|
||||||
if 'middle_touch' in formatted_data:
|
|
||||||
print(f"--- {finger_name} 指中触觉数据 (3x3) ---")
|
|
||||||
for row in formatted_data['middle_touch']:
|
|
||||||
print(row)
|
|
||||||
else:
|
|
||||||
print(f"{finger_name} 指中触觉数据缺失")
|
|
||||||
|
|
||||||
print(f"--- {finger_name} 指腹触觉数据 ({'12x8' if finger_name == '大拇指' else '10x8'}) ---")
|
|
||||||
for row in formatted_data.get('finger_pad', []):
|
|
||||||
print(row)
|
|
||||||
|
|
||||||
def print_formatted_palm_data(palm_data):
|
|
||||||
if palm_data is None:
|
|
||||||
print("掌心数据格式化失败")
|
|
||||||
return
|
|
||||||
|
|
||||||
print("--- 掌心数据 (8x14) ---")
|
|
||||||
for row in palm_data:
|
|
||||||
print(row)
|
|
||||||
|
|
||||||
def read_firmware_version(client):
|
|
||||||
"""
|
|
||||||
读取固件版本,返回十六进制字符串 地址14
|
|
||||||
"""
|
|
||||||
response = client.read_holding_registers(address=14, count=1)
|
|
||||||
if isinstance(response, ExceptionResponse) or response.isError():
|
|
||||||
print(f"读取固件版本失败:{response}")
|
|
||||||
return None
|
|
||||||
else:
|
|
||||||
reg_value = response.registers[0]
|
|
||||||
# 转换为16进制字符串
|
|
||||||
hex_str = format(reg_value, '04X') # 4位,补零
|
|
||||||
return hex_str
|
|
||||||
|
|
||||||
def read_multiple_registers():
|
|
||||||
client = ModbusTcpClient(MODBUS_IP, port=MODBUS_PORT)
|
|
||||||
client.connect()
|
|
||||||
|
|
||||||
try:
|
|
||||||
while True:
|
|
||||||
start_time = time.time()
|
|
||||||
|
|
||||||
# 读取各部分数据
|
|
||||||
pinky_register_values = read_register_range(
|
|
||||||
client,
|
|
||||||
TOUCH_SENSOR_BASE_ADDR_PINKY,
|
|
||||||
TOUCH_SENSOR_END_ADDR_PINKY
|
|
||||||
)
|
|
||||||
ring_register_values = read_register_range(
|
|
||||||
client,
|
|
||||||
TOUCH_SENSOR_BASE_ADDR_RING,
|
|
||||||
TOUCH_SENSOR_END_ADDR_RING
|
|
||||||
)
|
|
||||||
middle_register_values = read_register_range(
|
|
||||||
client,
|
|
||||||
TOUCH_SENSOR_BASE_ADDR_MIDDLE,
|
|
||||||
TOUCH_SENSOR_END_ADDR_MIDDLE
|
|
||||||
)
|
|
||||||
index_register_values = read_register_range(
|
|
||||||
client,
|
|
||||||
TOUCH_SENSOR_BASE_ADDR_INDEX,
|
|
||||||
TOUCH_SENSOR_END_ADDR_INDEX
|
|
||||||
)
|
|
||||||
thumb_register_values = read_register_range(
|
|
||||||
client,
|
|
||||||
TOUCH_SENSOR_BASE_ADDR_THUMB,
|
|
||||||
TOUCH_SENSOR_END_ADDR_THUMB
|
|
||||||
)
|
|
||||||
palm_register_values = read_register_range(
|
|
||||||
client,
|
|
||||||
TOUCH_SENSOR_BASE_ADDR_PALM,
|
|
||||||
TOUCH_SENSOR_END_ADDR_PALM
|
|
||||||
)
|
|
||||||
|
|
||||||
end_time = time.time()
|
|
||||||
frequency = 1 / (end_time - start_time) if end_time > start_time else float('inf')
|
|
||||||
|
|
||||||
# 格式化数据
|
|
||||||
pinky_formatted = format_finger_data("小拇指", pinky_register_values)
|
|
||||||
ring_formatted = format_finger_data("无名指", ring_register_values)
|
|
||||||
middle_formatted = format_finger_data("中指", middle_register_values)
|
|
||||||
index_formatted = format_finger_data("食指", index_register_values)
|
|
||||||
thumb_formatted = format_finger_data("大拇指", thumb_register_values)
|
|
||||||
palm_formatted = format_palm_data(palm_register_values)
|
|
||||||
|
|
||||||
# 打印格式化数据
|
|
||||||
print_formatted_finger_data("小拇指", pinky_formatted)
|
|
||||||
print_formatted_finger_data("无名指", ring_formatted)
|
|
||||||
print_formatted_finger_data("中指", middle_formatted)
|
|
||||||
print_formatted_finger_data("食指", index_formatted)
|
|
||||||
print_formatted_finger_data("大拇指", thumb_formatted)
|
|
||||||
print_formatted_palm_data(palm_formatted)
|
|
||||||
|
|
||||||
print(f"读取频率:{frequency:.2f} Hz")
|
|
||||||
print("\n" + "="*40 + "\n")
|
|
||||||
|
|
||||||
firmware_version_int = read_firmware_version(client)
|
|
||||||
if firmware_version_int is not None:
|
|
||||||
print(f"固件版本:{firmware_version_int}")
|
|
||||||
|
|
||||||
finally:
|
|
||||||
client.close()
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
read_multiple_registers()
|
|
||||||
16
scripts/README.md
Normal file
16
scripts/README.md
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
# 项目脚本
|
||||||
|
|
||||||
|
项目脚本统一放在 `scripts/`,以下命令默认从项目根目录执行。
|
||||||
|
|
||||||
|
| 入口 | 用途 |
|
||||||
|
| --- | --- |
|
||||||
|
| `build.sh` | 默认按 `Debug` 编译,也可指定 `Release` 或 `RelWithDebInfo`,成功后安装到 `output` |
|
||||||
|
| `install.sh` | 原有系统依赖安装及 gRPC 构建脚本 |
|
||||||
|
| `ethercat/` | EtherCAT 启动、停止和状态查看 |
|
||||||
|
| `start_can.sh` | CAN 接口配置 |
|
||||||
|
| `isaac_sim/` | 碰撞几何生成工具,见 [使用说明](isaac_sim/README.md) |
|
||||||
|
| `meshcat/` | URDF 碰撞模型可视化,见 [使用说明](meshcat/README.md) |
|
||||||
|
|
||||||
|
```bash
|
||||||
|
./scripts/build.sh
|
||||||
|
```
|
||||||
31
scripts/build.sh
Executable file
31
scripts/build.sh
Executable file
@ -0,0 +1,31 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
usage() {
|
||||||
|
echo "Usage: $0 [Debug|Release|RelWithDebInfo] (default: Debug)"
|
||||||
|
}
|
||||||
|
|
||||||
|
if [[ $# -eq 1 && ( $1 == --help || $1 == -h ) ]]; then
|
||||||
|
usage
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
if [[ $# -gt 1 ]]; then
|
||||||
|
usage >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
cmvr_build_type="${1:-Debug}"
|
||||||
|
case "$cmvr_build_type" in
|
||||||
|
Debug|Release|RelWithDebInfo) ;;
|
||||||
|
*) usage >&2; exit 1 ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
cmvr_root=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." && pwd)
|
||||||
|
cmvr_build_dir="$cmvr_root/build/$cmvr_build_type"
|
||||||
|
|
||||||
|
cmake -S "$cmvr_root" -B "$cmvr_build_dir" -G "Unix Makefiles" \
|
||||||
|
-DCMAKE_BUILD_TYPE="$cmvr_build_type" \
|
||||||
|
-DCMAKE_INSTALL_PREFIX="$cmvr_root/output"
|
||||||
|
cmake --build "$cmvr_build_dir" --parallel "${CMAKE_BUILD_PARALLEL_LEVEL:-4}"
|
||||||
|
cmake --install "$cmvr_build_dir" --prefix "$cmvr_root/output"
|
||||||
|
|
||||||
|
printf 'Built %s and installed to %s\n' "$cmvr_build_type" "$cmvr_root/output"
|
||||||
@ -4,16 +4,16 @@ set -euo pipefail
|
|||||||
usage() {
|
usage() {
|
||||||
cat <<'USAGE'
|
cat <<'USAGE'
|
||||||
Usage:
|
Usage:
|
||||||
sudo script/ethercat/start_ethercat.sh [iface] [ethercat_dev] [start_wait_sec]
|
sudo scripts/ethercat/start_ethercat.sh [iface] [ethercat_dev] [start_wait_sec]
|
||||||
Any pure numeric argument is treated as start_wait_sec.
|
Any pure numeric argument is treated as start_wait_sec.
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
sudo script/ethercat/start_ethercat.sh eno1
|
sudo scripts/ethercat/start_ethercat.sh eno1
|
||||||
sudo script/ethercat/start_ethercat.sh 10
|
sudo scripts/ethercat/start_ethercat.sh 10
|
||||||
sudo script/ethercat/start_ethercat.sh eno1 10
|
sudo scripts/ethercat/start_ethercat.sh eno1 10
|
||||||
sudo script/ethercat/start_ethercat.sh eno1 /dev/EtherCAT1
|
sudo scripts/ethercat/start_ethercat.sh eno1 /dev/EtherCAT1
|
||||||
sudo script/ethercat/start_ethercat.sh eno1 /dev/EtherCAT0 10
|
sudo scripts/ethercat/start_ethercat.sh eno1 /dev/EtherCAT0 10
|
||||||
sudo script/ethercat/start_ethercat.sh eno1 10 /dev/EtherCAT0
|
sudo scripts/ethercat/start_ethercat.sh eno1 10 /dev/EtherCAT0
|
||||||
|
|
||||||
Environment:
|
Environment:
|
||||||
DEVICE_MODULES=generic IgH device module list.
|
DEVICE_MODULES=generic IgH device module list.
|
||||||
@ -4,7 +4,7 @@ set -euo pipefail
|
|||||||
usage() {
|
usage() {
|
||||||
cat <<'USAGE'
|
cat <<'USAGE'
|
||||||
Usage:
|
Usage:
|
||||||
script/ethercat/status_ethercat.sh
|
scripts/ethercat/status_ethercat.sh
|
||||||
|
|
||||||
Environment:
|
Environment:
|
||||||
IGH_ROOT=... Override bundled IgH install path.
|
IGH_ROOT=... Override bundled IgH install path.
|
||||||
@ -4,11 +4,11 @@ set -euo pipefail
|
|||||||
usage() {
|
usage() {
|
||||||
cat <<'USAGE'
|
cat <<'USAGE'
|
||||||
Usage:
|
Usage:
|
||||||
sudo script/ethercat/stop_ethercat.sh [iface] [--restore-network]
|
sudo scripts/ethercat/stop_ethercat.sh [iface] [--restore-network]
|
||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
sudo script/ethercat/stop_ethercat.sh eno1
|
sudo scripts/ethercat/stop_ethercat.sh eno1
|
||||||
sudo script/ethercat/stop_ethercat.sh eno1 --restore-network
|
sudo scripts/ethercat/stop_ethercat.sh eno1 --restore-network
|
||||||
|
|
||||||
Environment:
|
Environment:
|
||||||
IGH_ROOT=... Override bundled IgH install path.
|
IGH_ROOT=... Override bundled IgH install path.
|
||||||
Loading…
Reference in New Issue
Block a user