Skip to content

Sensor APIs

The sensor APIs are implemented by the following classes. You can find the corresponding header files in the c++/include/drivers/sensors directory to access the complete set of APIs.

Header FileClass NameDescription
sensor_factory.hSensorFactoryA factory class for creating sensor instances of different types.
sensor_interface.hSensorDataBase class for sensor data. All sensor data types should inherit from this class to provide timestamp information.
SensorInterfaceBase class for sensor interfaces, defining common sensor control interfaces. All specific sensors should inherit from this class.
StreamableSensorSensor data stream class, derived from SensorInterface.
camera_data.hRGBDataRGB image data class, derived from SensorData.
RGBDDataRGB-D (Depth) image data class, derived from RGBData.
depth_camera_interface.hDepthCameraDepth camera interface class, inheriting from SensorInterface.

There are two ways to create a sensor instance.

  1. Create a sensor instance by sensor parameters.

    • Method:

      static std::shared_ptr<SensorInterface> create_sensor(
      const std::unordered_map<std::string, std::string>& params)
    • Parameter:

      ParameterTypeDescription

      params

      Input

      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:

      Returns a shared pointer to an object of a class derived from SensorInterface if the instance is created successfully; otherwise, returns nullptr.

  2. Create a sensor instance from a configuration file.

    • Method:

      static std::shared_ptr<SensorInterface> create_sensor_from_config(
      const std::string& config_path)
    • Parameter:

      ParameterTypeDescription

      config_path

      Input

      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:

      Returns a shared pointer to an object of a class derived from SensorInterface if the instance is created successfully; otherwise, returns nullptr.

  • Method:

    AbcErrorCode connect()
  • Return Value:

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

  • Method:

    AbcErrorCode disconnect()
  • Return Value:

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

Register Sensor Data Processing Callback Function

Section titled “Register Sensor Data Processing Callback Function”

This method registers a callback function. When the sensor captures new data, the system automatically invokes this callback for data processing.

  • Method:

    void set_data_callback(SensorCallback cb)
  • Parameter:

    Parameter
    Type
    Description
    cbInputSensorCallback is a function pointer type. For details, please refer to SensorCallback. The callback function is called whenever sensor data update is received.
  • Return Value:

    None (void).

  • Method:

    std::string get_name() const
  • Return Value:

    The name of the sensor instance.

  • Method:

    SensorType get_type() const
  • Return Value:

    The sensor type. For details, please refer to SensorType.

  • Method:

    SensorStatus get_status() const
  • Return Value:

    The sensor status. For details, please refer to SensorStatus.

  • Method:

    void set_status(SensorStatus status)
  • Parameter:

    Parameter
    Type
    Description
    statusInputThe sensor status. For details, please refer to SensorStatus.
  • Return Value:

    None (void).

  • Method:

    std::chrono::system_clock::time_point get_timestamp()
  • Return Value:

    Timestamp.

  • Method:

    void set_timestamp(const std::chrono::system_clock::time_point& timestamp)
  • Parameter:

    Parameter
    Type
    Description
    timestampInputTimestamp.
  • Return Value:

    None (void).

  • Method:

    AbcErrorCode start_stream()
  • Return Value:

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

  • Method:

    AbcErrorCode stop_stream()
  • Return Value:

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

  • Method:

    int get_width() const
  • Return Value:

    Color image width.

  • Method:

    int get_height() const
  • Return Value:

    Color image height.

  • Method:

    int get_channels() const
  • Return Value:

    Number of color image channels.

  • Method:

    std::vector<uint8_t>& get_rgb_data()
  • Return Value:

    Color image data.

  • Method:

    void set_rgb_data(const std::vector<uint8_t>& data)
  • Parameter:

    Parameter
    Type
    Description
    dataInputColor image data.
  • Return Value:

    None (void).

  • Method:

    const AbcIntrinsic& get_color_intrinsic() const
  • Return Value:

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

  • Method:

    void set_color_intrinsic(const AbcIntrinsic& intrinsic)
  • Parameter:

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

    None (void).

  • Method:

    const std::vector<float>& get_depth_data() const
    std::vector<float>& get_depth_data()
  • Return Value:

    Depth image data, in meters.

  • Method:

    void set_depth_data(const std::vector<float>& data)
  • Parameter:

    Parameter
    Type
    Description
    dataInputDepth image data, in meters.
  • Return Value:

    None (void).

  • Method:

    int get_depth_width() const
  • Return Value:

    Depth image width.

  • Method:

    int get_depth_height() const
  • Return Value:

    Depth image height.

  • Method:

    const AbcIntrinsic& get_depth_intrinsic() const
  • Return Value:

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

  • Method:

    void set_depth_intrinsic(const AbcIntrinsic& intrinsic)
  • Parameter:

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

    None (void).

There are two ways to create a depth camera instance.

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

    • Method:

      static std::shared_ptr<DepthCamera> create_depth_camera(
      const DepthSensorParam& param)
    • Parameter:

      Parameter
      Type
      Description
      paramInputParameters related to the depth camera. For details, please refer to DepthSensorParam.
    • Return Value:

      Returns a shared pointer to an object of a class derived from DepthCamera if the instance is created successfully; otherwise, returns nullptr.

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

    • Method:

      static std::shared_ptr<DepthCamera> create_depth_camera_from_config(
      const std::string& config_path)
    • Parameter:

      ParameterTypeDescription

      config_path

      Input

      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:

      Returns a shared pointer to an object of a class derived from DepthCamera if the instance is created successfully; otherwise, returns nullptr.

  • Method:

    std::shared_ptr<const RGBDData> get_data()
  • Return Value:

    A shared pointer to the RGBDData object.

  • Method:

    AbcErrorCode start_stream()
  • Return Value:

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

  • Method:

    AbcErrorCode stop_stream()
  • Return Value:

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

  • Method:

    AbcErrorCode set_color_resolution(int width, int height)
  • Parameters:

    Parameter
    Type
    Description
    widthInputImage width.
    heightInputImage height.
  • Return Value:

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

  • Method:

    AbcErrorCode set_depth_resolution(int width, int height)
  • Parameters:

    Parameter
    Type
    Description
    widthInputImage width.
    heightInputImage height.
  • Return Value:

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

  • Method:

    AbcErrorCode set_framerate(int fps)
  • Parameter:

    Parameter
    Type
    Description
    fpsInputFrame rate.
  • Return Value:

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

  • Method:

    AbcErrorCode set_align_to_color(bool align)
  • Parameter:

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

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

  • Method:

    bool is_aligned_to_color()
  • Return Value:

    true indicates the depth image is aligned to the color image; false indicates it is not.