3.10. Infrared Distance Sensor¶
-
ir_distance_sensor_ctrl.
enable_measure
(port_id)¶ Description: Enables the ranging function of the infrared distance sensor 参数: port_id (int) – The module number of the infrared distance sensor, whose range is [1:4] 返回: None Example: ir_distance_sensor_ctrl.enable_measure(1)
Example description: Enable the ranging function of infrared distance sensor 1
-
ir_distance_sensor_ctrl.
disable_measure
(port_id)¶ Description: Disables the ranging function of the infrared distance sensor 参数: port_id (int) – The module number of the infrared distance sensor, whose range is [1:4] 返回: None Example: ir_distance_sensor_ctrl.disable_measure(1)
Example description: Disable the ranging function of infrared distance sensor 1
-
ir_distance_sensor_ctrl.
get_distance_info
(port_id)¶ Description: Obtains the ranging information of the infrared distance sensor 参数: port_id (int) – The module number of the infrared distance sensor, whose range is [1:4] 返回: The distance to the obstacle in front of the infrared distance sensor, with an accuracy of 1 cm 返回类型: uint16 Example: ir_distance_sensor_ctrl.get_distance_info(1)
Example description: Obtain the ranging information of infrared distance sensor 1
-
def ir_distance_[port_id]_[compare_type]_[dist]_event(msg):
Description: When the distance to the obstacle in front of the infrared distance sensor is judged to satisfy the relevant conditions, run the program in the function
参数: - port_id (int) – The module number of the infrared distance sensor, whose range is [1:4]
- compare_type – The comparison type, which can be eq (equal), ge (greater than or equal to), gt (greater than), le (less than or equal to), or lt (less than).
- dist – The distance used for comparison, with an accuracy of 1 cm, range of 5-500 cm, and error rate of 5%
返回: None
Example:
1 2 3 4 | #When the distance to the obstacle in front of the infrared distance sensor is judged to satisfy the relevant conditions, run the program in the function
def ir_distance_1_lt_10_event(msg):
pass
|
-
ir_distance_sensor_ctrl.
cond_wait
('ir_distance_[port_id]_[compare_type]_[dist]')¶ Description: When the distance to the obstacle in front of the waiting infrared distance sensor is judged to satisfy the relevant conditions, execute the next instruction
参数: - 'ir_distance_[port_id]_[compare_type]_[dist]' – The string used for distance comparison, which includes the module number, comparison type, and distance
- port_id (int) – The module number of the infrared distance sensor, whose range is [1:4]
- compare_type – The comparison type, which can be eq (equal), ge (greater than or equal to), gt (greater than), le (less than or equal to), or lt (less than).
- dist – The distance used for comparison, with an accuracy of 1 cm, range of 5-500 cm, and error rate of 5%
返回: None
Example: ir_distance_sensor_ctrl.cond_wait('ir_distance_1_gt_50')
Example description: If the distance to the obstacle in front of infrared distance sensor 1 is greater than 50 cm, execute the next instruction
-
ir_distance_sensor_ctrl.
check_condition
('ir_distance_[port_id]_[compare_type]_[dist]')¶ Description: Determines whether the distance to the obstacle in front of the infrared distance sensor meets the relevant conditions
参数: - 'ir_distance_[port_id]_[compare_type]_[dist]' – The string used for distance comparison, which includes the module number, comparison type, and distance
- port_id (int) – The module number of the infrared distance sensor, whose range is [1:4]
- compare_type – The comparison type, which can be eq (equal), ge (greater than or equal to), gt (greater than), le (less than or equal to), or lt (less than).
- dist – The distance used for comparison, with an accuracy of 1 cm, range of 5-500 cm, and error rate of 5%
返回: Whether the relevant conditions are satisfied. If yes, true is returned. If no, false is returned.
返回类型: bool
Example:
1 2 3 4 | #When the distance to the obstacle in front of the infrared distance sensor is judged to satisfy the relevant conditions, run the program in the function
if ir_distance_sensor_ctrl.check_condition('ir_distance_1_gt_50'):
pass
|
提示
For the description of the module, refer to Infrared Distance Sensor.