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 File | Class Name | Description |
sensor_factory.h | SensorFactory | A factory class for creating sensor instances of different types. |
sensor_interface.h | SensorData | Base class for sensor data. All sensor data types should inherit from this class to provide timestamp information. |
SensorInterface | Base class for sensor interfaces, defining common sensor control interfaces. All specific sensors should inherit from this class. | |
StreamableSensor | Sensor data stream class, derived from SensorInterface. | |
camera_data.h | RGBData | RGB image data class, derived from SensorData. |
RGBDData | RGB-D (Depth) image data class, derived from RGBData. | |
depth_camera_interface.h | DepthCamera | Depth camera interface class, inheriting from SensorInterface. |
Sensors
Section titled “Sensors”Create a Sensor Instance
Section titled “Create a Sensor Instance”There are two ways to create a sensor instance.
-
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:
Parameter Type Description paramsInput
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
SensorInterfaceif the instance is created successfully; otherwise, returnsnullptr.
-
-
Create a sensor instance from a configuration file.
-
Method:
static std::shared_ptr<SensorInterface> create_sensor_from_config(const std::string& config_path) -
Parameter:
Parameter Type Description config_pathInput
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
SensorInterfaceif the instance is created successfully; otherwise, returnsnullptr.
-
Connect to the Sensor
Section titled “Connect to the Sensor”-
Method:
AbcErrorCode connect() -
Return Value:
AbcErrorCode::SUCCESSindicates success. For other error codes, please refer to AbcErrorCode.
Disconnect from the Sensor
Section titled “Disconnect from the Sensor”-
Method:
AbcErrorCode disconnect() -
Return Value:
AbcErrorCode::SUCCESSindicates 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:
ParameterTypeDescription cbInput SensorCallbackis 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).
Get Sensor Name
Section titled “Get Sensor Name”-
Method:
std::string get_name() const -
Return Value:
The name of the sensor instance.
Get Sensor Type
Section titled “Get Sensor Type”-
Method:
SensorType get_type() const -
Return Value:
The sensor type. For details, please refer to SensorType.
Get Sensor Status
Section titled “Get Sensor Status”-
Method:
SensorStatus get_status() const -
Return Value:
The sensor status. For details, please refer to SensorStatus.
Set Sensor Status
Section titled “Set Sensor Status”-
Method:
void set_status(SensorStatus status) -
Parameter:
ParameterTypeDescription statusInput The sensor status. For details, please refer to SensorStatus. -
Return Value:
None (void).
Sensor Data
Section titled “Sensor Data”Get Data Timestamp
Section titled “Get Data Timestamp”-
Method:
std::chrono::system_clock::time_point get_timestamp() -
Return Value:
Timestamp.
Set Data Timestamp
Section titled “Set Data Timestamp”-
Method:
void set_timestamp(const std::chrono::system_clock::time_point& timestamp) -
Parameter:
ParameterTypeDescription timestampInput Timestamp. -
Return Value:
None (void).
Sensor Data Stream
Section titled “Sensor Data Stream”Start Data Stream
Section titled “Start Data Stream”-
Method:
AbcErrorCode start_stream() -
Return Value:
AbcErrorCode::SUCCESSindicates success. For other error codes, please refer to AbcErrorCode.
Stop Data Stream
Section titled “Stop Data Stream”-
Method:
AbcErrorCode stop_stream() -
Return Value:
AbcErrorCode::SUCCESSindicates success. For other error codes, please refer to AbcErrorCode.
Image Data
Section titled “Image Data”Get Color Image Width
Section titled “Get Color Image Width”-
Method:
int get_width() const -
Return Value:
Color image width.
Get Color Image Height
Section titled “Get Color Image Height”-
Method:
int get_height() const -
Return Value:
Color image height.
Get Color Image Channels
Section titled “Get Color Image Channels”-
Method:
int get_channels() const -
Return Value:
Number of color image channels.
Get Color Image Data
Section titled “Get Color Image Data”-
Method:
std::vector<uint8_t>& get_rgb_data() -
Return Value:
Color image data.
Set Color Image Data
Section titled “Set Color Image Data”-
Method:
void set_rgb_data(const std::vector<uint8_t>& data) -
Parameter:
ParameterTypeDescription dataInput Color image data. -
Return Value:
None (void).
Get Color Camera Intrinsic Parameters
Section titled “Get Color Camera Intrinsic Parameters”-
Method:
const AbcIntrinsic& get_color_intrinsic() const -
Return Value:
Color camera intrinsic parameters. For details, please refer to AbcIntrinsic.
Set Color Camera Intrinsic Parameters
Section titled “Set Color Camera Intrinsic Parameters”-
Method:
void set_color_intrinsic(const AbcIntrinsic& intrinsic) -
Parameter:
ParameterTypeDescription intrinsicInput Color camera intrinsic parameters. For details, please refer to AbcIntrinsic. -
Return Value:
None (void).
Get Depth Image Data
Section titled “Get Depth Image Data”-
Method:
const std::vector<float>& get_depth_data() conststd::vector<float>& get_depth_data() -
Return Value:
Depth image data, in meters.
Set Depth Image Data
Section titled “Set Depth Image Data”-
Method:
void set_depth_data(const std::vector<float>& data) -
Parameter:
ParameterTypeDescription dataInput Depth image data, in meters. -
Return Value:
None (void).
Get Depth Image Width
Section titled “Get Depth Image Width”-
Method:
int get_depth_width() const -
Return Value:
Depth image width.
Get Depth Image Height
Section titled “Get Depth Image Height”-
Method:
int get_depth_height() const -
Return Value:
Depth image height.
Get Depth Camera Intrinsic Parameters
Section titled “Get Depth Camera Intrinsic Parameters”-
Method:
const AbcIntrinsic& get_depth_intrinsic() const -
Return Value:
Depth camera intrinsic parameters. For details, please refer to AbcIntrinsic.
Set Depth Camera Intrinsic Parameters
Section titled “Set Depth Camera Intrinsic Parameters”-
Method:
void set_depth_intrinsic(const AbcIntrinsic& intrinsic) -
Parameter:
ParameterTypeDescription intrinsicInput Depth camera intrinsic parameters. For details, please refer to AbcIntrinsic. -
Return Value:
None (void).
Depth Camera
Section titled “Depth Camera”Create a Depth Camera Instance
Section titled “Create a Depth Camera Instance”There are two ways to create a depth camera instance.
-
Create a depth camera instance by depth camera parameters.
-
Method:
static std::shared_ptr<DepthCamera> create_depth_camera(const DepthSensorParam& param) -
Parameter:
ParameterTypeDescription paramInput Parameters 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
DepthCameraif the instance is created successfully; otherwise, returnsnullptr.
-
-
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:
Parameter Type Description config_pathInput
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
DepthCameraif the instance is created successfully; otherwise, returnsnullptr.
-
Get Depth Image Data
Section titled “Get Depth Image Data”-
Method:
std::shared_ptr<const RGBDData> get_data() -
Return Value:
A shared pointer to the
RGBDDataobject.
Start Data Stream
Section titled “Start Data Stream”-
Method:
AbcErrorCode start_stream() -
Return Value:
AbcErrorCode::SUCCESSindicates success. For other error codes, please refer to AbcErrorCode.
Stop Data Stream
Section titled “Stop Data Stream”-
Method:
AbcErrorCode stop_stream() -
Return Value:
AbcErrorCode::SUCCESSindicates success. For other error codes, please refer to AbcErrorCode.
Set Color Image Resolution
Section titled “Set Color Image Resolution”-
Method:
AbcErrorCode set_color_resolution(int width, int height) -
Parameters:
ParameterTypeDescription widthInput Image width. heightInput Image height. -
Return Value:
AbcErrorCode::SUCCESSindicates success. For other error codes, please refer to AbcErrorCode.
Set Depth Image Resolution
Section titled “Set Depth Image Resolution”-
Method:
AbcErrorCode set_depth_resolution(int width, int height) -
Parameters:
ParameterTypeDescription widthInput Image width. heightInput Image height. -
Return Value:
AbcErrorCode::SUCCESSindicates success. For other error codes, please refer to AbcErrorCode.
Set Frame Rate
Section titled “Set Frame Rate”-
Method:
AbcErrorCode set_framerate(int fps) -
Parameter:
ParameterTypeDescription fpsInput Frame rate. -
Return Value:
AbcErrorCode::SUCCESSindicates success. For other error codes, please refer to AbcErrorCode.
Set Depth Image Alignment to Color Image
Section titled “Set Depth Image Alignment to Color Image”-
Method:
AbcErrorCode set_align_to_color(bool align) -
Parameter:
ParameterTypeDescription alignInput Whether to align the depth image to the color image. -
Return Value:
AbcErrorCode::SUCCESSindicates success. For other error codes, please refer to AbcErrorCode.
Get Current Alignment Setting
Section titled “Get Current Alignment Setting”-
Method:
bool is_aligned_to_color() -
Return Value:
trueindicates the depth image is aligned to the color image;falseindicates it is not.