数据结构
本页只列 Python 侧最常用的容器类型与返回形态;完整定义以官方
nrc_interface.py的类定义为准(该文件是 SWIG 生成的包装,Vector*与 C++ 的std::vector<T>一一对应)。
1. 容器类型(nrc_interface.py 第 121–1171 行)
| 类 | 元素类型 | 典型用途 |
|---|---|---|
VectorChar | char | 字节序列 |
VectorInt | int | 整型数组(IO 列表、状态对等) |
VectorDouble | double | 点位 / 速度 / 力矩等浮点数组(最常用) |
VectorString | string | 字符串数组 |
VectorCondition / VectorVectorCondition | 结构体 | 条件 / 条件组 |
VectorVectorInt | VectorInt | 二维整型 |
VectorAlarmdIO | 结构体 | 报警与 IO |
VectorRemoteProgram* | 结构体 | 远程程序 |
Conveyor* / LaserCutting* | 结构体 | 传送带 / 激光切割参数 |
2. 通用行为(所有 Vector* 一致)
python
import nrc_interface
pos = nrc_interface.VectorDouble(7) # 预分配长度(与接口要求的 pos 长度一致)
len(pos) # 7
pos[0] = 1.5 # 按下标读写
list(pos) # 转成 Python list,后续计算更自然3. 返回值形态(最容易踩的坑)
| 情形 | 返回 | 数据在哪 |
|---|---|---|
单输出 getter(如 get_current_position(fd, coord, pos)) | int 结果码(SUCCESS = 0) | 写进你传入的容器 pos |
| 多输出 getter | list,形如 [结果码, 值](不是 tuple) | 用 ret[0] / ret[1] 取值 |
python
pos = nrc_interface.VectorDouble(7)
ret = nrc_interface.get_current_position(fd, 0, pos) # ret 是 int 结果码
ret2 = nrc_interface.get_servo_state(...) # 例:[0, 3]
code, value = ret2[0], ret2[1]不要互相推断:同一接口在不同语言封装里的返回形态可能不同。 写业务前先跑一次探针,打印
type(x)与repr(x);判类型请用isinstance(x, (tuple, list))(只判tuple会漏掉list)。 点位单位不自带标志,见 核心概念 §位置单位 与 基础连接与系统接口 的表注。