Ultrasonic ranging method and device, readable storage medium and electronic equipment

文档序号:167780 发布日期:2021-10-29 浏览:54次 中文

阅读说明:本技术 超声波测距方法、装置、可读存储介质及电子设备 (Ultrasonic ranging method and device, readable storage medium and electronic equipment ) 是由 张磊 于 2020-04-28 设计创作,主要内容包括:本申请公开了一种超声波测距方法、装置、可读存储介质及电子设备,通过判断发送超声波的时间间隔与接收到超声波的时间间隔是否一致,并在两者一致时计算电子设备与目标物体的距离。所述方法包括:获取预设时间起点后的第一预设时间段内的第一状态信息;获取接收时间起点后的第一预设时间段内各个时刻是否接收到所述超声波的第二状态信息;根据第一状态信息和第二状态信息,判断发送超声波的时间间隔与接收超声波的时间间隔是否一致;在发送超声波的时间间隔与接收超声波的时间间隔一致时,根据超声波的发送与接收之间的时间差、超声波的传播速度计算所述电子设备与所述目标物体之间的距离。本方案能够排除超声波干扰,提高测距的精确性。(The application discloses an ultrasonic ranging method, an ultrasonic ranging device, a readable storage medium and electronic equipment. The method comprises the following steps: acquiring first state information in a first preset time period after a preset time starting point; acquiring second state information whether the ultrasonic wave is received at each moment in a first preset time period after the starting point of the receiving time; judging whether the time interval for sending the ultrasonic waves is consistent with the time interval for receiving the ultrasonic waves or not according to the first state information and the second state information; when the time interval for transmitting the ultrasonic wave coincides with the time interval for receiving the ultrasonic wave, the distance between the electronic device and the target object is calculated from the time difference between transmission and reception of the ultrasonic wave and the propagation speed of the ultrasonic wave. Ultrasonic interference can be got rid of to this scheme, improves the accuracy nature of range finding.)

1. An ultrasonic ranging method is applied to an electronic device, and the method comprises the following steps:

starting to intermittently transmit ultrasonic waves with the frequency within a preset frequency range to a target object from a preset time starting point, and acquiring first state information of whether the ultrasonic waves are transmitted at each moment within a first preset time period after the preset time starting point;

acquiring a receiving time starting point of the ultrasonic wave within the preset frequency range for the first time within a second preset time period after the preset time starting point, wherein the second preset time period is greater than the first preset time period;

acquiring second state information whether the ultrasonic wave is received at each moment in a first preset time period after the starting point of the receiving time;

judging whether the time interval for sending the ultrasonic waves is consistent with the time interval for receiving the ultrasonic waves or not according to the first state information and the second state information;

when the time interval for transmitting the ultrasonic wave coincides with the time interval for receiving the ultrasonic wave, the distance between the electronic device and the target object is calculated from the time difference between transmission and reception of the ultrasonic wave and the propagation speed of the ultrasonic wave.

2. The method according to claim 1, wherein the step of intermittently transmitting the ultrasonic wave having the frequency within the preset frequency range to the target object from the preset time start point comprises:

taking a third preset time period as a first time granularity within the first preset time period, and starting from the starting point of the preset time and taking the first time granularity as a unit to intermittently send ultrasonic waves with the frequency within a preset frequency range to a target object, wherein the first preset time period comprises a plurality of third preset time periods;

the step of determining whether or not the time interval for transmitting the ultrasonic wave and the time interval for receiving the ultrasonic wave coincide with each other based on the first state information and the second state information includes:

obtaining first coded data in a first preset time period after the preset time starting point according to the first state information and the first time granularity;

obtaining second coded data in a first preset time period after the starting point of the receiving time according to the second state information and the first time granularity;

judging whether the first coded data is consistent with the second coded data;

if the first encoded data is identical to the second encoded data, determining that a time interval for transmitting the ultrasonic wave is identical to a time interval for receiving the ultrasonic wave;

if the first encoded data does not match the second encoded data, it is determined that the time interval for transmitting the ultrasonic waves does not match the time interval for receiving the ultrasonic waves.

3. The method of claim 2, wherein the step of determining whether the first encoded data and the second encoded data correspond comprises:

in the first preset time period, taking a fourth preset time period as a second time granularity, and aiming at each second time granularity in the first preset time period, obtaining a coding symbol corresponding to each first time granularity in the second time granularity from first coding data to obtain first sub-coding data corresponding to the second time granularity, wherein the first preset time period comprises a plurality of fourth preset time periods, and the fourth preset time period comprises a plurality of third preset time periods;

judging whether second sub-coded data respectively corresponding to each first sub-coded data exists in the second coded data, and judging whether the second sub-coded data in the second coded data exceeds a preset number;

if the second sub-coded data exceeds a preset number, judging that the first coded data is consistent with the second coded data;

and if the second sub-coded data does not exceed the preset number, judging that the first coded data is inconsistent with the second coded data.

4. A method according to claim 3, wherein the step of determining whether there is second sub-coded data corresponding to each of the first sub-coded data in the second coded data comprises:

aiming at each first sub-coded data in a first preset time period, acquiring a first identification coded segment which is composed of a first preset number of continuous coded symbols in the first sub-coded data;

judging whether a second identification code segment which is the same as the first identification code segment exists in the second coded data;

if the second identification code segment exists in the second coded data, checking whether a first data code segment is the same as a second data code segment or not, wherein the first data code segment comprises a second preset number of coded symbols which are continuous after the first identification code segment, and the second data code segment comprises a second preset number of coded symbols which are continuous after the second identification code segment;

when the first data encoding segment is the same as the second data encoding segment, the second sub-encoded data exists in the second encoded data.

5. The method of claim 4, wherein said step of verifying whether the first segment of data encoding and the second segment of data encoding are identical comprises:

encrypting the second data coding segment according to a preset encryption rule to obtain a first check code consisting of a plurality of coding symbols;

comparing a third preset number of encoding symbols after the second data encoding segment with the first check code;

if the third preset number of code symbols is the same as the first check code, judging that the first data code segment is the same as the second data code segment;

and if the third preset number of code symbols is different from the first check code, judging that the first data coding section is different from the second data coding section.

6. The method according to claim 3, wherein the step of calculating the distance between the electronic device and the target object from the time difference between transmission and reception of the ultrasonic wave and the propagation speed of the ultrasonic wave comprises:

for each first sub-coded data, calculating a first distance between the electronic equipment and the target object according to the difference between the starting time of the first sub-coded data and the starting time of second sub-coded data corresponding to the first sub-coded data and the propagation speed of the ultrasonic wave;

and calculating the average value of the first distances corresponding to each first sub-coded data to obtain the distance between the electronic equipment and the target object.

7. The method according to any one of claims 1-6, further comprising:

and when the time interval for sending the ultrasonic waves is inconsistent with the time interval for receiving the ultrasonic waves, adjusting the preset frequency range, and re-executing the step of starting to intermittently send the ultrasonic waves with the frequency within the preset frequency range from the preset time starting point to the target object according to the adjusted preset frequency range.

8. An ultrasonic ranging apparatus, applied to an electronic device, the apparatus comprising:

the sending and recording module is used for starting from a preset time starting point to intermittently send the ultrasonic waves with the frequency within the preset frequency range to the target object and obtaining first state information of whether the ultrasonic waves are sent at each moment within a first preset time period after the preset time starting point;

the acquisition module is used for acquiring a receiving time starting point of the ultrasonic wave within the preset frequency range within a second preset time period after the preset time starting point, wherein the second preset time period is greater than the first preset time period;

the receiving and recording module is used for acquiring whether second state information of the ultrasonic wave is received at each moment in a first preset time period after the starting point of the receiving time;

the distance calculation module is used for judging whether the time interval for sending the ultrasonic waves is consistent with the time interval for receiving the ultrasonic waves or not according to the first state information and the second state information;

and calculating a distance between the electronic device and the target object based on a time difference between transmission and reception of the ultrasonic wave and a propagation speed of the ultrasonic wave when a time interval at which the ultrasonic wave is transmitted coincides with a time interval at which the ultrasonic wave is received.

9. A readable storage medium, in which an executable program is stored, which when executed by a processor implements the method according to any one of claims 1 to 7.

10. An electronic device, comprising a memory and a processor, the memory being electrically connected to the processor, the memory having stored therein an executable program, the processor, when executing the executable program, implementing the method of any one of claims 1-7.

Technical Field

The present disclosure relates to the field of ranging technologies, and in particular, to an ultrasonic ranging method, an ultrasonic ranging device, a readable storage medium, and an electronic device.

Background

With the development of mobile devices, the functions of the mobile devices are more and more abundant, wherein the ranging is the function of most mobile devices. One common way of ranging for mobile devices is ultrasonic ranging. In measuring a distance using ultrasonic waves, ultrasonic waves in a preset frequency range are generally directly transmitted to a target object to be measured in an environment, and then, after the ultrasonic waves are transmitted, the ultrasonic waves in the preset frequency range in the environment are received, and then, the measured distance is calculated based on a time difference between a time when the ultrasonic waves are transmitted and a time when the ultrasonic waves are received and a propagation velocity of the ultrasonic waves in the preset frequency range.

Since various sound waves and the like exist in the environment where the mobile device is located, the sound waves may also be received by the mobile device, and if the sound waves received by the mobile device are located within the preset frequency range, the calculated time difference is interfered by the sound waves existing in the environment, so that the calculated distance is inaccurate.

Disclosure of Invention

In order to overcome at least the above-mentioned deficiencies in the prior art, an object of the present application is to provide an ultrasonic ranging method applied to an electronic device, the method comprising:

starting to intermittently transmit ultrasonic waves with the frequency within a preset frequency range to a target object from a preset time starting point, and acquiring first state information of whether the ultrasonic waves are transmitted at each moment within a first preset time period after the preset time starting point;

acquiring a receiving time starting point of the ultrasonic wave within the preset frequency range for the first time within a second preset time period after the preset time starting point, wherein the second preset time period is greater than the first preset time period;

acquiring second state information whether the ultrasonic wave is received at each moment in a first preset time period after the starting point of the receiving time;

judging whether the time interval for sending the ultrasonic waves is consistent with the time interval for receiving the ultrasonic waves or not according to the first state information and the second state information;

when the time interval for transmitting the ultrasonic wave coincides with the time interval for receiving the ultrasonic wave, the distance between the electronic device and the target object is calculated from the time difference between transmission and reception of the ultrasonic wave and the propagation speed of the ultrasonic wave.

Optionally, the step of starting from the preset time starting point to intermittently transmit the ultrasonic wave with the frequency within the preset frequency range to the target object includes:

taking a third preset time period as a first time granularity within the first preset time period, and starting from the starting point of the preset time and taking the first time granularity as a unit to intermittently send ultrasonic waves with the frequency within a preset frequency range to a target object, wherein the first preset time period comprises a plurality of third preset time periods;

the step of determining whether or not the time interval for transmitting the ultrasonic wave and the time interval for receiving the ultrasonic wave coincide with each other based on the first state information and the second state information includes:

obtaining first coded data in a first preset time period after the preset time starting point according to the first state information and the first time granularity;

obtaining second coded data in a first preset time period after the starting point of the receiving time according to the second state information and the first time granularity;

judging whether the first coded data is consistent with the second coded data;

if the first encoded data is identical to the second encoded data, determining that a time interval for transmitting the ultrasonic wave is identical to a time interval for receiving the ultrasonic wave;

if the first encoded data does not match the second encoded data, it is determined that the time interval for transmitting the ultrasonic waves does not match the time interval for receiving the ultrasonic waves.

Optionally, the step of determining whether the first encoded data and the second encoded data are consistent includes:

in the first preset time period, taking a fourth preset time period as a second time granularity, and aiming at each second time granularity in the first preset time period, obtaining a coding symbol corresponding to each first time granularity in the second time granularity from first coding data to obtain first sub-coding data corresponding to the second time granularity, wherein the first preset time period comprises a plurality of fourth preset time periods, and the fourth preset time period comprises a plurality of third preset time periods;

judging whether second sub-coded data respectively corresponding to each first sub-coded data exists in the second coded data, and judging whether the second sub-coded data in the second coded data exceeds a preset number;

if the second sub-coded data exceeds a preset number, judging that the first coded data is consistent with the second coded data;

and if the second sub-coded data does not exceed the preset number, judging that the first coded data is inconsistent with the second coded data.

Optionally, the step of determining whether there is second sub-encoded data corresponding to each first sub-encoded data in the second encoded data includes:

aiming at each first sub-coded data in a first preset time period, acquiring a first identification coded segment which is composed of a first preset number of continuous coded symbols in the first sub-coded data;

judging whether a second identification code segment which is the same as the first identification code segment exists in the second coded data;

if the second identification code segment exists in the second coded data, checking whether a first data code segment is the same as a second data code segment or not, wherein the first data code segment comprises a second preset number of coded symbols which are continuous after the first identification code segment, and the second data code segment comprises a second preset number of coded symbols which are continuous after the second identification code segment;

when the first data encoding segment is the same as the second data encoding segment, the second sub-encoded data exists in the second encoded data.

Optionally, the step of checking whether the first data encoding segment is the same as the second data encoding segment includes:

encrypting the second data coding segment according to a preset encryption rule to obtain a first check code consisting of a plurality of coding symbols;

comparing a third preset number of encoding symbols after the second data encoding segment with the first check code;

if the third preset number of code symbols is the same as the first check code, judging that the first data code segment is the same as the second data code segment;

and if the third preset number of code symbols is different from the first check code, judging that the first data coding section is different from the second data coding section.

Optionally, the step of calculating the distance between the electronic device and the target object according to the time difference between the transmission and the reception of the ultrasonic wave and the propagation speed of the ultrasonic wave includes:

for each first sub-coded data, calculating a first distance between the electronic equipment and the target object according to the difference between the starting time of the first sub-coded data and the starting time of second sub-coded data corresponding to the first sub-coded data and the propagation speed of the ultrasonic wave;

and calculating the average value of the first distances corresponding to each first sub-coded data to obtain the distance between the electronic equipment and the target object.

Optionally, the method further comprises:

and when the time interval for sending the ultrasonic waves is inconsistent with the time interval for receiving the ultrasonic waves, adjusting the preset frequency range, and re-executing the step of starting to intermittently send the ultrasonic waves with the frequency within the preset frequency range from the preset time starting point to the target object according to the adjusted preset frequency range.

Another object of the present application is to provide an ultrasonic ranging apparatus applied to an electronic device, the apparatus including:

the sending and recording module is used for starting from a preset time starting point to intermittently send the ultrasonic waves with the frequency within the preset frequency range to the target object and obtaining first state information of whether the ultrasonic waves are sent at each moment within a first preset time period after the preset time starting point;

the acquisition module is used for acquiring a receiving time starting point of the ultrasonic wave within the preset frequency range within a second preset time period after the preset time starting point, wherein the second preset time period is greater than the first preset time period;

the receiving and recording module is used for acquiring whether second state information of the ultrasonic wave is received at each moment in a first preset time period after the starting point of the receiving time;

the distance calculation module is used for judging whether the time interval for sending the ultrasonic waves is consistent with the time interval for receiving the ultrasonic waves or not according to the first state information and the second state information;

and calculating a distance between the electronic device and the target object based on a time difference between transmission and reception of the ultrasonic wave and a propagation speed of the ultrasonic wave when a time interval at which the ultrasonic wave is transmitted coincides with a time interval at which the ultrasonic wave is received.

It is also an object of the present application to provide a readable storage medium having stored therein an executable program which, when executed by a processor, implements a method as in any of the present applications.

It is another object of the present application to provide an electronic device, which includes a memory and a processor, the memory being electrically connected to the processor, the memory storing an executable program therein, the processor implementing the method according to any of the present application when executing the executable program.

Compared with the prior art, the method has the following beneficial effects:

according to the ultrasonic ranging method, the ultrasonic ranging device, the readable storage medium and the electronic device, the first state information in the first preset time period after the preset time starting point is acquired, and the second state information in the first preset time period after the time starting point is received are acquired, so that whether the time interval for sending the ultrasonic wave is consistent with the time interval for receiving the ultrasonic wave is judged according to the first state information and the second state information, and the distance between the electronic device and the target object is calculated under the condition that the time interval for sending the ultrasonic wave is consistent with the time interval for receiving the ultrasonic wave. Since the distance is calculated in the case where the time interval for transmitting the ultrasonic wave and the time interval for receiving the ultrasonic wave coincide with each other throughout the process, it can be detected that the received ultrasonic wave is an interfering ultrasonic wave other than the transmitted ultrasonic wave. The distance is recalculated without interference in the received ultrasonic waves, and the accuracy of the calculated distance can be improved.

Drawings

In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings that are required to be used in the embodiments will be briefly described below, it should be understood that the following drawings only illustrate some embodiments of the present application and therefore should not be considered as limiting the scope, and for those skilled in the art, other related drawings can be obtained from the drawings without inventive effort.

Fig. 1 is a block diagram schematically illustrating a structure of an electronic device according to an embodiment of the present disclosure;

fig. 2 is a first schematic flowchart of an ultrasonic ranging method according to an embodiment of the present application;

FIG. 3 is a schematic diagram of coding time division provided by an embodiment of the present application;

fig. 4 is a second schematic flowchart of an ultrasonic ranging method according to an embodiment of the present application;

fig. 5 is a third schematic flowchart of an ultrasonic ranging method according to an embodiment of the present application;

fig. 6 is a schematic diagram of a first encoded data composition structure provided in an embodiment of the present application;

fig. 7 is a schematic block diagram of an ultrasonic ranging device according to an embodiment of the present application.

Icon: 100-an electronic device; 110-ultrasonic ranging device; 111-sending a recording module; 112-an acquisition module; 113-a reception recording module; 114-a distance calculation module; 120-a memory; 130-a processor.

Detailed Description

In order to make the objects, technical solutions and advantages of the embodiments of the present application clearer, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application, and it is obvious that the described embodiments are some embodiments of the present application, but not all embodiments. The components of the embodiments of the present application, generally described and illustrated in the figures herein, can be arranged and designed in a wide variety of different configurations.

Thus, the following detailed description of the embodiments of the present application, presented in the accompanying drawings, is not intended to limit the scope of the claimed application, but is merely representative of selected embodiments of the application. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present application.

It should be noted that: like reference numbers and letters refer to like items in the following figures, and thus, once an item is defined in one figure, it need not be further defined and explained in subsequent figures.

In the description of the present application, it is further noted that, unless expressly stated or limited otherwise, the terms "disposed," "mounted," "connected," and "connected" are to be construed broadly, e.g., as meaning either a fixed connection, a removable connection, or an integral connection; can be mechanically or electrically connected; they may be connected directly or indirectly through intervening media, or they may be interconnected between two elements. The specific meaning of the above terms in the present application can be understood in a specific case by those of ordinary skill in the art.

In an embodiment of the ultrasonic ranging, when the relative movement speed between the distance measuring device and the target object is small or there is no relative movement, for example, when a mobile phone or the like is used to measure a distance of a static object, the distance measuring device usually transmits ultrasonic waves to the target object, then receives echoes of the transmitted ultrasonic waves (the ultrasonic waves reflected by the target object to the electronic device) by the distance measuring device, calculates a time difference according to a start time of transmitting the ultrasonic waves and a start time of receiving the echoes, and finally calculates a distance between the target object and the distance measuring device according to the ultrasonic propagation speed and the time difference.

Because the environment of the distance measuring device is complex, ultrasonic waves with the same frequency range as the ultrasonic waves used for distance measurement may exist in the environment of the distance measuring device, and thus, when the distance measuring device receives the ultrasonic waves of the non-echo waves in the environment, errors exist in the calculated distance.

In order to solve the above problem, in the present embodiment, an electronic device 100 is provided, please refer to fig. 1, fig. 1 is a schematic block diagram of a structure of the electronic device 100 provided in the embodiments of the present application, where the electronic device 100 includes an ultrasonic ranging apparatus 110, a memory 120 and a processor 130, and the memory 120 and the processor 130 are electrically connected to each other directly or indirectly for implementing data interaction. For example, the components may be electrically connected to each other via one or more communication buses or signal lines. The ultrasonic ranging apparatus 110 includes at least one software function module which may be stored in the memory 120 in the form of software or firmware (firmware) or solidified in an Operating System (OS) of the electronic device 100. The processor 130 is used to execute executable modules stored in the memory 120, such as software functional modules and computer programs included in the ultrasonic ranging device 110.

The present application also provides an ultrasonic ranging method applied to the above electronic device 100, which includes steps S10-S50. Referring to FIG. 2, the following describes steps S10-S50 in detail with reference to the embodiment.

Step S10, intermittently transmitting ultrasonic waves and acquiring first state information within a first preset time period after the preset time start point.

Specifically, ultrasonic waves with the frequency within a preset frequency range are sent to the target object from a preset time starting point, and first state information of whether the ultrasonic waves are sent at each moment in a first preset time period after the preset time starting point is obtained.

In step S20, a reception time starting point at which reception of the ultrasonic wave is started is acquired.

Specifically, a receiving time starting point at which the ultrasonic wave within the preset frequency range is received for the first time within a second preset time period after the preset time starting point is obtained, where the second preset time period is greater than the first preset time period.

In step S30, second state information within a first preset time period after the start of the receiving time is obtained.

Specifically, second state information of whether the ultrasonic wave is received at each time within a first preset time period after the start of the reception time is acquired.

In step S40, it is determined whether or not the time interval between ultrasonic wave transmissions and ultrasonic wave receptions match.

Specifically, it is determined whether or not the time interval for transmitting the ultrasonic wave and the time interval for receiving the ultrasonic wave coincide, based on the first state information and the second state information.

In step S50, the distance between the electronic apparatus 100 and the target object is calculated when the time interval for transmitting the ultrasonic wave matches the time interval for receiving the ultrasonic wave.

Specifically, when the time interval for transmitting the ultrasonic wave coincides with the time interval for receiving the ultrasonic wave, the distance between the electronic apparatus 100 and the target object is calculated from the time difference between transmission and reception of the ultrasonic wave and the propagation speed of the ultrasonic wave.

In this embodiment, the first state information includes information on whether the ultrasonic wave is transmitted at each time within a first preset time period after a preset time start point. The second state information includes information whether the ultrasonic wave is received at each time within a first preset time period after the reception time start point. The time difference between the transmission and reception of the ultrasonic wave may be, but is not limited to, a time difference between a preset time start point and a reception time start point, and may be, for example, a time difference between an ultrasonic wave transmitted at a certain time after the reception time start point and a time at which the ultrasonic wave is received. Since the ultrasonic wave is reflected when it encounters an obstacle, in a case where there is no ultrasonic wave in the preset frequency range in the environment, the transmitted ultrasonic wave reaches the electronic apparatus 100 that receives the ultrasonic wave after a certain period of time due to reflection by the target object.

Therefore, in the present embodiment, it is sufficient to determine whether or not there is a received ultrasonic wave after a certain time corresponding to each time when the ultrasonic wave is transmitted. If there are no ultrasonic waves in the environment at the same frequency as the ultrasonic waves emitted by the electronic device 100, the time interval of the received ultrasonic waves is necessarily identical to the time interval of the transmitted ultrasonic waves. Therefore, in the present embodiment, by comparing the time interval between the transmission of the ultrasonic wave and the time interval between the reception of the ultrasonic wave, it is possible to determine whether or not there is interference in the environment. When the time interval for transmitting the ultrasonic wave and the time interval for receiving the ultrasonic wave are consistent, it is indicated that there is no ultrasonic wave interfering with ranging in the environment, and therefore, it is more accurate to calculate the distance between the electronic device 100 and the target object according to the time difference between the transmission and the reception of the ultrasonic wave and the propagation speed of the ultrasonic wave at this time.

Optionally, in this embodiment, step S10 includes, within the first preset time period, taking a third preset time period as the first time granularity, and intermittently transmitting, from the preset time start point to the target object, the ultrasonic waves with the frequency within the preset frequency range in units of the first time granularity, where the first preset time period includes a plurality of third preset time periods.

In brief, a first preset time period after a preset time start point is divided according to a third preset time period to obtain a plurality of time segments with a time length of the third preset time period, and each time segment is used as a first time granularity, and please refer to fig. 3 for a relationship between the first time granularity and the first preset time period. Then, when the ultrasonic waves within the preset frequency range are intermittently transmitted to the target object, the ultrasonic waves may be continuously transmitted at one first time granularity or two or more consecutive first time granularities, or the ultrasonic waves may not be transmitted at one first time granularity or two or more first time granularities, for example, for a first preset time period including 6 first time granularities, the ultrasonic waves may be continuously transmitted at first and second two consecutive first time granularities, the ultrasonic waves may not occur at a third first time granularity, and the ultrasonic waves may be transmitted at fourth, fifth, and sixth first time granularities.

Referring to fig. 4, in the present embodiment, the step S40 includes sub-steps S41-S45.

Step S41, obtaining first encoded data of a first preset time period after the start of the preset time according to the first state information.

Specifically, first coded data in a first preset time period after the preset time starting point is obtained according to first state information and first time granularity.

Step S42, obtaining second encoded data within a first preset time period after the start of the receiving time according to the second status information.

And obtaining second coded data in a first preset time period after the starting point of the receiving time according to the second state information and the first time granularity.

Step S43, determining whether the first encoded data and the second encoded data match.

In step S44, if the first encoded data matches the second encoded data, it is determined that the time interval for transmitting the ultrasonic waves matches the time interval for receiving the ultrasonic waves.

In step S45, if the first encoded data does not match the second encoded data, it is determined that the time interval for transmitting the ultrasonic waves does not match the time interval for receiving the ultrasonic waves.

In short, in this embodiment, the encoding symbol is used to represent the state of transmitting the ultrasonic wave within each first time granularity within a first preset time period after a preset time starting point, so as to convert the transmitting state of the ultrasonic wave into first encoded data, and the encoding symbol is used to represent the state of receiving the ultrasonic wave within the first time granularity within the first preset time period after the time starting point is received, so as to convert the ultrasonic wave into second encoded data. Then, whether the time interval for transmitting the ultrasonic wave matches the time interval for receiving the ultrasonic wave is determined based on the first encoded data and the second encoded data.

For example, if the ultrasonic wave is continuously transmitted within a first time granularity within a first preset time period after the preset time starting point, the symbol "1" indicates that the ultrasonic wave is not transmitted within the first time granularity, and the code "0" indicates that the ultrasonic wave is not transmitted within the first time granularity. If the ultrasonic wave is continuously received within a first time granularity after a first preset time period after the starting point of the receiving time, the symbol "1" is used for indicating, and the code "0" is used for indicating that the ultrasonic wave is not received within the first time granularity.

The following explanation is made in detail with reference to an example of actually transmitted ultrasonic waves, and if the preset frequency range is 25khz to 30khz, ultrasonic waves of 200 frequency points in total are transmitted and received at this frequency. For a frequency, for example, 25khz ultrasonic wave, it is not always in a 1 state, that is, the 25khz ultrasonic wave sound is not always present but is transmitted at intervals, so as to transmit encoded data composed of 1011101001 ultrasonic wave states, and it is necessary to receive 1011101001 corresponding ultrasonic wave to confirm that the transmission and reception of this ultrasonic wave are normal and the data are valid and reliable. If the data check of this time is failed, that is, if the encoded data composed of the transmitted ultrasonic waves and the encoded data composed of the received ultrasonic waves are not consistent, it indicates that the data of this time receives interference, and the data of this time is discarded.

Optionally, in this embodiment, referring to fig. 5, when determining whether the first encoded data and the second encoded data are consistent, the method may be performed according to steps S431 to S434.

In step S431, the first sub-coded data is acquired.

Specifically, within the first preset time period, a fourth preset time period is used as a second time granularity, and for each second time granularity in the first preset time period, a code symbol corresponding to each first time granularity in the second time granularity is obtained from the first coded data, so as to obtain first sub-coded data corresponding to the second time granularity, where the first preset time period includes a plurality of fourth preset time periods, and the fourth preset time period includes a plurality of third preset time periods. Each second temporal granularity's start point coincides with a first temporal granularity's start point, and each second temporal granularity's end point coincides with its included another temporal granularity's end point.

That is, within each first preset time period, a plurality of second time granularities are divided, wherein each second time granularity is composed of a plurality of first time granularities, and a part of the first encoded data corresponding to each second time granularity is taken as the first sub-encoded data corresponding to the second time granularity. Referring to fig. 4, in the embodiment, each of the second time granularities may be continuous, or may be spaced by one or more first time granularities.

Step S432, acquiring the second sub-coded data and determining whether the number of the second sub-coded data exceeds a preset number.

Specifically, it is determined whether second sub-coded data respectively corresponding to each first sub-coded data exists in the second coded data, and it is determined whether the second sub-coded data in the second coded data exceeds a preset number.

The present embodiment is specifically configured to determine that the number of the received ultrasonic waves is the same for the transmitted ultrasonic waves within each second time granularity.

Step S433, if the second sub-coded data exceeds a preset number, determining that the first coded data is consistent with the second coded data.

In this embodiment, the preset number may be set according to a specific ranging environment, for example, the preset number may be set to 1, 2, or more according to the possibility that the number of the moving objects in the ranging environment blocks the transmission of the ultrasonic waves.

Step S434, if the second sub-coded data does not exceed the preset number, determining that the first coded data is inconsistent with the second coded data.

In this embodiment, the ultrasonic waves transmitted within a first preset time period after the preset time starting point are divided according to the plurality of second time granularities, and the reception condition of the ultrasonic waves is judged according to the code symbol corresponding to the ultrasonic wave transmission state within each second time granularity, so that not only can the interference of the ultrasonic waves in the environment be eliminated when the distance between the target object and the electronic device 100 is calculated, but also the influence of the moving object on the ranging process can be reduced.

Referring to fig. 6, optionally, in the present embodiment, step S432 includes first, for each first sub-coded data in a first preset time period, obtaining a first identification code segment, which is composed of a first preset number of consecutive code symbols, in the first sub-coded data.

In this embodiment, each first sub-coded data may be similar to a data packet, and when the ultrasonic wave is transmitted, the transmission state of the ultrasonic wave corresponding to the first time granularity of the first preset number before each second time granularity is determined according to a predetermined rule, and the ultrasonic wave within the first time granularity can uniquely identify each second time granularity. The first identification code segment is used for identifying the transmission state combination of the ultrasonic waves corresponding to the second time granularity, and is equivalent to a data head of a data packet.

And then judging whether a second identification code segment which is the same as the first identification code segment exists in the second coded data.

In this embodiment, specifically, the first identification code segment may be compared with every first preset number of consecutive code symbols in the second coded data, so as to determine whether the second identification code segment exists.

If the second identification code segment exists in the second encoded data, checking whether the first data encoded segment is the same as the second data encoded segment, where the first data encoded segment includes a second preset number of encoded symbols after the first identification code segment, and the second data encoded segment includes a second preset number of encoded symbols after the second identification code segment, for example, one first data encoded segment (data) of the first encoded data is 1010111011, and when checking a partial row corresponding to the data in the second encoded data, it is necessary to check whether a portion corresponding to the data in the second encoded data is the same.

When the first data encoding segment is the same as the second data encoding segment, the second sub-encoded data exists in the second encoded data.

The present embodiment is configured to determine whether the ultrasonic sequence corresponding to each first sub-coded data is normally received by the electronic apparatus 100.

Optionally, in this embodiment, in the transmitted ultrasonic waves, the transmission state of the ultrasonic waves within the first time granularity corresponding to the third preset number of code symbols after each first data code segment is determined according to the transmission state of the ultrasonic waves in the first time granularity corresponding to each code symbol in the first data code segment. For example, the hash may be calculated over the code symbols in the first data code segment. The checking whether the first data encoding segment is the same as the second data encoding segment may specifically include the following steps of, first, encrypting the second data encoding segment according to a preset encryption rule to obtain a first check code composed of a plurality of encoding symbols. And then comparing a third preset number of coded symbols after the second data coding segment with the first check code.

And if the third preset number of code symbols is the same as the first check code, judging that the first data code segment is the same as the second data code segment.

And if the third preset number of code symbols is different from the first check code, judging that the first data coding section is different from the second data coding section.

In the case that the ultrasonic waves transmitted within the second time granularity are all normally reflected and received, then, in the second encoded data, there is necessarily second sub-encoded data corresponding to the first sub-encoded data of the second time granularity, and for this second sub-encoded data, the first check code obtained by encrypting the content of the second data encoding segment according to the preset encryption rule should be the same as the third preset number of encoded symbols after the second data encoding segment. Therefore, in this embodiment, by comparing the first check code corresponding to the second data encoding segment in the second sub-encoded data with the third preset number of encoded symbols after the second data encoding segment, the encoded symbols can be prevented from being compared one by one, so that the checking process is simpler, and the checking efficiency and precision can be improved.

Alternatively, step S50 includes, first, for each first sub-encoded data, calculating a first distance between the electronic device 100 and the target object from a difference between a start time of the first sub-encoded data and a start time of second sub-encoded data corresponding to the first sub-encoded data and a propagation speed of the ultrasonic wave; then, an average value of the first distances corresponding to each first sub-coded data is calculated, and a distance between the electronic device 100 and the target object is obtained.

The present embodiment is used to calculate the distance from the overall transmission and reception of the ultrasonic waves. In the specific calculation, for the case of dividing the second time granularity, the calculation may be performed by using only the first sub-coded data and the corresponding second sub-coded data. For example, the first sub-coded data A, B, C, D, and the corresponding second sub-coded data a ', B ', C ', D ', if a ' is verified, B ' is not verified, C ' is verified, and D ' is verified, then a first distance is calculated according to A, A ', a first distance is calculated according to C, C ', a first distance is calculated according to D, D ', and finally, the distance between the electronic device and the target object is calculated according to the three first distances.

In this embodiment, the distance between the electronic device 100 and the target object may be calculated by using other conventional distance calculation methods.

With reference to fig. 2, optionally, in this embodiment, the method further includes step S60. And step S60, when the time interval for sending the ultrasonic wave is inconsistent with the time interval for receiving the ultrasonic wave, adjusting the preset frequency range, and re-executing the step of intermittently sending the ultrasonic wave with the frequency within the preset frequency range from the preset time starting point to the target object according to the adjusted preset frequency range.

The embodiment is used for adjusting the frequency of the ultrasonic wave under the condition that interference exists, so that the interference is avoided, and the accuracy of the distance measurement result is ensured.

For example, the currently used ultrasonic frequency band is 200 frequency points in the 25 khz-30 khz frequency band to transmit and receive data, and if 26khz-27khz has interference, which causes data to fail to be checked all the time, the ultrasonic waves of 40 frequency points in the middle of 26khz-27khz are automatically terminated, and the ultrasonic waves of 20 frequency points in 24.5khz-25khz and 30khz-30.5khz are started to be sent, so that 200 frequency points are ensured to be sent, and the 26khz-27khz interfered frequency band is avoided.

Referring to fig. 7, another object of the present application is to provide an ultrasonic ranging apparatus 110, which includes a sending recording module 111, an obtaining module 112, a receiving recording module 113, and a distance calculating module 114. The ultrasonic ranging apparatus 110 includes a software function module which can be stored in the memory 120 in the form of software or firmware or solidified in an Operating System (OS) of the electronic device 100.

The sending and recording module 111 is configured to start to intermittently send the ultrasonic wave with the frequency within the preset frequency range to the target object from the preset time starting point, and obtain first state information of whether to send the ultrasonic wave at each time within a first preset time period after the preset time starting point.

The transmission recording module 111 in this embodiment is configured to execute step S10, and the detailed description about the transmission recording module 111 may refer to the description about step S10.

The obtaining module 112 is configured to obtain a receiving time starting point of the ultrasonic wave received within the preset frequency range for the first time within a second preset time period after the preset time starting point, where the second preset time period is greater than the first preset time period.

The obtaining module 112 in this embodiment is configured to execute step S20, and the detailed description about the obtaining module 112 may refer to the description about step S20.

The receiving and recording module 113 is configured to obtain whether second state information of the ultrasonic wave is received at each time within a first preset time period after the start of the receiving time.

The receiving recording module 113 in this embodiment is configured to execute step S30, and the detailed description about the receiving recording module 113 may refer to the description about step S30.

A distance calculating module 114, configured to determine whether a time interval for transmitting the ultrasonic wave is consistent with a time interval for receiving the ultrasonic wave according to the first state information and the second state information, and calculate a distance between the electronic device 100 and the target object according to a time difference between transmission and reception of the ultrasonic wave and a propagation speed of the ultrasonic wave when the time interval for transmitting the ultrasonic wave is consistent with the time interval for receiving the ultrasonic wave.

The reception recording module 113 in this embodiment is configured to execute the step S40, the step S50, and the detailed description of the reception recording module 113 may refer to the description of the step S40, the step S50.

It is another object of the present application to provide a readable storage medium, wherein an executable program is stored in the readable storage medium, and when the executable program is executed, the processor 130 implements the method according to any one of the embodiments.

The above description is only for various embodiments of the present application, but the scope of the present application is not limited thereto, and any person skilled in the art can easily conceive of changes or substitutions within the technical scope of the present application, and all such changes or substitutions are included in the scope of the present application. Therefore, the protection scope of the present application shall be subject to the protection scope of the claims.

19页详细技术资料下载
上一篇:一种医用注射器针头装配设备
下一篇:超声合成孔径聚焦的变压器套管内引线检测方法及系统

网友询问留言

已有0条留言

还没有人留言评论。精彩留言会获得点赞!

精彩留言,会给你点赞!