Skip to content

Sensor APIs

The SensorFactory class is used to create sensor and depth camera instances.

  1. Create a sensor instance by sensor parameters.

    • Method:

      create_sensor(params: dict[str, str]) -> SensorInterface
    • Parameter:

      ParameterDescription
      params

      Parameters related to the sensor, such as:

      {
      "sensor_name":"rs1", # Sensor name
      "sensor_type":"realsense", # Sensor vendor
      "serial_number":"215322070063", # Serial number
      "color_width":"640", # Color image width
      "color_height":"480", # Color image height
      "depth_width":"640", # Depth image width
      "depth_height":"480", # Depth image height
      "align_to_color":"true", # Whether to align depth image to color image
      "frame_rate":"30" # Frame rate
      }
    • Return value:

      A SensorInterface instance if creation succeeds, otherwise None.

  2. Create a sensor instance from a configuration file.

    • Method:

      create_sensor_from_config(config_path: str) -> SensorInterface
    • Parameter:

      ParameterDescription
      params

      Path to the configuration file. The configuration file must be a JSON file.

      {
      "sensor_name":"rs1", # Sensor name
      "sensor_type":"realsense", # Sensor vendor
      "serial_number":"215322070063", # Serial number
      "color_width":"640", # Color image width
      "color_height":"480", # Color image height
      "depth_width":"640", # Depth image width
      "depth_height":"480", # Depth image height
      "align_to_color":"true", # Whether to align depth image to color image
      "frame_rate":"30" # Frame rate
      }
    • Return value:

      A SensorInterface instance if creation succeeds, otherwise None.

  1. Create a depth camera instance by depth camera parameters.

    • Method:

      create_depth_camera(param: DepthSensorParam) -> DepthCamera
    • Parameter:

      Parameter
      Description
      paramParameters related to the depth camera. For details, please refer to DepthSensorParam.
    • Return value:

      A DepthCamera instance if creation succeeds, otherwise None.

  2. Create a depth camera instance from a configuration file.

    • Method:

      create_depth_camera_from_config(config_path: str) -> DepthCamera
    • Parameter:

      ParameterDescription
      params

      Path to the configuration file. The configuration file must be a JSON file.

      {
      "sensor_name":"rs1", # Sensor name
      "sensor_type":"realsense", # Sensor vendor
      "serial_number":"215322070063", # Serial number
      "color_width":"640", # Color image width
      "color_height":"480", # Color image height
      "depth_width":"640", # Depth image width
      "depth_height":"480", # Depth image height
      "align_to_color":"true", # Whether to align depth image to color image
      "frame_rate":"30" # Frame rate
      }
    • Return value:

      A DepthCamera instance if creation succeeds, otherwise None.

The SensorInterface class provides a series of public methods for controlling sensors. Ensure a sensor instance has been created before using these methods.

Attribute (Read-Only)Data TypeDescription
namestrSensor name
statusSensorStatusSensor status
typeSensorTypeSensor type

After creating a sensor instance, you can establish a connection to the sensor using the following method.

  • Method:

    connect(self) -> alphabot.core.AbcErrorCode
  • Return Value:

    AbcErrorCode.SUCCESS indicates success. For other error codes, please refer to AbcErrorCode.

You can disconnect from the sensor using the following method.

  • Method:

    disconnect(self) -> alphabot.core.AbcErrorCode
  • Return Value:

    AbcErrorCode.SUCCESS indicates success. For other error codes, please refer to AbcErrorCode.

The SyncDataPackage class synchronizes robotic arm and sensor data. It supports adding and getting the robotic arm real-time state and sensor data with aligned timestamps.

  • Method:

    get_timestamp(self) -> typing.Any
  • Return Value:

    Timestamp.

  • Method:

    add_sensor_data(self, arg0: str, arg1: SensorData) -> None
  • Parameters:

    Parameter
    Description
    arg0Sensor name.
    arg1Sensor data. For details, please refer to SensorData.
  • Return Value:

    None.

  • Method:

    add_arm_state(self, arg0: str, arg1: alphabot.arm.ArmRealtimeState) -> None
  • Parameters:

    Parameter
    Description
    arg0Robotic arm name.
    arg1Robotic arm real-time state data. For details, please refer to ArmRealtimeState.
  • Return Value:

    None.

  • Method:

    get_sensor_data(self, arg0: str) -> SensorData
  • Parameter:

    Parameter
    Description
    arg0Sensor name
  • Return Value:

    Sensor data. For details, please refer to SensorData.

  • Method:

    get_all_sensor_data(self) -> dict[str, SensorData]
  • Return value:

    A dictionary mapping str keys to SensorData values.

    TypeDescription
    strSensor name.
    SensorDataSensor data. For details, please refer to SensorData.
  • Method:

    get_all_arm_data(self) -> dict[str, alphabot.arm.ArmRealtimeState]
  • Return value:

    A dictionary mapping str keys to ArmRealtimeState values.

    TypeDescription
    strRobotic arm name.
    ArmRealtimeStateRobotic arm real-time state data. For details, please refer to ArmRealtimeState.

Check If Contains Data for Specified Sensor

Section titled “Check If Contains Data for Specified Sensor”
  • Method:

    has_sensor_data(self, arg0: str) -> bool
  • Parameter:

    Parameter
    Description
    arg0Sensor name
  • Return Value:

    True if data exists, False otherwise.

  • Method:

    get_sensor_count(self) -> int
  • Return Value:

    Number of sensors.

  • Method:

    get_arm_count(self) -> int
  • Return Value:

    Number of arms.

The SensorSynchronizer class implements software-based synchronization for data from multiple sensors and the robotic arm.

  • Method:

    __init__(self, sync_policy: typing.Any = None, time_tolerance_ms: int = 10) -> None
  • Parameters:

    Parameter
    Description
    sync_policySynchronization policy. For details, please refer to SyncPolicy.
    time_tolerance_msTime tolerance, in milliseconds.
  • Return Value:

    None.

  • Method:

    add_sensor(self, name: str, sensor: SensorInterface) -> alphabot.core.AbcErrorCode
  • Parameters:

    Parameter
    Description
    nameSensor name.
    sensorA SensorInterface instance.
  • Return Value:

    AbcErrorCode.SUCCESS indicates success. For other error codes, please refer to AbcErrorCode.

  • Method:

    add_arm(self, name: str, arm: alphabot.arm.ArmInterface) -> alphabot.core.AbcErrorCode
  • Parameters:

    Parameter
    Description
    nameRobotic arm name.
    armA ArmInterface instance.
  • Return Value:

    AbcErrorCode.SUCCESS indicates success. For other error codes, please refer to AbcErrorCode.

  • Method:

    remove_sensor(self, name: str) -> alphabot.core.AbcErrorCode
  • Parameter:

    Parameter
    Description
    nameSensor name
  • Return Value:

    AbcErrorCode.SUCCESS indicates success. For other error codes, please refer to AbcErrorCode.

  • Method:

    remove_arm(self, name: str) -> alphabot.core.AbcErrorCode
  • Parameter:

    Parameter
    Description
    nameRobotic arm name
  • Return Value:

    AbcErrorCode.SUCCESS indicates success. For other error codes, please refer to AbcErrorCode.

  • Method:

    get_sensor(self, name: str) -> SensorInterface
  • Parameter:

    Parameter
    Description
    nameSensor name
  • Return Value:

    A SensorInterface instance.

  • Method:

    start(self) -> alphabot.core.AbcErrorCode
  • Return Value:

    AbcErrorCode.SUCCESS indicates success. For other error codes, please refer to AbcErrorCode.

  • Method:

    stop(self) -> alphabot.core.AbcErrorCode
  • Return Value:

    AbcErrorCode.SUCCESS indicates success. For other error codes, please refer to AbcErrorCode.

Register Data Synchronization Callback Function

Section titled “Register Data Synchronization Callback Function”
  • Method:

    set_sync_data_callback(self, arg0: typing.Callable) -> None
  • Parameter:

    Parameter
    Description
    arg0The callback function is called whenever sensor data or robotic arm state data is updated. The callback function receives a parameter of type SyncDataPackage.
  • Return Value:

    None.

  • Method:

    set_sync_policy(self, policy: SyncPolicy) -> None
  • Parameter:

    Parameter
    Description
    policySynchronization policy. For details, please refer to SyncPolicy.
  • Return Value:

    None.

  • Method:

    set_time_tolerance(self, tolerance_ms: int) -> None
  • Parameter:

    Parameter
    Description
    tolerance_msTime tolerance, in milliseconds.
  • Return Value:

    None.

  • Method:

    get_sync_policy(self) -> SyncPolicy
  • Return Value:

    The current synchronization policy. For details, please refer to SyncPolicy.

  • Method:

    get_time_tolerance(self) -> int
  • Return Value:

    Time tolerance, in milliseconds.

  • Method:

    set_sync_mode(self, mode: SyncMode) -> None
  • Parameter:

    Parameter
    Description
    modeSynchronization mode. For details, please refer to SyncMode.
  • Return Value:

    None.

  • Method:

    get_sync_mode(self) -> SyncMode
  • Return Value:

    The current synchronization mode. For details, please refer to SyncMode.

  • Method:

    set_reference_sensor(self, sensor_name: str) -> None
  • Parameter:

    Parameter
    Description
    sensor_nameSensor name
  • Return Value:

    None.

  • Method:

    get_reference_sensor(self) -> str
  • Return Value:

    The name of the reference sensor.

  • Method:

    is_syncing(self) -> bool
  • Return Value:

    true if data is synchronizing, false otherwise.

The SyncPolicy class is an enumerator representing synchronization policies.

Constant MemberValueDescription
NEAREST0Nearest timestamp matching
INTERPOLATE1Interpolation matching
EXTRAPOLATE2Extrapolation matching

The SyncMode class is an enumerator representing synchronization modes.

Constant MemberValueDescription
LATEST_TIMESTAMP0Synchronize based on the latest timestamp (default mode)
REFERENCE_SENSOR1Synchronize based on a reference sensor
AttributeData TypeDescription
sensor_typestrSensor vendor (e.g., "realsense")
sensor_namestrSensor name (e.g., "head_camera")
serial_numberstrSerial number
color_widthintColor image width
color_heightintColor image height
depth_widthintDepth image width
depth_heightintDepth image height
frame_rateintFrame rate
align_to_colorboolWhether to align the depth image to the color image
enable_depthboolWhether to enable the depth stream. Default is True. When set to False, the depth stream and all related logic that depends on depth data will be disabled.
active_pullboolWhether to use active frame pulling mode. Defaults to False (automatic background frame pulling). When set to True, only one frame is fetched when get_data() is called, and the callback mechanism is not supported.
Attribute (Read-Write)Data TypeDescription
timestamptyping.AnyTimestamp

The AbcIntrinsic class represents the intrinsic parameters of a camera.

Structure MemberData TypeDescription
widthintImage width, in pixels.
heightintImage height, in pixels.
ppxfloatHorizontal coordinate of the principal point, expressed as pixel offset from the left edge.
ppyfloatVertical coordinate of the principal point, expressed as pixel offset from the top edge.
fxfloatHorizontal focal length, expressed as a multiple of pixel width.
fyfloatVertical focal length, expressed as a multiple of pixel height.
coeffslist[float]Distortion coefficients. The parameter order for each model is as follows:
- Brown-Conrady model: [k1, k2, p1, p2, k3].
- F-Theta fisheye lens model: [k1, k2, k3, k4, 0].
- Other models: Refer to their specific interpretation rules.

The DepthCamera class inherits from SensorInterface. This section only explains methods that are overridden or newly added in the DepthCamera class.

  • Method:

    connect(self) -> alphabot.core.AbcErrorCode
  • Return Value:

    AbcErrorCode.SUCCESS indicates success. For other error codes, please refer to AbcErrorCode.

  • Method:

    disconnect(self) -> None
  • Return Value:

    None.

  • Method:

    get_data(self) -> RGBDData
  • Return Value:

    Depth image data. For details, please refer to RGBDData.

  • Method:

    start_stream(self) -> alphabot.core.AbcErrorCode
  • Return Value:

    AbcErrorCode.SUCCESS indicates success. For other error codes, please refer to AbcErrorCode.

  • Method:

    stop_stream(self) -> alphabot.core.AbcErrorCode
  • Return Value:

    AbcErrorCode.SUCCESS indicates success. For other error codes, please refer to AbcErrorCode.

  • Method:

    set_color_resolution(self, arg0: int, arg1: int) -> alphabot.core.AbcErrorCode
  • Parameters:

    Parameter
    Description
    arg0Image width
    arg1Image height
  • Return Value:

    AbcErrorCode.SUCCESS indicates success. For other error codes, please refer to AbcErrorCode.

  • Method:

    set_depth_resolution(self, arg0: int, arg1: int) -> alphabot.core.AbcErrorCode
  • Parameters:

    Parameter
    Description
    arg0Image width
    arg1Image height
  • Return Value:

    AbcErrorCode.SUCCESS indicates success. For other error codes, please refer to AbcErrorCode.

  • Method:

    set_framerate(self, arg0: int) -> alphabot.core.AbcErrorCode
  • Parameter:

    Parameter
    Description
    arg0Frame rate
  • Return Value:

    AbcErrorCode.SUCCESS indicates success. For other error codes, please refer to AbcErrorCode.

  • Method:

    set_align_to_color(self, arg0: bool) -> alphabot.core.AbcErrorCode
  • Parameter:

    Parameter
    Description
    arg0Whether to align the depth image to the color image.
  • Return Value:

    AbcErrorCode.SUCCESS indicates success. For other error codes, please refer to AbcErrorCode.

  • Method:

    is_aligned_to_color(self)
  • Return Value:

    True indicates the depth image is aligned to the color image; False indicates it is not.

Register Depth Camera Data Processing Callback Function

Section titled “Register Depth Camera Data Processing Callback Function”
  • Method:

    set_data_callback(self, arg0: typing.Callable) -> None
  • Parameter:

    Parameter
    Description
    arg0The callback function is called whenever depth camera data is updated. The callback function receives a parameter of type RGBDData.
  • Return Value:

    None.

The RGBData class, which inherits from SensorData, encapsulates RGB image data along with the intrinsic parameters of the camera.

AttributeData TypeDescription
height (read-only)intColor image height
width (read-only)intColor image width
channels (read-only)intNumber of color image channels
rgb_data (read-write)numpy.ndarray[numpy.uint8]Color image data (height, width, channels)
  • Method:

    get_color_intrinsic(self) -> AbcIntrinsic
  • Return Value:

    Color camera intrinsic parameters. For details, please refer to AbcIntrinsic.

  • Method:

    set_color_intrinsic(self, arg0: AbcIntrinsic) -> None
  • Parameter:

    Parameter
    Description
    arg0Color camera intrinsic parameters. For details, please refer to AbcIntrinsic.
  • Return Value:

    None.

The RGBDData class, which inherits from RGBData, encapsulates RGB-D images and the intrinsic parameters of the camera.

AttributeData TypeDescription
depth_height (read-only)intDepth image height
depth_width (read-only)intDepth image width
depth_data (read-write)numpy.ndarray[numpy.float32]Depth image data (depth_height, depth_width)
  • Method:

    get_depth_intrinsic(self) -> AbcIntrinsic
  • Return Value:

    Depth camera intrinsic parameters. For details, please refer to AbcIntrinsic.

  • Method:

    set_depth_intrinsic(self, arg0: AbcIntrinsic) -> None
  • Parameter:

    Parameter
    Description
    arg0Depth camera intrinsic parameters. For details, please refer to AbcIntrinsic.
  • Return Value:

    None.