Chirp SonicLib
4.5.2
|
Chirp SonicLib API range finding function implementations. More...
#include <invn/soniclib/ch_log.h>
#include <invn/soniclib/details/ch_common.h>
#include <invn/soniclib/sensor_fw/icu_gpt/icu_gpt.h>
#include <invn/soniclib/ch_rangefinder_types.h>
#include <invn/soniclib/ch_rangefinder.h>
Macros | |
#define | CH_LOG_MODULE_NAME "CH_RANGEFINDER" |
Functions | |
uint8_t | ch_get_num_targets (ch_dev_t *dev_ptr) |
Get the number of targets detected in last measurement. More... | |
uint8_t | ch_get_num_thresholds (const ch_dev_t *dev_ptr) |
Get number of detection thresholds. More... | |
uint16_t | ch_get_rx_holdoff (ch_dev_t *dev_ptr) |
Get the receive holdoff sample count. More... | |
uint16_t | ch_get_static_range (const ch_dev_t *dev_ptr) |
Get static target rejection range setting. More... | |
uint16_t | ch_get_target_amplitude (ch_dev_t *dev_ptr, uint8_t target_num) |
Get the amplitude for a specific target detected in last measurement. More... | |
uint32_t | ch_get_target_range (ch_dev_t *dev_ptr, uint8_t target_num, ch_range_t range_type) |
Get the range to a specific target detected in last measurement. More... | |
uint32_t | ch_get_target_tof_us (ch_dev_t *dev_ptr, uint8_t target_num) |
Get the measured time-of-flight for a specific target in microseconds. More... | |
uint16_t | ch_get_threshold (ch_dev_t *dev_ptr, uint8_t threshold_index) |
Get the detection threshold. More... | |
uint8_t | ch_get_thresholds (ch_dev_t *dev_ptr, ch_thresholds_t *thresh_ptr) |
Get detection thresholds. More... | |
uint32_t | ch_get_tof_us (ch_dev_t *dev_ptr) |
Get the measured time-of-flight from a sensor in microseconds. More... | |
uint8_t | ch_is_target_in_ringdown (ch_dev_t *dev_ptr) |
Return if a target is detected near sensor (in the ringdown) More... | |
uint8_t | ch_rangefinder_display_config_info (ch_dev_t *dev_ptr) |
uint8_t | ch_rangefinder_get_algo_config (const ch_dev_t *dev_ptr, ch_rangefinder_algo_config_t *config_ptr) |
uint16_t | ch_rangefinder_get_amplitude (ch_dev_t *dev_ptr) |
uint32_t | ch_rangefinder_get_range (ch_dev_t *dev_ptr, ch_range_t range_type) |
uint16_t | ch_rangefinder_get_rx_holdoff (ch_dev_t *dev_ptr) |
uint32_t | ch_rangefinder_get_target_range (ch_dev_t *dev_ptr, uint8_t target_num, ch_range_t range_type) |
uint8_t | ch_rangefinder_get_thresholds (ch_dev_t *dev_ptr, ch_thresholds_t *lib_thresh_buf_ptr) |
uint8_t | ch_rangefinder_set_algo_config (ch_dev_t *dev_ptr, const ch_rangefinder_algo_config_t *config_ptr) |
uint8_t | ch_rangefinder_set_rx_holdoff (ch_dev_t *dev_ptr, uint16_t num_samples) |
uint8_t | ch_rangefinder_set_static_range (ch_dev_t *dev_ptr, uint16_t num_samples) |
uint8_t | ch_rangefinder_set_thresholds (ch_dev_t *dev_ptr, ch_thresholds_t *lib_thresh_buf_ptr) |
uint8_t | ch_set_rx_holdoff (ch_dev_t *dev_ptr, uint16_t num_samples) |
Set the receive holdoff sample count. More... | |
uint8_t | ch_set_static_range (ch_dev_t *dev_ptr, uint16_t num_samples) |
Configure static target rejection. More... | |
uint8_t | ch_set_threshold (ch_dev_t *dev_ptr, uint8_t threshold_index, uint16_t amplitude) |
Set the detection threshold. More... | |
uint8_t | ch_set_thresholds (ch_dev_t *dev_ptr, ch_thresholds_t *thresh_ptr) |
Set detection thresholds. More... | |
Variables | |
const uint8_t | THRESH_LEN_REGS [CHX01_COMMON_NUM_THRESHOLDS] |
Chirp SonicLib API range finding function implementations.
uint8_t ch_get_num_targets | ( | ch_dev_t * | dev_ptr | ) |
Get the number of targets detected in last measurement.
dev_ptr | pointer to the ch_dev_t descriptor structure |
This function returns the number of valid targets that were detected in the last measurement completed by the sensor. Data for each of these targets may then be read using ch_get_target_range() and ch_get_target_amplitude().
See also ch_get_target_range(), ch_set_num_ranges().
uint8_t ch_get_num_thresholds | ( | const ch_dev_t * | dev_ptr | ) |
Get number of detection thresholds.
dev_ptr | pointer to the ch_dev_t descriptor structure |
This function returns the number of independent detection threshold values that are supported by the current sensor and sensor firmware. For firmware supporting multiple thresholds, the number of thresholds is the same as the number of threshold fields in the ch_thresholds_t structure.
See also ch_set_thresholds().
uint16_t ch_get_rx_holdoff | ( | ch_dev_t * | dev_ptr | ) |
Get the receive holdoff sample count.
dev_ptr | pointer to the ch_dev_t descriptor structure |
This function gets the receive (rx) holdoff sample count. The rx holdoff count is the number of samples at the beginning of a measurement that will be ignored for the purpose of detecting a target, as previously set by ch_set_rx_holdoff().
To convert the returned sample count to a physical distance, use ch_samples_to_mm().
For ICU sensors, this function always returns the value for the default measurement definition. To specify which measurement to query, use the icu_gpt_get_rx_holdoff() function.
See also ch_set_rx_holdoff().
uint16_t ch_get_static_range | ( | const ch_dev_t * | dev_ptr | ) |
Get static target rejection range setting.
dev_ptr | pointer to the ch_dev_t descriptor structure |
This function returns the number of samples at the beginning of a measurement cycle over which static target rejection filtering will be applied.
To calculate the physical distance that corresponds to the number of samples, use the ch_samples_to_mm() function.
For ICU sensors, this function always returns the value for the default measurement definition. To specify which measurement to query, use the icu_gpt_get_static_filter() function.
See also ch_set_static_range().
uint16_t ch_get_target_amplitude | ( | ch_dev_t * | dev_ptr, |
uint8_t | target_num | ||
) |
Get the amplitude for a specific target detected in last measurement.
dev_ptr | pointer to the ch_dev_t descriptor structure |
target_num | number of target to report |
This function reads the measurement data for a specific target and returns the measured amplitude value. The amplitude is representative of the incoming sound pressure. The value is expressed in internal sensor counts (LSBs) and is not calibrated to any standard units.
The amplitude value is not updated if a measurement cycle resulted in CH_NO_TARGET, as returned by ch_get_target_range().
See also ch_get_target_range(), ch_get_amplitude().
uint32_t ch_get_target_range | ( | ch_dev_t * | dev_ptr, |
uint8_t | target_num, | ||
ch_range_t | range_type | ||
) |
Get the range to a specific target detected in last measurement.
dev_ptr | pointer to the ch_dev_t descriptor structure |
target_num | number of target to report |
range_type | the range type to be reported (e.g. one-way vs. round-trip) |
This function reads the measurement data for a specific target and then computes the actual range. It should be called after the sensor has indicated that a measurement cycle is complete by generating a signal on the INT line. (Typically, this will be set up by an interrupt handler associated with that input line.)
target_num specifies the target whose range is to be calculated. The ch_get_num_targets() function may be used to determine the total number of valid targets detected by the measurement.
The range_type parameter indicates whether the measurement is based on the one-way or round-trip distance to/from a target, or the direct distance between two sensors operating in pitch-catch mode. The possible values are:
See also ch_get_target_amplitude(), ch_get_range(), ch_get_num_targets().
uint32_t ch_get_target_tof_us | ( | ch_dev_t * | dev_ptr, |
uint8_t | target_num | ||
) |
Get the measured time-of-flight for a specific target in microseconds.
dev_ptr | pointer to the ch_dev_t descriptor structure |
target_num | number of the detected target to be reported |
This function reads the measurement result registers from the sensor and then computes the time-of-flight in microseconds. The time-of-flight is returned as a 32-bit integer.
If the sensor did not successfully find the range of a target during the most recent measurement, the returned value will be zero (0). If an error occurs when getting or calculating the range, zero (0) will be returned.
uint16_t ch_get_threshold | ( | ch_dev_t * | dev_ptr, |
uint8_t | threshold_index | ||
) |
Get the detection threshold.
dev_ptr | pointer to the ch_dev_t descriptor structure |
threshold_index | index to the thresholds, starting from 0 |
This function obtains the detection threshold value with the specified threshold_index from the sensor and returns the corresponding threshold amplitude.
See also ch_set_threshold().
uint8_t ch_get_thresholds | ( | ch_dev_t * | dev_ptr, |
ch_thresholds_t * | thresh_ptr | ||
) |
Get detection thresholds.
dev_ptr | pointer to the ch_dev_t descriptor structure |
thresh_ptr | pointer to ch_thresholds_t structure to receive threshold data |
This function obtains the current detection threshold values from the sensor and returns them in a ch_thresholds_t structure specified by thresh_ptr. The ch_thresholds_t structure holds an array of ch_thresh_t structures, each of which contains a starting sample number and amplitude threshold value.
For ICU sensors, this function only reports the thresholds for the default measurement (CH_DEFAULT_MEAS_NUM). If both measurements are being used, the thresholds for each may be obtained individually by using the icu_gpt_get_thresholds() function.
See also ch_set_thresholds().
uint32_t ch_get_tof_us | ( | ch_dev_t * | dev_ptr | ) |
Get the measured time-of-flight from a sensor in microseconds.
dev_ptr | pointer to the ch_dev_t descriptor structure |
This function reads the measurement result registers from the sensor and then computes the time-of-flight in microseconds. The time-of-flight is returned as a 32-bit integer.
If the sensor did not successfully find the range of a target during the most recent measurement, the returned value will be zero (0). If an error occurs when getting or calculating the range, zero (0) will be returned.
uint8_t ch_is_target_in_ringdown | ( | ch_dev_t * | dev_ptr | ) |
Return if a target is detected near sensor (in the ringdown)
dev_ptr | pointer to the ch_dev_t descriptor structure |
uint8_t ch_set_rx_holdoff | ( | ch_dev_t * | dev_ptr, |
uint16_t | num_samples | ||
) |
Set the receive holdoff sample count.
dev_ptr | pointer to the ch_dev_t descriptor structure |
num_samples | number of samples to be ignored at the beginning of each measurement |
This function sets the receive (rx) holdoff sample count. num_samples specifies a number of samples at the beginning of a measurement that will be ignored for the purpose of detecting a target. (These samples correspond to the closest distances from the sensor.)
To convert a physical distance into a sample count value to use here, use ch_mm_to_samples().
For ICU sensors, this function always controls the default measurement definition. To specify which measurement to modify, use the icu_gpt_set_rx_holdoff() function.
See also ch_get_rx_holdoff().
uint8_t ch_set_static_range | ( | ch_dev_t * | dev_ptr, |
uint16_t | num_samples | ||
) |
Configure static target rejection.
dev_ptr | pointer to the ch_dev_t descriptor structure |
num_samples | number of sensor samples (at beginning of measurement cycle) over which static targets will be rejected |
Static target rejection is a special processing mode in which the sensor will actively filter out signals from close, non-moving objects, so that they do not continue to generate range readings. This allows detection and reporting of target objects that are farther away than the static objects. (Normally, the sensor reports the range value for the closest detected object.)
Static target rejection is applied for a specified number of samples, starting at the beginning of a measurement cycle* (i.e. for the closest objects). The num_samples parameter specifies the number of samples that will be filtered. To calculate the appropriate value for num_samples to filter over a certain physical distance, use the ch_mm_to_samples() function.
For ICU sensors, this function always controls the default measurement definition. To specify which measurement to modify, use the icu_gpt_set_static_filter() function.
See also ch_get_static_range().
uint8_t ch_set_threshold | ( | ch_dev_t * | dev_ptr, |
uint8_t | threshold_index, | ||
uint16_t | amplitude | ||
) |
Set the detection threshold.
dev_ptr | pointer to the ch_dev_t descriptor structure |
threshold_index | index to the thresholds, starting from 0 |
amplitude | amplitude threshold value |
This function sets the detection threshold value with the specified threshold_index value for the sensor. The detection threshold is the minimum amplitude required for a target detection to be reported. The amplitude value is the new required amplitude, expressed in the same internal units used in ch_get_amplitude() and other functions.
See also ch_get_threshold().
uint8_t ch_set_thresholds | ( | ch_dev_t * | dev_ptr, |
ch_thresholds_t * | thresh_ptr | ||
) |
Set detection thresholds.
dev_ptr | pointer to the ch_dev_t descriptor structure |
thresh_ptr | pointer to ch_thresholds_t structure containing threshold data |
This function sets the detection threshold values for the sensor based on the values in the ch_thresholds_t structure specified by thresh_ptr. The ch_thresholds_t structure holds an array of ch_thresh_t structures, each of which contains a starting sample number and amplitude threshold value.
To use this function, first initialize the ch_thresh_t sample/level pair of values for each threshold. The ICU sensor supports eight (8) separate thresholds, while the CH201 sensor with GPRMT firmware supports six (6) thresholds. Each threshold has a maximum sample length of 255.
It is not necessary to use the full set of thresholds, if the application and sensing environment do not require that many different levels. Unused thresholds should occupy the last elements in the ch_thresholds_t structure and should have zero (0) for their starting sample number. These entries will be ignored, and the threshold specified in the final valid entry will apply to the rest of the measurement.
For ICU sensors, this function only sets the thresholds for the default measurement (CH_DEFAULT_MEAS_NUM). If both measurements are being used, the thresholds for each may be set individually by using the icu_gpt_set_thresholds() function.
See also ch_get_thresholds().
const uint8_t THRESH_LEN_REGS[CHX01_COMMON_NUM_THRESHOLDS] |