跳转到内容

传感器相关接口

SensorFactory 类用于创建传感器和深度相机实例。

  1. 根据传感器参数,创建传感器实例。

    • 方法原型:

      create_sensor(params: dict[str, str]) -> SensorInterface
    • 参数说明:

      参数名称说明
      params

      传感器相关参数,例如:

      {
      "sensor_name":"rs1", # 传感器名称
      "sensor_type":"realsense", # 传感器厂商
      "serial_number":"215322070063", # 序列号
      "color_width":"640", #彩色图宽
      "color_height":"480", # 彩色图高
      "depth_width":"640", # 深度图宽
      "depth_height":"480", # 深度图高
      "align_to_color":"true", # 是否将深度图对齐到彩色图
      "frame_rate":"30" # 帧率
      }
    • 返回值:

      若创建成功,则返回 SensorInterface 实例;否则返回 None

  2. 根据配置文件,创建传感器实例。

    • 方法原型:

      create_sensor_from_config(config_path: str) -> SensorInterface
    • 参数说明:

      参数名称说明
      config_path

      配置文件路径。配置文件为 JSON 文件,例如:

      {
      "sensor_name":"rs1", # 传感器名称
      "sensor_type":"realsense", # 传感器厂商
      "serial_number":"215322070063", # 序列号
      "color_width":"640", #彩色图宽
      "color_height":"480", # 彩色图高
      "depth_width":"640", # 深度图宽
      "depth_height":"480", # 深度图高
      "align_to_color":"true", # 是否将深度图对齐到彩色图
      "frame_rate":"30" # 帧率
      }
    • 返回值:

      若创建成功,则返回 SensorInterface 实例;否则返回 None

  1. 根据深度相机参数,创建深度相机实例。

    • 方法原型:

      create_depth_camera(param: DepthSensorParam) -> DepthCamera
    • 参数说明:

      参数名称说明
      param深度相机相关参数,具体参见 DepthSensorParam
    • 返回值:

      若创建成功,则返回 DepthCamera 实例;否则返回 None

  2. 根据配置文件,创建深度相机实例。

    • 方法原型:

      create_depth_camera_from_config(config_path: str) -> DepthCamera
    • 参数说明:

      参数名称说明
      config_path

      配置文件路径。配置文件为 JSON 文件,例如:

      {
      "sensor_name":"rs1", # 传感器名称
      "sensor_type":"realsense", # 传感器厂商
      "serial_number":"215322070063", # 序列号
      "color_width":"640", #彩色图宽
      "color_height":"480", # 彩色图高
      "depth_width":"640", # 深度图宽
      "depth_height":"480", # 深度图高
      "align_to_color":"true", # 是否将深度图对齐到彩色图
      "frame_rate":"30" # 帧率
      }
    • 返回值:

      若创建成功,则返回 DepthCamera 实例;否则返回 None

SensorInterface 类提供了一系列用于控制传感器的公共方法。在使用前,请确保已创建传感器实例。

属性(只读)数据类型说明
namestr传感器名称
statusSensorStatus传感器状态
typeSensorType传感器类型

在创建传感器实例后,用户可通过如下方法与传感器建立连接。

  • 方法原型:

    connect(self) -> alphabot.core.AbcErrorCode
  • 返回值:

    AbcErrorCode.SUCCESS 表示成功;其他错误码,请参见 AbcErrorCode

用户可通过如下方法断开与传感器的连接。

  • 方法原型:

    disconnect(self) -> alphabot.core.AbcErrorCode
  • 返回值:

    AbcErrorCode.SUCCESS 表示成功;其他错误码,请参见 AbcErrorCode

SyncDataPackage 类用于同步机械臂和传感器数据,支持添加和查询机械臂实时状态、传感器数据等。

  • 方法原型:

    get_timestamp(self) -> typing.Any
  • 返回值:

    时间戳。

  • 方法原型:

    add_sensor_data(self, arg0: str, arg1: SensorData) -> None
  • 参数说明:

    参数名称说明
    arg0传感器名称。
    arg1传感器数据,具体参见 SensorData
  • 返回值:

    None

  • 方法原型:

    add_arm_state(self, arg0: str, arg1: alphabot.arm.ArmRealtimeState) -> None
  • 参数说明:

    参数名称说明
    arg0机械臂名称。
    arg1机械臂实时状态数据,具体参见 ArmRealtimeState
  • 返回值:

    None

  • 方法原型:

    get_sensor_data(self, arg0: str) -> SensorData
  • 参数说明:

    参数名称说明
    arg0传感器名称
  • 返回值:

    传感器数据,具体参见 SensorData

  • 方法原型:

    get_all_sensor_data(self) -> dict[str, SensorData]
  • 返回值:

    键为 str 类型、值为 SensorData 类型的字典。

    类型说明
    str传感器名称。
    SensorData传感器数据,具体参见 SensorData
  • 方法原型:

    get_all_arm_data(self) -> dict[str, alphabot.arm.ArmRealtimeState]
  • 返回值:

    键为 str 类型、值为 ArmRealtimeState 类型的字典。

    类型说明
    str机械臂名称。
    ArmRealtimeState机械臂实时状态数据,具体参见 ArmRealtimeState

检查是否包含指定传感器的数据

Section titled “检查是否包含指定传感器的数据”
  • 方法原型:

    has_sensor_data(self, arg0: str) -> bool
  • 参数说明:

    参数名称说明
    arg0传感器名称
  • 返回值:

    True 表示包含,False 表示不包含。

  • 方法原型:

    get_sensor_count(self) -> int
  • 返回值:

    传感器数量。

  • 方法原型:

    get_arm_count(self) -> int
  • 返回值:

    机械臂数量。

SensorSynchronizer 类是一个多传感器数据同步管理器,用于协调多个传感器和机械臂的数据同步。

  • 方法原型:

    __init__(self, sync_policy: typing.Any = None, time_tolerance_ms: int = 10) -> None
  • 参数说明:

    参数名称说明
    sync_policy同步策略,具体参见 SyncPolicy
    time_tolerance_ms时间容差,单位为毫秒。
  • 返回值:

    None

  • 方法原型:

    add_sensor(self, name: str, sensor: SensorInterface) -> alphabot.core.AbcErrorCode
  • 参数说明:

    参数名称说明
    name传感器名称。
    sensor传感器接口实例,具体参见 SensorInterface
  • 返回值:

    AbcErrorCode.SUCCESS 表示成功;其他错误码,请参见 AbcErrorCode

  • 方法原型:

    add_arm(self, name: str, arm: alphabot.arm.ArmInterface) -> alphabot.core.AbcErrorCode
  • 参数说明:

    参数名称说明
    name机械臂名称。
    arm机械臂接口实例,具体参见 ArmInterface
  • 返回值:

    AbcErrorCode.SUCCESS 表示成功;其他错误码,请参见 AbcErrorCode

  • 方法原型:

    remove_sensor(self, name: str) -> alphabot.core.AbcErrorCode
  • 参数说明:

    参数名称说明
    name传感器名称
  • 返回值:

    AbcErrorCode.SUCCESS 表示成功;其他错误码,请参见 AbcErrorCode

  • 方法原型:

    remove_arm(self, name: str) -> alphabot.core.AbcErrorCode
  • 参数说明:

    参数名称说明
    name机械臂名称
  • 返回值:

    AbcErrorCode.SUCCESS 表示成功;其他错误码,请参见 AbcErrorCode

  • 方法原型:

    get_sensor(self, name: str) -> SensorInterface
  • 参数说明:

    参数名称说明
    name传感器名称
  • 返回值:

    传感器接口实例,具体参见 SensorInterface

  • 方法原型:

    start(self) -> alphabot.core.AbcErrorCode
  • 返回值:

    AbcErrorCode.SUCCESS 表示成功;其他错误码,请参见 AbcErrorCode

  • 方法原型:

    stop(self) -> alphabot.core.AbcErrorCode
  • 返回值:

    AbcErrorCode.SUCCESS 表示成功;其他错误码,请参见 AbcErrorCode

  • 方法原型:

    set_sync_data_callback(self, arg0: typing.Callable) -> None
  • 参数说明:

    参数名称
    说明
    arg0当传感器数据或机械臂状态数据更新时,系统会自动调用此回调函数。回调函数接收类型为 SyncDataPackage 的参数。
  • 返回值:

    None

  • 方法原型:

    set_sync_policy(self, policy: SyncPolicy) -> None
  • 参数说明:

    参数名称说明
    policy同步策略,具体参见 SyncPolicy
  • 返回值:

    None

  • 方法原型:

    set_time_tolerance(self, tolerance_ms: int) -> None
  • 参数说明:

    参数名称说明
    tolerance_ms时间容差,单位为毫秒。
  • 返回值:

    None

  • 方法原型:

    get_sync_policy(self) -> SyncPolicy
  • 返回值:

    同步策略,具体参见 SyncPolicy

  • 方法原型:

    get_time_tolerance(self) -> int
  • 返回值:

    时间容差,单位为毫秒。

  • 方法原型:

    set_sync_mode(self, mode: SyncMode) -> None
  • 参数说明:

    参数名称说明
    mode同步模式,具体参见 SyncMode
  • 返回值:

    None

  • 方法原型:

    get_sync_mode(self) -> SyncMode
  • 返回值:

    同步模式,具体参见 SyncMode

  • 方法原型:

    set_reference_sensor(self, sensor_name: str) -> None
  • 参数说明:

    参数名称说明
    sensor_name传感器名称
  • 返回值:

    None

  • 方法原型:

    get_reference_sensor(self) -> str
  • 返回值:

    参考传感器名称。

  • 方法原型:

    is_syncing(self) -> bool
  • 返回值:

    True 表示正在同步,False 表示未同步。

SyncPolicy 类是一个枚举器,用于表示同步策略。

常量成员说明
NEAREST0最近时间戳匹配
INTERPOLATE1插值匹配
EXTRAPOLATE2外推匹配

SyncMode 类是一个枚举器,用于表示同步模式。

常量成员说明
LATEST_TIMESTAMP0基于最新时间戳同步(默认模式)
REFERENCE_SENSOR1基于参考传感器同步
属性
数据类型
说明
sensor_typestr传感器类型,例如 "realsense"
sensor_namestr传感器名称,例如 "head_camera"
serial_numberstr序列号。
color_widthint彩色图的宽。
color_heightint彩色图的高。
depth_widthint深度图的宽。
depth_heightint深度图的高。
frame_rateint帧率。
align_to_colorbool是否将深度图对齐到彩色图。
enable_depthbool是否启用深度流。默认为 True;设置为 False 时,深度流及所有依赖深度数据的相关逻辑将被关闭。
active_pullbool是否采用主动拉流模式。默认为 False(后台自动拉流);设置为 True 时,仅在调用 get_data() 时拉取一帧,且不支持回调机制。
属性(可读写)数据类型说明
timestamptyping.Any时间戳

AbcIntrinsic 类用于表示相机内参数据,包含以下属性。

结构体成员数据类型说明
widthint图像宽度,单位为像素。
heightint图像高度,单位为像素。
ppxfloat图像主点的水平坐标,以距左边缘的像素偏移量表示。
ppyfloat图像主点的垂直坐标,以距上边缘的像素偏移量表示。
fxfloat水平焦距,以像素宽度倍数表示。
fyfloat垂直焦距,以像素高度倍数表示。
coeffslist[float]畸变系数,列表长度固定为 5。各模型的参数顺序如下。
- Brown-Conrady 模型:[k1, k2, p1, p2, k3]
- F-Theta 鱼眼镜头模型:[k1, k2, k3, k4, 0]
- 其他模型:参见其具体解释规则。

DepthCamera 是一个深度相机传感器类,继承自 SensorInterface。本节只讲解 DepthCamera 类中重写或新增的方法。

  • 方法原型:

    connect(self) -> alphabot.core.AbcErrorCode
  • 返回值:

    AbcErrorCode.SUCCESS 表示成功;其他错误码,请参见 AbcErrorCode

  • 方法原型:

    disconnect(self) -> None
  • 返回值:

    None

  • 方法原型:

    get_data(self) -> RGBDData
  • 返回值:

    深度图像数据,具体参见 RGBDData

  • 方法原型:

    start_stream(self) -> alphabot.core.AbcErrorCode
  • 返回值:

    AbcErrorCode.SUCCESS 表示成功;其他错误码,请参见 AbcErrorCode

  • 方法原型:

    stop_stream(self) -> alphabot.core.AbcErrorCode
  • 返回值:

    AbcErrorCode.SUCCESS 表示成功;其他错误码,请参见 AbcErrorCode

  • 方法原型:

    set_color_resolution(self, arg0: int, arg1: int) -> alphabot.core.AbcErrorCode
  • 参数说明:

    参数名称说明
    arg0宽度
    arg1高度
  • 返回值:

    AbcErrorCode.SUCCESS 表示成功;其他错误码,请参见 AbcErrorCode

  • 方法原型:

    set_depth_resolution(self, arg0: int, arg1: int) -> alphabot.core.AbcErrorCode
  • 参数说明:

    参数名称说明
    arg0宽度
    arg1高度
  • 返回值:

    AbcErrorCode.SUCCESS 表示成功;其他错误码,请参见 AbcErrorCode

  • 方法原型:

    set_framerate(self, arg0: int) -> alphabot.core.AbcErrorCode
  • 参数说明:

    参数名称说明
    arg0帧率
  • 返回值:

    AbcErrorCode.SUCCESS 表示成功;其他错误码,请参见 AbcErrorCode

  • 方法原型:

    set_align_to_color(self, arg0: bool) -> alphabot.core.AbcErrorCode
  • 参数说明:

    参数名称说明
    arg0是否将深度图像对齐到彩色图像
  • 返回值:

    AbcErrorCode.SUCCESS 表示成功;其他错误码,请参见 AbcErrorCode

  • 方法原型:

    is_aligned_to_color(self) -> bool
  • 返回值:

    True 表示深度图像已对齐到彩色图像,False 表示深度图像未对齐到彩色图像。

注册深度相机数据处理回调函数

Section titled “注册深度相机数据处理回调函数”
  • 方法原型:

    set_data_callback(self, arg0: typing.Callable) -> None
  • 参数说明:

    参数名称
    说明
    arg0当深度相机数据更新时,系统会自动调用此回调函数。回调函数接收类型为 RGBDData 的参数。
  • 返回值:

    None

RGBData 是一个彩色图像数据类,继承自 SensorData。它封装了 RGB(红绿蓝)格式的图像数据以及相机内参。

属性数据类型说明
height(只读)int彩色图像高度
width(只读)int彩色图像宽度
channels(只读)int彩色图像通道数
rgb_data(可读写)numpy.ndarray[numpy.uint8]彩色图像数据 (height, width, channels)
  • 方法原型:

    get_color_intrinsic(self) -> AbcIntrinsic
  • 返回值:

    彩色相机内参,具体参见 AbcIntrinsic

  • 方法原型:

    set_color_intrinsic(self, arg0: AbcIntrinsic) -> None
  • 参数说明:

    参数名称说明
    arg0彩色相机内参,具体参见 AbcIntrinsic
  • 返回值:

    None

RGBDData 是一个 RGB-D(彩色+深度)图像数据类,继承自 RGBData。它封装了彩色图像、深度图像以及相机内参信息。

属性数据类型说明
depth_height(只读)int深度图像高度
depth_width(只读)int深度图像宽度
depth_data(可读写)numpy.ndarray[numpy.float32]深度图像数据 (depth_height, depth_width)
  • 方法原型:

    get_depth_intrinsic(self) -> AbcIntrinsic
  • 返回值:

    深度相机内参,具体参见 AbcIntrinsic

  • 方法原型:

    set_depth_intrinsic(self, arg0: AbcIntrinsic) -> None
  • 参数说明:

    参数名称说明
    arg0深度相机内参,具体参见 AbcIntrinsic
  • 返回值:

    None