Sensor APIs
SensorFactory
Section titled “SensorFactory”The SensorFactory class is used to create sensor and depth camera instances.
Create a Sensor Instance
Section titled “Create a Sensor Instance”-
Create a sensor instance by sensor parameters.
-
Method:
create_sensor(params: dict[str, str]) -> SensorInterface -
Parameter:
Parameter Description paramsParameters 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.
-
-
Create a sensor instance from a configuration file.
-
Method:
create_sensor_from_config(config_path: str) -> SensorInterface -
Parameter:
Parameter Description paramsPath 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.
-
Create a Depth Camera Instance
Section titled “Create a Depth Camera Instance”-
Create a depth camera instance by depth camera parameters.
-
Method:
create_depth_camera(param: DepthSensorParam) -> DepthCamera -
Parameter:
ParameterDescription paramParameters related to the depth camera. For details, please refer to DepthSensorParam. -
Return value:
A DepthCamera instance if creation succeeds, otherwise
None.
-
-
Create a depth camera instance from a configuration file.
-
Method:
create_depth_camera_from_config(config_path: str) -> DepthCamera -
Parameter:
Parameter Description paramsPath 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.
-
SensorInterface
Section titled “SensorInterface”The SensorInterface class provides a series of public methods for controlling sensors. Ensure a sensor instance has been created before using these methods.
Attributes
Section titled “Attributes”| Attribute (Read-Only) | Data Type | Description |
|---|---|---|
name | str | Sensor name |
status | SensorStatus | Sensor status |
type | SensorType | Sensor type |
Connect to the Sensor
Section titled “Connect to the Sensor”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.SUCCESSindicates success. For other error codes, please refer to AbcErrorCode.
Disconnect from the Sensor
Section titled “Disconnect from the Sensor”You can disconnect from the sensor using the following method.
-
Method:
disconnect(self) -> alphabot.core.AbcErrorCode -
Return Value:
AbcErrorCode.SUCCESSindicates success. For other error codes, please refer to AbcErrorCode.
SyncDataPackage
Section titled “SyncDataPackage”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.
Get Package Timestamp
Section titled “Get Package Timestamp”-
Method:
get_timestamp(self) -> typing.Any -
Return Value:
Timestamp.
Add Sensor Data
Section titled “Add Sensor Data”-
Method:
add_sensor_data(self, arg0: str, arg1: SensorData) -> None -
Parameters:
ParameterDescription arg0Sensor name. arg1Sensor data. For details, please refer to SensorData. -
Return Value:
None.
Add Robotic Arm Real-time State Data
Section titled “Add Robotic Arm Real-time State Data”-
Method:
add_arm_state(self, arg0: str, arg1: alphabot.arm.ArmRealtimeState) -> None -
Parameters:
ParameterDescription arg0Robotic arm name. arg1Robotic arm real-time state data. For details, please refer to ArmRealtimeState. -
Return Value:
None.
Get Sensor Data
Section titled “Get Sensor Data”-
Method:
get_sensor_data(self, arg0: str) -> SensorData -
Parameter:
ParameterDescription arg0Sensor name -
Return Value:
Sensor data. For details, please refer to SensorData.
Get All Sensor Data
Section titled “Get All Sensor Data”-
Method:
get_all_sensor_data(self) -> dict[str, SensorData] -
Return value:
A dictionary mapping
strkeys toSensorDatavalues.Type Description strSensor name. SensorDataSensor data. For details, please refer to SensorData.
Get All Robotic Arm Real-time State Data
Section titled “Get All Robotic Arm Real-time State Data”-
Method:
get_all_arm_data(self) -> dict[str, alphabot.arm.ArmRealtimeState] -
Return value:
A dictionary mapping
strkeys toArmRealtimeStatevalues.Type Description 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:
ParameterDescription arg0Sensor name -
Return Value:
Trueif data exists,Falseotherwise.
Get Sensor Count in Data Package
Section titled “Get Sensor Count in Data Package”-
Method:
get_sensor_count(self) -> int -
Return Value:
Number of sensors.
Get Arm Count in Data Package
Section titled “Get Arm Count in Data Package”-
Method:
get_arm_count(self) -> int -
Return Value:
Number of arms.
SensorSynchronizer
Section titled “SensorSynchronizer”The SensorSynchronizer class implements software-based synchronization for data from multiple sensors and the robotic arm.
Parameterized Constructor
Section titled “Parameterized Constructor”-
Method:
__init__(self, sync_policy: typing.Any = None, time_tolerance_ms: int = 10) -> None -
Parameters:
ParameterDescription sync_policySynchronization policy. For details, please refer to SyncPolicy. time_tolerance_msTime tolerance, in milliseconds. -
Return Value:
None.
Add Sensor
Section titled “Add Sensor”-
Method:
add_sensor(self, name: str, sensor: SensorInterface) -> alphabot.core.AbcErrorCode -
Parameters:
ParameterDescription nameSensor name. sensorA SensorInterface instance. -
Return Value:
AbcErrorCode.SUCCESSindicates success. For other error codes, please refer to AbcErrorCode.
Add Robotic Arm
Section titled “Add Robotic Arm”-
Method:
add_arm(self, name: str, arm: alphabot.arm.ArmInterface) -> alphabot.core.AbcErrorCode -
Parameters:
ParameterDescription nameRobotic arm name. armA ArmInterface instance. -
Return Value:
AbcErrorCode.SUCCESSindicates success. For other error codes, please refer to AbcErrorCode.
Remove Sensor
Section titled “Remove Sensor”-
Method:
remove_sensor(self, name: str) -> alphabot.core.AbcErrorCode -
Parameter:
ParameterDescription nameSensor name -
Return Value:
AbcErrorCode.SUCCESSindicates success. For other error codes, please refer to AbcErrorCode.
Remove Robotic Arm
Section titled “Remove Robotic Arm”-
Method:
remove_arm(self, name: str) -> alphabot.core.AbcErrorCode -
Parameter:
ParameterDescription nameRobotic arm name -
Return Value:
AbcErrorCode.SUCCESSindicates success. For other error codes, please refer to AbcErrorCode.
Get Sensor
Section titled “Get Sensor”-
Method:
get_sensor(self, name: str) -> SensorInterface -
Parameter:
ParameterDescription nameSensor name -
Return Value:
A SensorInterface instance.
Start Synchronization
Section titled “Start Synchronization”-
Method:
start(self) -> alphabot.core.AbcErrorCode -
Return Value:
AbcErrorCode.SUCCESSindicates success. For other error codes, please refer to AbcErrorCode.
Stop Synchronization
Section titled “Stop Synchronization”-
Method:
stop(self) -> alphabot.core.AbcErrorCode -
Return Value:
AbcErrorCode.SUCCESSindicates 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:
ParameterDescription 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.
Set Synchronization Policy
Section titled “Set Synchronization Policy”-
Method:
set_sync_policy(self, policy: SyncPolicy) -> None -
Parameter:
ParameterDescription policySynchronization policy. For details, please refer to SyncPolicy. -
Return Value:
None.
Set Time Tolerance
Section titled “Set Time Tolerance”-
Method:
set_time_tolerance(self, tolerance_ms: int) -> None -
Parameter:
ParameterDescription tolerance_msTime tolerance, in milliseconds. -
Return Value:
None.
Get Synchronization Policy
Section titled “Get Synchronization Policy”-
Method:
get_sync_policy(self) -> SyncPolicy -
Return Value:
The current synchronization policy. For details, please refer to SyncPolicy.
Get Time Tolerance
Section titled “Get Time Tolerance”-
Method:
get_time_tolerance(self) -> int -
Return Value:
Time tolerance, in milliseconds.
Set Synchronization Mode
Section titled “Set Synchronization Mode”-
Method:
set_sync_mode(self, mode: SyncMode) -> None -
Parameter:
ParameterDescription modeSynchronization mode. For details, please refer to SyncMode. -
Return Value:
None.
Get Synchronization Mode
Section titled “Get Synchronization Mode”-
Method:
get_sync_mode(self) -> SyncMode -
Return Value:
The current synchronization mode. For details, please refer to SyncMode.
Set Reference Sensor
Section titled “Set Reference Sensor”-
Method:
set_reference_sensor(self, sensor_name: str) -> None -
Parameter:
ParameterDescription sensor_nameSensor name -
Return Value:
None.
Get Reference Sensor
Section titled “Get Reference Sensor”-
Method:
get_reference_sensor(self) -> str -
Return Value:
The name of the reference sensor.
Check If Data Is Synchronizing
Section titled “Check If Data Is Synchronizing”-
Method:
is_syncing(self) -> bool -
Return Value:
trueif data is synchronizing,falseotherwise.
SyncPolicy
Section titled “SyncPolicy”The SyncPolicy class is an enumerator representing synchronization policies.
| Constant Member | Value | Description |
|---|---|---|
NEAREST | 0 | Nearest timestamp matching |
INTERPOLATE | 1 | Interpolation matching |
EXTRAPOLATE | 2 | Extrapolation matching |
SyncMode
Section titled “SyncMode”The SyncMode class is an enumerator representing synchronization modes.
| Constant Member | Value | Description |
|---|---|---|
LATEST_TIMESTAMP | 0 | Synchronize based on the latest timestamp (default mode) |
REFERENCE_SENSOR | 1 | Synchronize based on a reference sensor |
DepthSensorParam
Section titled “DepthSensorParam”| Attribute | Data Type | Description |
|---|---|---|
sensor_type | str | Sensor vendor (e.g., "realsense") |
sensor_name | str | Sensor name (e.g., "head_camera") |
serial_number | str | Serial number |
color_width | int | Color image width |
color_height | int | Color image height |
depth_width | int | Depth image width |
depth_height | int | Depth image height |
frame_rate | int | Frame rate |
align_to_color | bool | Whether to align the depth image to the color image |
enable_depth | bool | Whether 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_pull | bool | Whether 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. |
SensorData
Section titled “SensorData”| Attribute (Read-Write) | Data Type | Description |
|---|---|---|
timestamp | typing.Any | Timestamp |
AbcIntrinsic
Section titled “AbcIntrinsic”The AbcIntrinsic class represents the intrinsic parameters of a camera.
| Structure Member | Data Type | Description |
|---|---|---|
width | int | Image width, in pixels. |
height | int | Image height, in pixels. |
ppx | float | Horizontal coordinate of the principal point, expressed as pixel offset from the left edge. |
ppy | float | Vertical coordinate of the principal point, expressed as pixel offset from the top edge. |
fx | float | Horizontal focal length, expressed as a multiple of pixel width. |
fy | float | Vertical focal length, expressed as a multiple of pixel height. |
coeffs | list[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. |
DepthCamera
Section titled “DepthCamera”The DepthCamera class inherits from SensorInterface. This section only explains methods that are overridden or newly added in the DepthCamera class.
Connect to the Depth Camera
Section titled “Connect to the Depth Camera”-
Method:
connect(self) -> alphabot.core.AbcErrorCode -
Return Value:
AbcErrorCode.SUCCESSindicates success. For other error codes, please refer to AbcErrorCode.
Disconnect from the Depth Camera
Section titled “Disconnect from the Depth Camera”-
Method:
disconnect(self) -> None -
Return Value:
None.
Get Depth Image Data
Section titled “Get Depth Image Data”-
Method:
get_data(self) -> RGBDData -
Return Value:
Depth image data. For details, please refer to RGBDData.
Start Data Stream
Section titled “Start Data Stream”-
Method:
start_stream(self) -> alphabot.core.AbcErrorCode -
Return Value:
AbcErrorCode.SUCCESSindicates success. For other error codes, please refer to AbcErrorCode.
Stop Data Stream
Section titled “Stop Data Stream”-
Method:
stop_stream(self) -> alphabot.core.AbcErrorCode -
Return Value:
AbcErrorCode.SUCCESSindicates success. For other error codes, please refer to AbcErrorCode.
Set Color Image Resolution
Section titled “Set Color Image Resolution”-
Method:
set_color_resolution(self, arg0: int, arg1: int) -> alphabot.core.AbcErrorCode -
Parameters:
ParameterDescription arg0Image width arg1Image 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:
set_depth_resolution(self, arg0: int, arg1: int) -> alphabot.core.AbcErrorCode -
Parameters:
ParameterDescription arg0Image width arg1Image height -
Return Value:
AbcErrorCode.SUCCESSindicates success. For other error codes, please refer to AbcErrorCode.
Set Frame Rate
Section titled “Set Frame Rate”-
Method:
set_framerate(self, arg0: int) -> alphabot.core.AbcErrorCode -
Parameter:
ParameterDescription arg0Frame 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:
set_align_to_color(self, arg0: bool) -> alphabot.core.AbcErrorCode -
Parameter:
ParameterDescription arg0Whether 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:
is_aligned_to_color(self) -
Return Value:
Trueindicates the depth image is aligned to the color image;Falseindicates 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:
ParameterDescription arg0The callback function is called whenever depth camera data is updated. The callback function receives a parameter of type RGBDData. -
Return Value:
None.
RGBData
Section titled “RGBData”The RGBData class, which inherits from SensorData, encapsulates RGB image data along with the intrinsic parameters of the camera.
Attributes
Section titled “Attributes”| Attribute | Data Type | Description |
|---|---|---|
height (read-only) | int | Color image height |
width (read-only) | int | Color image width |
channels (read-only) | int | Number of color image channels |
rgb_data (read-write) | numpy.ndarray[numpy.uint8] | Color image data (height, width, channels) |
Get Color Camera Intrinsic Parameters
Section titled “Get Color Camera Intrinsic Parameters”-
Method:
get_color_intrinsic(self) -> AbcIntrinsic -
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:
set_color_intrinsic(self, arg0: AbcIntrinsic) -> None -
Parameter:
ParameterDescription arg0Color camera intrinsic parameters. For details, please refer to AbcIntrinsic. -
Return Value:
None.
RGBDData
Section titled “RGBDData”The RGBDData class, which inherits from RGBData, encapsulates RGB-D images and the intrinsic parameters of the camera.
Attributes
Section titled “Attributes”| Attribute | Data Type | Description |
|---|---|---|
depth_height (read-only) | int | Depth image height |
depth_width (read-only) | int | Depth image width |
depth_data (read-write) | numpy.ndarray[numpy.float32] | Depth image data (depth_height, depth_width) |
Get Depth Camera Intrinsic Parameters
Section titled “Get Depth Camera Intrinsic Parameters”-
Method:
get_depth_intrinsic(self) -> AbcIntrinsic -
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:
set_depth_intrinsic(self, arg0: AbcIntrinsic) -> None -
Parameter:
ParameterDescription arg0Depth camera intrinsic parameters. For details, please refer to AbcIntrinsic. -
Return Value:
None.