坐标转换

坐标转换 API 参考文档

模块:convert_transform_api — 相机坐标系 → 机械臂基坐标系

1. 类方法

类方法 CameraToBaseConverter.from_json()
CameraToBaseConverter.from_json(config_path)
参数 类型 必需 说明
config_path str / Path 是 JSON 配置文件路径(包含旋转矩阵、平移向量、单位设置等)
CameraToBaseConverter — 转换器实例
Python
from convert_transform_api.convert_transform_api import CameraToBaseConverter

converter = CameraToBaseConverter.from_json("coordinate_transform.json")
print("转换器已加载")
💡 提示:需先准备 JSON 配置文件,格式见附录 §4。

2. 实例方法

实例方法 converter.cam_point_to_base()
result = converter.cam_point_to_base(camera_point, ee_pose, output_unit="mm")
参数 类型 必需 默认值 说明
camera_point Sequence[float] 是 — 相机坐标系下的 3D 点 [x, y, z],单位由配置文件决定
ee_pose Sequence[float] 是 — 机械臂末端位姿 [x, y, z, rx, ry, rz]
output_unit str 否 配置值 输出位置单位,可选 'mm' 或 'm'
{ "ok": True, "camera_point_m": [x, y, z], "camera_point_mm": [x, y, z], "point_ee_m": [x, y, z], "point_ee_mm": [x, y, z], "point_base_m": [x, y, z], "point_base_mm": [x, y, z], "point_base": [x, y, z], "point_base_unit": "mm", "pose_base_mrad": [x, y, z, 0, 0, 0], "pose_base_mmrad": [x, y, z, 0, 0, 0], "pose_base": [x, y, z, 0, 0, 0], "pose_base_unit": "mm/rad" }
Python
# 创建转换器
converter = CameraToBaseConverter.from_json("coordinate_transform.json")

# 相机坐标点 → 基坐标系点
result = converter.cam_point_to_base(
    camera_point=[0.1, 0.2, 0.7],                        # 相机坐标(米)
    ee_pose=[-117.0, 0.0, 520.0, 3.141, 1.570, 0.0],  # 末端位姿(毫米/弧度)
    output_unit="mm"
)

base_point = result["point_base"]
print(f"基座坐标: X={base_point[0]:.2f}, Y={base_point[1]:.2f}, Z={base_point[2]:.2f} mm")
实例方法 converter.cam_pose_to_base()
result = converter.cam_pose_to_base(camera_pose, ee_pose, output_unit="mm", output_euler_mode="fixed_xyz")
参数 类型 必需 默认值 说明
camera_pose Sequence[float] 是 — 相机坐标系下的物体位姿 [x, y, z, rx, ry, rz]
ee_pose Sequence[float] 是 — 机械臂末端位姿 [x, y, z, rx, ry, rz]
output_unit str 否 配置值 输出位置单位,可选 'mm' 或 'm'
output_euler_mode str 否 配置值 输出欧拉角模式,如 'fixed_xyz'、'fixed_zyx_abc_xyz'
{ // 同 cam_point_to_base 的所有字段 + 姿态信息 "ok": True, "pose_base": [x, y, z, rx, ry, rz], "pose_base_unit": "mm/rad", // ... 还包含多种单位/格式的中间结果 }
Python
result = converter.cam_pose_to_base(
    camera_pose=[0.1, 0.2, 0.7, 0.0, 0.0, 0.0],           # 相机位姿(米/弧度)
    ee_pose=[-117.0, 0.0, 520.0, 3.141, 1.570, 0.0],     # 末端位姿(毫米/弧度)
    output_unit="mm",
    output_euler_mode="fixed_xyz"
)

base_pose = result["pose_base"]
print(f"基座位姿: X={base_pose[0]:.2f}, Y={base_pose[1]:.2f}, Z={base_pose[2]:.2f}")
print(f"基座姿态: Rx={base_pose[3]:.4f}, Ry={base_pose[4]:.4f}, Rz={base_pose[5]:.4f}")

3. 兼容函数

独立函数 convert_camera_to_base()
x, y, z = convert_camera_to_base(x, y, z, ee_pose, config_path, output_unit)
参数 类型 必需 默认值 说明
x float 是 — 相机坐标系 X 坐标
y float 是 — 相机坐标系 Y 坐标
z float 是 — 相机坐标系 Z 坐标
ee_pose Sequence[float] 是 — 机械臂末端位姿 [x, y, z, rx, ry, rz]
config_path str 否 默认配置 JSON 配置文件路径(如不传则使用模块默认配置)
output_unit str 否 配置值 输出单位 'mm' 或 'm'
tuple[float, float, float] — 基坐标系下的 (X, Y, Z) 坐标
Python
from convert_transform_api.convert_transform_api import convert_camera_to_base

x, y, z = convert_camera_to_base(
    x=0.1,
    y=0.2,
    z=0.7,
    ee_pose=[-117.0, 0.0, 520.0, 3.141, 1.570, 0.0]
)
print(f"基座坐标: X={x:.2f}, Y={y:.2f}, Z={z:.2f} mm")

4. 附录 — JSON 配置文件格式

coordinate_transform.json
JSON
{
    "convert": {
        // 相机→末端 旋转矩阵 (3×3)
        "rotation_cam_to_ee": [
            [0.0, -1.0, 0.0],
            [1.0,  0.0,  0.0],
            [0.0,  0.0,  1.0]
        ],
        // 相机→末端 平移向量(米)
        "translation_cam_to_ee_m": [-0.083, 0.035, -0.02],

        // 以下为输入/输出单位设置
        "camera_point_unit": "m",       // 相机坐标输入单位
        "ee_position_unit": "mm",      // 末端位置输入单位
        "ee_angle_unit": "rad",         // 末端角度输入单位
        "output_position_unit": "mm",   // 输出位置单位
        "ee_euler_mode": "fixed_zyx_abc_xyz"  // 末端欧拉角模式
    }
}
💡 提示:旋转矩阵 rotation_cam_to_ee 和平移向量 translation_cam_to_ee_m 需根据实际相机安装位置进行标定。请参考相机外参标定流程获取正确的值。

5. 依赖安装

Shell
pip install numpy scipy
四川天链机器人股份有限公司  |  坐标转换 API 文档 Ver1.0.0