3.11. Sensor Adapter

sensor_adapter_ctrl.get_sensor_adapter_adc(board_id, port_num)
Description:

Obtains the ADC value of the analog pin for the corresponding port on the sensor adapter

参数:
  • board_id (int) – The module number of the sensor adapter, whose range is [1:6]
  • port_num (uint8) – The number of the port on the sensor adapter, whose range is [1:2]
  • wait_for_complete (bool) – Whether to wait for execution to be completed. The default value is True.
返回:

The ADC value of the analog pin for the corresponding port on the sensor adapter, whose range is [0:1023]

返回类型:

uint16

Example:

ret = sensor_adapter_ctrl.get_sensor_adapter_adc(1, 2)

Example description:
 

Obtain the ADC value of the analog pin for port 2 on sensor adapter 1

sensor_adapter_ctrl.get_sensor_adapter_pulse_period(board_id, port_num)
Description:

Obtains the pulse duration of the pin for the corresponding port on the sensor adapter

参数:
  • board_id (int) – The module number of the sensor adapter, whose range is [1:6]
  • port_num (uint8) – The number of the port on the sensor adapter, whose range is [1:2]
返回:

The pulse duration of the pin for the corresponding port on the sensor adapter, with an accuracy of 1 ms

返回类型:

uint32

Example:

ret = sensor_adapter_ctrl.get_sensor_pulse_period(1, 2)

Example description:
 

Obtain the pulse duration of the analog pin for port 2 on sensor adapter 1

def sensor_adapter[board_id]_port[port_id]_[judge_type]_event(msg):
Description:

When the pulse on the pin of the corresponding port on the sensor adapter changes to high, low, or bidirectional, run the program in the function

参数:
  • board_id (int) – The module number of the sensor adapter, whose range is [1:6]
  • port_num (uint8) – The number of the port on the sensor adapter, whose range is [1:2]
  • judge_type – The trigger condition, which can be high, low, or trigger. These values indicate high level, low level, and bidirectional skipping respectively.
返回:

None

Example:
1
2
3
4
#When the pulse on the pin of port 2 on sensor adapter 1 changes to high, run the program in the function

def sensor_adapter1_port2_high_event(msg):
    pass
sensor_adapter_ctrl.cond_wait(rm_define.cond_sensor_adapter[board_id]_port[port_id]_[judge_type]_event)
Description:

When the pulse on the pin of the corresponding port on the waiting sensor adapter is high, low, or trigger, execute the next instruction

参数:
  • board_id (int) – The module number of the sensor adapter, whose range is [1:6]
  • port_num (uint8) – The number of the port on the sensor adapter, whose range is [1:2]
  • judge_type – The trigger condition, which can be high, low, or trigger. These values indicate high level, low level, and bidirectional skipping respectively.
返回:

None

Example:

sensor_adapter_ctrl.cond_wait(rm_define.cond_sensor_adapter1_port2_high_event)

Example description:
 

When the pulse on the pin of port 2 on sensor adapter 1 is high, execute the next instruction

sensor_adapter_ctrl.check_condition(rm_define.cond_sensor_adapter[board_id]_port[port_id]_[judge_type]_event)
Description:

Determines whether the pulse on the pin of the corresponding port on the sensor adapter is high, low, or trigger

参数:
  • board_id (int) – The module number of the sensor adapter, whose range is [1:6]
  • port_num (uint8) – The number of the port on the sensor adapter, whose range is [1:2]
  • judge_type – The trigger condition, which can be high, low, or trigger. These values indicate high level, low level, and bidirectional skipping respectively.
返回:

Whether the relevant conditions are satisfied. If yes, true is returned. If no, false is returned.

返回类型:

bool

Example:
1
2
3
4
#If the pulse on the pin of port 2 on sensor adapter 1 is trigger, execute the next instruction

if sensor_adapter_ctrl.check_condition(rm_define.cond_sensor_adapter1_port2_trigger_event):
    pass

提示

For the description of the module, refer to Sensor Adapter.