Principle and Realization of UWB Ranging

1. Ranging

Distance (length) is one of the most commonly used physical quantities. The measurement of distance is the most common in our daily life, such as the measurement of the length and size of objects in daily life and work, and the measurement of human height.
insert image description here

Length is a measure of one-dimensional space and is the distance from point to point. The international unit of length is "meter" ("m"), commonly used units are kilometers (km), meters (m), decimeters (dm), centimeters (cm), millimeters (mm), micrometers (μm), nanometers (nm) and so on. The national standard for length measurement is GBT1219-2000.
insert image description here

2. Ranging method

2.1 Measuring ruler distance measurement

Using a ruler with a scale to directly measure the distance, this method is easy to operate and has high accuracy.
insert image description here

2.2 Line-of-sight ranging

Some measuring instruments use the line of sight to measure distance, and the instrument uses the principles of optics and trigonometry to determine the distance between two points. Common line-of-sight measuring instruments include theodolite, flat plate, level and so on. These instruments pass through the line-of-sight wire inside the telescope. The distance between the line-of-sight wire on the scale is called the line-of-sight reading. The distance between the instrument and the scale is a function of the distance between the scales. The measurement accuracy of most line-of-sight measuring instruments can reach 1/400 . The distance measuring principle of the level gauge is as follows:
insert image description here

2.3 Ultrasonic ranging

Some devices use ultrasonic waves to measure distances. The principle of ultrasonic distance measurement is to use ultrasonic transmitters to emit ultrasonic waves, and start timing while emitting ultrasonic waves. Ultrasonic waves propagate in the air and return immediately when they encounter obstacles. The ultrasonic receiver receives reflected waves. Immediately stop the timer. The propagation speed of ultrasonic waves in the air is 340m/s. According to the time t (seconds) recorded by the timer, the distance s between the emission point and the obstacle can be calculated: s=340*t/2
insert image description here

2.4 Laser ranging

The laser rangefinder is an instrument that uses laser to measure the distance of the target. There are roughly three methods of distance measurement: pulse method, phase method and triangular reflection method . The working principle of the pulsed laser range finder is relatively simple. Here is a brief description of the pulsed laser range finder. Its working principle is to shoot a short pulse laser beam to the target. The component receives the reflected laser beam, and the timer measures the time from emission to reception of the laser beam, and calculates the distance from the observer to the target.

The laser propagates in the air at the speed c, and the time required for the laser to go back and forth between two points A and B is t, then the distance D between the two points A and B can be expressed as follows.
insert image description here

In the formula: D is the distance between the station A and B; c is the speed of light propagating in the atmosphere; t is the time required for light to go back and forth between A and B once.
  insert image description here
In addition to the above-mentioned ranging methods, there is also a more popular ranging method in recent years (which is the protagonist we are going to talk about today): UWB ranging .
insert image description here

3. UWB technology and application

UWB technology is a wireless communication technology using frequencies above 1GHz . UWB does not use a sinusoidal carrier, but uses narrow pulses of nanoseconds to transmit data . UWB occupies a large spectrum range, and its data transmission rate can reach hundreds of megabits per second. UWB technology uses ultra-wide baseband pulses for communication, and is mainly used in communication systems for military radar, positioning and low interception rates. In February 2002, the Federal Communications Commission of the United States issued preliminary regulations on the spectrum and power used by civilian UWB equipment. In this regulation, the communication system that transmits data bandwidth greater than 500MHz in the 3.1~10.6GHz frequency band is called UWB system.
insert image description here
UWB technology uses a pulse with a very low duty cycle as the carrier-free spread spectrum technology of the information carrier. It directly modulates the shock pulse with a very steep rise and fall time. The shock pulse usually adopts a single-cycle Gaussian pulse, and one information bit can be mapped to hundreds of such pulses. The width of the single-cycle pulse is on the order of nanoseconds and has a very wide frequency spectrum.
insert image description here
UWB technology solves the major problems in communication that have plagued traditional wireless communication technology for many years. UWB technology has the following characteristics:

1. Simple realization of system structure
2. High-speed data transmission
3. Low power consumption
4. High security
6. Precise positioning
7. Low system cost

Realization of UWB The realization of
UWB system structure is relatively simple, and the UWB transmitter directly excites the transmitter with low-cost pulses. During high-speed data transmission, the transmission range of UWB signals is generally required to be within 10 m, and its transmission rate can reach more than 500 Mbit/s. The UWB system uses gap pulses to send data, has a very low duty cycle, and the system power consumption can be very low. During high-speed communication, the power consumption of the system is only a few hundred μW to tens of mW. The picture shows the basic circuit structure of the ultra-wideband wireless communication system:
insert image description here
UWB application
1. Communication application , the communication speed based on UWB technology can reach 1Gb/s. When the transmission distance is very short, the speed advantage of UWB communication is more obvious. It is very suitable for VR, mobile phone file transfer, wireless networking and other fields.
2. Ranging applications , based on UWB technology, can achieve high-precision distance measurement, and solve problems such as range and aiming. Suitable for social distance tracing, item loss prevention, etc.

3. Positioning applications . Based on UWB technology, indoor and outdoor high-precision positioning can be realized. This is the most advantageous application of UWB technology. UWB positioning can be applied to high-precision positioning in various complex environments. For example: prison personnel location management, activity trajectory tracking, personnel location management in high-risk workplaces, etc.

4. Encryption and authentication applications , due to the high security of UWB communication, it is suitable for mobile payment, authentication, credit card, ID card, swiping card, etc.

4. Ranging medium and algorithm

Before explaining the principle of UWB ranging, let's first understand the two probabilities in the ranging process:
1. The ranging medium , the medium or tool used for distance measurement.
2. Distance measurement algorithm , the distance calculation method used in distance measurement.

Based on these two concepts, we will use the ranging medium and ranging algorithm for the several distance measurement methods mentioned in the second chapter.

Measuring ruler distance
Measuring medium: measuring ruler with scale.
Distance measurement algorithm: the minimum difference method, find the scale with the smallest difference between the measured object and the scale scale, and use this scale value as the measurement distance.

Line-of-sight ranging
Ranging medium: optical imaging.
Ranging algorithm: Approximation method, adjusting the optical focal length or position, so that the line of sight in the optical lens is close to the target. When the line of sight in the optical lens matches the target, the distance is determined according to the optical parameters.

Ultrasonic distance measurement
Distance measurement medium: ultrasonic.
Ranging algorithm: time-of-flight (TOF), by recording the time difference between the ultrasonic wave being transmitted and receiving the ultrasonic echo, the distance value is obtained by multiplying the sound propagation speed by the time.

Laser distance measurement
Distance measurement medium: laser.
Ranging algorithm: time-of-flight (TOF), by recording the time difference between laser emission and receiving laser echo, the distance value is obtained by multiplying the speed of light by time.

UWB distance measurement
distance measurement medium: UWB electromagnetic wave.
Ranging algorithm: time of flight (TOF), the time error information in the received radio signal, the time difference is calculated according to the time stamp, and the distance value is obtained by multiplying the radio propagation speed by the time.

Time stamp difference method
We can use the time stamp method to calculate the time difference. We use an example to describe the time stamp algorithm :
For example, a friend wrote us a paper letter, and at the end of the letter, the friend wrote down The date when the letter was sent was October 1, 2022. After a long journey, the postman delivered the letter to our home. We opened the letter and read the date (October 1, 2022) and then according to the date of receipt of the envelope, October 2022 On August 8, based on these two dates, it was calculated that the letter took a total of 8 days from sending to receiving .
This is the timestamp algorithm. We add time during the communication process, and the receiver can calculate the time difference between sending and receiving the information based on the time when the information is received (the time of the receiver and the sender are synchronized).
insert image description here
We calculate that it takes a total of 8 days from sending to receiving the letter, assuming that the average speed of the postman sending letters is 200km per day, so we can conclude that the distance between our friend's house and our home is about 1600km, which is measured by the time stamp difference method distance .

5. UWB ranging principle and algorithm

Principle of UWB ranging

The principle of UWB ranging is to use the time stamp difference method to calculate the flight time of electromagnetic waves , thereby calculating the distance. There are two kinds of entities in the UWB ranging application:
1. The base station, which is fixedly installed somewhere for calculating distance and outputting data.
2. The label is installed on the target object to be measured.
insert image description here

The base station and the tag use UWB communication, and there is a time stamp in the communication process, so the base station can calculate the distance between the tag and the base station according to the time stamp . The block diagram of UWB timestamp implementation is as follows:
insert image description here

The tag initiates communication, and the communication data contains the time information t1 of sending data. When the base station receives the data, it first records the receiving time t2, and then extracts the sending time from the received information (assuming that the time of the base station and the tag are synchronized), according to The flight time t=t2-t1 is calculated from the sending timestamp and the receiving timestamp , and the distance from the tag to the base station is calculated d= (c * t )/2 , where c is the speed of light.
The above description is just a brief introduction to the basic principle of UWB measuring distance by using the time stamp method, but the actual application is not as simple as shown in the above figure. In practical application, the UWB ranging algorithm is divided into: two-way ranging (TWR) and Bilateral two-way ranging (ADSTWR).

UWB ranging algorithm

Two-way ranging (TWR)
Two-way ranging is also called TWR (Two-Way-Ranging). The base station initiates a ranging request and records the time t1. After the tag receives the request, it records the receiving time t2, and then the tag responds with a response, replying The response information includes two times t2 (reception request time) and t3 (response request time). When the base station receives the response, it records the reception time t4. At this time, the base station has 4 times: t1, t2, t3, t4, so The flight time T=( (t4 - t1) - (t3 - t2) )/ 2 , calculate the distance D= T*c between the base station and the tag. The block diagram of the algorithm is as follows:
insert image description here
Question 1: Why not use t2 - t1 or t4 - t3 directly for the time of flight?
Because the time of the two devices, the base station and the tag, is not synchronized, it is very difficult for the two devices to synchronize time!

Question 2: How to solve the time synchronization problem?
We carefully observe the four times t1, t2, t3, and t4. It is not difficult to find that t1 and t4 are the time recorded by the base station, and these two times are synchronized; t2 and t3 are the time recorded by the label. These two times is synchronous. So we use (t4 - t1) - (t3 - t2) to get the time of flight, so that the time synchronization of the two devices, the base station and the tag, is not required .

TWR algorithm perfectly solves the problem? In fact, this is not the case. Let's take the time difference (t4 - t1) recorded by the base station as an example. Is there an error in this time difference? We assume that the main frequency of the MCU is 10Mhz, and the counter in the timer will increase by one every clock cycle. We know the time according to the counter . For example, the value of the counter is 800. At this time, we think the time is 80us.

But is the main frequency of the MCU really working at 10Mhz? It is impossible for every MCU to work at an absolute 10Mhz! There is an error in the working main frequency of every MCU. Assuming that the main frequency error of the MCU is 1%, the corresponding real time when the counter value is 800 is 79.2us (80 * 0.99), the time error is 0.8us, and the distance error is 120m !
insert image description here
According to the calculation, it can be seen that when the time difference recorded by the base station is greater, the time error will be greater. t = T * P, where t is the error time, T is the recorded time difference, and P is the clock error.

Bilateral Two-Way Ranging (ADSTWR)

ADSTWR (Asymetic double side two way ranging) is an upgraded and improved version of TWR (to improve the problem of large errors in the TWR algorithm), ADS-TWR adds a transmission on the basis of TWR , and improves the time calculation method. The block diagram of the algorithm is as follows:
insert image description here
According to these three communications, two flight times can be calculated:

T1  =  ( (t4 - t1)  -  (t3 - t2) ) / 2
T2  =  ( (t6 - t3)  -  (t5 - t4) ) / 2

Since the time between the two measurements is very short, it can be considered that the distance has not changed and the flight time is also equal, so:

T1  =  T2

We can find the average flight time by two flight times:

T~  =  ( T1  +  T2 )/2  = ( ( (t4 - t1)  -  (t3 - t2) ) +  ( (t6 - t3)  -  (t5 - t4) ) )  / 4

Let's convert the formula:

Ta	=	t4 - t1
Tb	=	t3 - t2
Tc	=	t6 - t3
Td	=	t5 - t4

then:

T1  =  ( Ta 	-  Tb ) / 2 
T2  =  (Tc	-  Td ) / 2 
T~   =  ( ( Ta  -  Tb) +  ( Tc  -  Td ) )  / 4

This algorithm is the same as the TWR algorithm, so the error is the same! So we have to change the algorithm!

A known:

T1  =  ( Ta 	-  Tb ) / 2
T2  =  (Tc	-  Td ) / 2
T1  =  T2

Convert:

Ta 	= 	2*T1	  +  Tb
Tc 	= 	2*T2  +  Td

Ta*Tc 	=  ( 2*T1  +  Tb ) *(2*T2  +  Td)
		=  ( 2*T1  +  Tb ) *(2*T1  +  Td)
		=  4*T1*T1  +  2*T1*Td  +  2*T1*Tb  +  Tb*Td

then:

Ta*Tc  -   Tb*Td  =   4*T1*T1  +  2*T1*Td  +  2*T1*Tb 
Ta*Tc  -   Tb*Td  =   T1*(4*T1  +  2*Td  +  2*Tb )

in:

4*T1  = (2*T1)  + ( 2*T2)  =  (Ta  -  Tb)  +  (Tc	-  Td )

then:

Ta*Tc  -   Tb*Td  =  T1*( (Ta  -  Tb)  +  (Tc  -  Td )  +  2*Td  +  2*Tb )
Ta*Tc  -   Tb*Td  =  T1*(Ta +  Tc  +  Td  +  Tb)

and end up with:

T1  =  (Ta*Tc  -   Tb*Td ) /(Ta +  Tc  +  Td  +  Tb)

The error generated by this algorithm has little to do with the processing time of the response sent after receiving the frame. The same clock error ADSTWR has higher ranging accuracy than TWR (this algorithm is used in our software algorithm design) .

6. UWB ranging embedded design

This section introduces the hardware and software design of the UWB base station. The MCU of the base station circuit uses STM32F103, the base station uses the DW1000 chip for UWB communication, and the base station uses a lithium battery for power supply. The circuit schematic diagram of the base station is as follows:
insert image description here
The UWB positioning circuit is based on the UWB positioning system of DecaWave DW1000 series. DW1000 uses the SPI interface. The relevant circuits are as follows:
insert image description here

software architecture

The overall architecture of the embedded software is shown in the figure: it is mainly divided into driver layer, DW_API layer and application layer.
insert image description here
The driver layer mainly realizes the SPI communication between STM32 and DWIC, uses the HAL library for development, completes SPI configuration, interrupt configuration, IIC configuration, serial port configuration, watchdog configuration, etc., connects to the DW_API layer, and completes the driver layer construction.

The DW_API layer uses DecaWave's official API for transplantation and construction. The API encapsulates common functions. The main functions of DWIC are basically realized by reading and writing the corresponding registers. You can get a general understanding of common API functions through the simple example in the official API combined with DW1000_Software_API_Guide.pdf .

The application layer is the implementation code that realizes the main functions of TWR ranging, and completes the functions of system status reading, parameter configuration, TWR data sending and receiving, TOF calculation, Kalman filtering, and serial data sending.

Workflow of the main program
The main program is located in Src/application/dw_main.c, which mainly completes the initialization of device parameters and the operation of the base station or label state machine according to the status of the DIP switch
, and finally packs and sends the serial data. The working process of the base station is realized by the state machine, which completes the whole process of single-cycle ADSTWR. The main working process is shown in the figure: the
Please add a picture description
code source code is as follows :

void anchor_app(void)
{
    
    
    switch (state)
    {
    
    
        case STA_INIT_POLL_BLINK: //初始化接收机,接收poll消息

            dwt_setpreambledetecttimeout(0);                        //清除前导码超时,一直接收
            dwt_setrxtimeout(0);                                    //清除接收数据超时,一直接收
            int ret = dwt_rxenable(DWT_START_RX_IMMEDIATE);         //打开接收机,等待接收数据    
            rx_status = RX_WAIT;                                    //清rx标志位,中断服务函数更改其状态
            state = STA_WAIT_POLL_BLINK; 
			/*  省略代码*/
            break;
        
        case STA_WAIT_POLL_BLINK:                                   //等待poll消息,中断回调函数状态变更
        
            if(rx_status == RX_OK)                                  //接收到数据
            {
    
    
                rx_status = RX_WAIT;

                    state = STA_RECV_POLL_BLINK;
            }
            else if((rx_status == RX_TIMEOUT)||(rx_status == RX_ERROR))  //接收数据错误,重新开启接收
            {
    
    
                state = STA_INIT_POLL_BLINK;
            }
			/*  省略代码*/
            break;

        case STA_RECV_POLL_BLINK://接收处理poll消息
            if(rx_buffer[FUNC_CODE_IDX] == FUNC_CODE_POLL)      //判断收到的数据是POLL
            {
    
    
                range_nb = rx_buffer[RANGE_NB_IDX];             //取range_nb,resp发送时发送相同的range_nb
                recv_tag_id = rx_buffer[SENDER_SHORT_ADD_IDX];  //取发送标签的ID
                if(recv_tag_id >= inst_slot_number)             //标签ID如果大于标签总容量则退出
                {
    
    
                    state = STA_INIT_POLL_BLINK;
                    break;
                }
                range_time = portGetTickCnt();  //取得测距时间
                poll_rx_ts = get_rx_timestamp_u64(); //获得poll_rx时间戳
				/*  省略代码*/
            }
            else //非POLL数据重新开启接收POLL
            {
    
    
                state = STA_INIT_POLL_BLINK;
            }
			/*  省略代码*/
            break;

        case STA_SORR_RESP://根据基站ID按顺序进行发送或接收resp消息
            
            if(sr > 0)// sr>0 处于resp阶段,按基站ID判断接收resp或发送resp
            {
    
    
                if(rr & 0x01)//当前该基站需发送resp
                {
    
    
                    rr = 0;
                    state = STA_SEND_RESP;
                }
                else//当前该基站需接收resp
                {
    
    
                    dwt_setdelayedtrxtime(resp_rx_time);         //设置接收机开启延时时间
                    dwt_setrxtimeout(inst_resp_rx_timeout);      //设置接收数据超时时间
                    dwt_setpreambledetecttimeout(PRE_TIMEOUT);   //设置接收前导码超时时间
                    int ret = dwt_rxenable(DWT_START_RX_DELAYED);          //延时开启接收机
                    if(ret == DWT_ERROR)
                    {
    
    
                        state = STA_INIT_POLL_BLINK;
                        break;
                    }   
                    rr = rr >> 1;
                    state = STA_WAIT_RESP;
                }
                sr = sr - 1; 
				/*  省略代码*/				
            }
            else//准备接收final
            {
    
          
				/*  省略代码*/
                dwt_setrxtimeout(inst_final_rx_timeout);       //设置接收数据超时时间
                dwt_setpreambledetecttimeout(PRE_TIMEOUT);     //设置接收前导码超时时间
                int ret = dwt_rxenable(DWT_START_RX_DELAYED);            //延时开启接收机
                if(ret == DWT_ERROR)
                {
    
    
                    state = STA_INIT_POLL_BLINK;
                    break;
                }   
                state = STA_WAIT_FINAL;
            }
            break;

        case STA_SEND_RESP: //打包发送resp消息
        {
    
    
			/*  省略代码*/
            /* resp数据打包 */
            tx_resp_msg[SEQ_NB_IDX] = frame_seq_nb++;
            tx_resp_msg[RANGE_NB_IDX] = range_nb;
            tx_resp_msg[SENDER_SHORT_ADD_IDX] = anc_id;
            tx_resp_msg[RECEIVER_SHORT_ADD_IDX] = recv_tag_id;
            tx_resp_msg[FUNC_CODE_IDX] = FUNC_CODE_RESP;

			/*  省略代码*/
            state = STA_SORR_RESP;
        }
            break;

        case STA_WAIT_RESP:  //等待接收resp消息,在中断回调函数内rx_status状态变更
            if(rx_status == RX_OK)
            {
    
    
                rx_status = RX_WAIT;
                state = STA_RECV_RESP;
            }
            else if((rx_status == RX_TIMEOUT)||(rx_status == RX_ERROR))
            {
    
    
                rx_status = RX_WAIT;
                state = STA_SORR_RESP;
            }   
            break;

            case STA_RECV_RESP: //接收到其他基站的resp消息
            {
    
    
                if(rx_buffer[FUNC_CODE_IDX] == FUNC_CODE_RESP)//正确接收到resp消息
                {
    
    
                    if(rx_buffer[RANGE_NB_IDX] == range_nb)//和当前测距具有相同的range_nb
                    {
    
    
                        uint8_t recv_anc_id = rx_buffer[SENDER_SHORT_ADD_IDX]; //取基站ID
                        distance_report[recv_anc_id]  = (int32_t)rx_buffer[RESP_MSG_PREV_DIS_IDX]   << 24;
                        distance_report[recv_anc_id] += (int32_t)rx_buffer[RESP_MSG_PREV_DIS_IDX+1] << 16;
                        distance_report[recv_anc_id] += (int32_t)rx_buffer[RESP_MSG_PREV_DIS_IDX+2] << 8;
                        distance_report[recv_anc_id] += (int32_t)rx_buffer[RESP_MSG_PREV_DIS_IDX+3];
                    }
                }
                state = STA_SORR_RESP;
            }
                break;
        

        case STA_WAIT_FINAL:  //等待接收final消息,在中断回调函数内rx_status状态变更
            if(rx_status == RX_OK)
            {
    
    

                {
    
    
                    state = STA_RECV_FINAL;
                }

            }
            else if((rx_status == RX_TIMEOUT)||(rx_status == RX_ERROR))
            {
    
    
                rx_status = RX_WAIT;
                state = STA_INIT_POLL_BLINK;
                range_status = RANGE_ERROR; 
            }
            break;

        case STA_RECV_FINAL:  //接收到final消息,数据处理
            if ((rx_buffer[FUNC_CODE_IDX] == FUNC_CODE_FINAL) && (rx_buffer[RANGE_NB_IDX] == range_nb))
            {
    
    
                resp_valid = rx_buffer[FINAL_MSG_FINAL_VALID_IDX];
                if((resp_valid >> anc_id) & 0x01) //final消息中,本基站发送的resp消息是有效的,则进行距离计算
                {
    
    
                    uint32_t poll_tx_ts, resp_rx_ts, final_tx_ts;
                    uint32_t poll_rx_ts_32, resp_tx_ts_32, final_rx_ts_32;
                    double Ra, Rb, Da, Db;
                    int64_t tof_dtu;
                    double tof;


                    resp_tx_ts = get_tx_timestamp_u64();   //取得resp_tx时间戳
                    final_rx_ts = get_rx_timestamp_u64();  //取得final_rx时间戳

                    /* 从final消息中,取得poll_tx时间戳,resp_rx时间戳,final_tx时间戳 */
                    final_msg_get_ts(&rx_buffer[FINAL_MSG_POLL_TX_TS_IDX], &poll_tx_ts);
                    final_msg_get_ts(&rx_buffer[FINAL_MSG_RESP1_RX_TS_IDX + anc_id * FINAL_MSG_TS_LEN], &resp_rx_ts);
                    final_msg_get_ts(&rx_buffer[FINAL_MSG_FINAL_TX_TS_IDX], &final_tx_ts);

                    /* 计算飞行时间 */
                    poll_rx_ts_32 = (uint32_t)poll_rx_ts;
                    resp_tx_ts_32 = (uint32_t)resp_tx_ts;
                    final_rx_ts_32 = (uint32_t)final_rx_ts;
                    Ra = (double)(resp_rx_ts - poll_tx_ts);
                    Rb = (double)(final_rx_ts_32 - resp_tx_ts_32);
                    Da = (double)(final_tx_ts - resp_rx_ts);
                    Db = (double)(resp_tx_ts_32 - poll_rx_ts_32);
                    tof_dtu = (int64_t)((Ra * Rb - Da * Db) / (Ra + Rb + Da + Db));

                    tof = (int32)tof_dtu; 
                    if (tof > 0x7FFFFFFF) 
                    {
    
    
                        tof -= 0x80000000;  
                    }

                    tof = tof * DWT_TIME_UNITS;
                    distance_now_m = tof * SPEED_OF_LIGHT;

                    if(distance_now_m > 20000.000)  
                    {
    
    
                        distance_now_m = -1;
                    }

                    distance_now_m = distance_now_m - (float)distance_offset_cm/100.0f;


                    //将上次的测距值写入distance_report用于串口输出
                    distance_report[anc_id] = prev_range[recv_tag_id].distance;
                    
                    //更新prev_range为本次测距值
                    prev_range[recv_tag_id].distance = distance_now_m * 1000;//单位转换为mm
                    prev_range[recv_tag_id].range_nb = range_nb;

                    valid_report = resp_valid;
					/*  省略代码*/
                }
            }
            dwt_forcetrxoff();
            state = STA_INIT_POLL_BLINK;
            break;
        
        default:
            break;
    }
    
}

Ranging algorithm related code :

poll_rx_ts_32 = (uint32_t)poll_rx_ts;
resp_tx_ts_32 = (uint32_t)resp_tx_ts;
final_rx_ts_32 = (uint32_t)final_rx_ts;
Ra = (double)(resp_rx_ts - poll_tx_ts);
Rb = (double)(final_rx_ts_32 - resp_tx_ts_32);
Da = (double)(final_tx_ts - resp_rx_ts);
Db = (double)(resp_tx_ts_32 - poll_rx_ts_32);
tof_dtu = (int64_t)((Ra * Rb - Da * Db) / (Ra + Rb + Da + Db));

tof = (int32)tof_dtu; 

tof = tof * DWT_TIME_UNITS;
distance_now_m = tof * SPEED_OF_LIGHT;

The formula corresponding to the code:
**T1  =  (Ta*Tc  -   Tb*Td ) /(Ta +  Tc  +  Td  +  Tb)**

Thanks:
insert image description here

CSDN: https://blog.csdn.net/li_man_man_man
Today's headlines: https://www.toutiao.com/article/7149576260891443724
Creation is not easy, I hope friends like, forward, comment, follow!
Your likes, forwards, Comments and attention will be my driving force for continuous updates!

Guess you like

Origin blog.csdn.net/li_man_man_man/article/details/127709991