From bbb6a0f1379f06a06a9a2414fd847539ec4f122e Mon Sep 17 00:00:00 2001 From: zhyinch <zhyinch@gmail.com> Date: 星期日, 15 十二月 2019 19:37:02 +0800 Subject: [PATCH] 跟踪微分器调试完成,V1.12 --- 源码/核心板/Src/application/dw_app.c | 45 +++++++++++++++++++++++++++++++++------------ 1 files changed, 33 insertions(+), 12 deletions(-) diff --git "a/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/application/dw_app.c" "b/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/application/dw_app.c" index 4c8db75..def4780 100644 --- "a/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/application/dw_app.c" +++ "b/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/application/dw_app.c" @@ -94,7 +94,7 @@ DWT_PAC8, /* Preamble acquisition chunk size. Used in RX only. */ 9, /* TX preamble code. Used in TX only. */ 9, /* RX preamble code. Used in RX only. */ - 0, /* Use non-standard SFD (Boolean) */ + 1, /* Use non-standard SFD (Boolean) */ DWT_BR_6M8, /* Data rate. */ DWT_PHRMODE_STD, /* PHY header mode. */ (129 + 8 - 8) /* SFD timeout (preamble length + 1 + SFD length - PAC size). Used in RX only. */ @@ -145,7 +145,7 @@ float dis_after_filter; //当前距离值 LPFilter_Frac* p_Dis_Filter; //测距用的低通滤波器 -uint16_t g_Tagdist[TAG_NUM_IN_SYS]; +int32_t g_Tagdist[TAG_NUM_IN_SYS]; uint8_t g_flag_Taggetdist[256]; /*------------------------------------ Functions ------------------------------------------*/ @@ -238,7 +238,7 @@ for(i=0;i<255;i++) { g_flag_Taggetdist[i]++; - if(g_flag_Taggetdist[i]>=2) + if(g_flag_Taggetdist[i]>=20) { g_Tagdist[i]=0xffff; } @@ -313,7 +313,7 @@ uint16_t g_Resttimer; uint8_t result; u8 tag_succ_times=0; -int32_t hex_dist; +int32_t hex_dist,hex_dist2; u16 checksum; int8_t tag_delaytime; extern uint16_t sync_timer; @@ -395,7 +395,7 @@ } TIM3->CNT=tmp_time; } - memcpy(&anchor_dist_last_frm[0], &rx_buffer[DIST_IDX], 4); + memcpy(&hex_dist2, &rx_buffer[DIST_IDX], 4); memcpy(&tx_final_msg[ANCHOR_ID_IDX], &rx_buffer[ANCHOR_ID_IDX], 4); /* Compute final message transmission time. See NOTE 9 below. */ final_tx_time = (resp_rx_ts + (RESP_RX_TO_FINAL_TX_DLY_UUS * UUS_TO_DWT_TIME)) >> 8;//计算final包发送时间,T5=T4+Treply2 @@ -418,7 +418,7 @@ tag_succ_times++; LED0_BLINK; - hex_dist = anchor_dist_last_frm[0]; + memcpy(&anc_id_recv,&rx_buffer[ANCHOR_ID_IDX],2); // g_Tagdist[anc_id_recv]= hex_dist; // g_flag_Taggetdist[anc_id_recv]=0; @@ -430,7 +430,7 @@ memcpy(&usart_send[5],&dev_id,2); memcpy(&usart_send[7],&rx_buffer[ANCHOR_ID_IDX],2); - memcpy(&usart_send[9],&hex_dist,4); + memcpy(&usart_send[9],&hex_dist2,4); usart_send[13] = battary; usart_send[14] = button; checksum = Checksum_u16(&usart_send[2],17); @@ -474,12 +474,13 @@ } int8_t correction_time; extern uint8_t sync_seq; +#define TDFILTER void Anchor_App(void) { uint32_t frame_len; uint32_t resp_tx_time; - + static u8 misdist_num; /* Clear reception timeout to start next ranging process. */ dwt_setrxtimeout(0);//设定接收超时时间,0位没有超时时间 @@ -603,7 +604,7 @@ distance = tof * SPEED_OF_LIGHT;//距离=光速*飞行时间 dist_no_bias = distance - dwt_getrangebias(config.chan, (float)distance, config.prf); //距离减去矫正系数 - dist_cm = dist_no_bias * 100; //dis 为单位为cm的距离 + dist_cm = dist_no_bias * 1000; //dis 为单位为cm的距离 // dist[TAG_ID] = LP(dis, TAG_ID); //LP 为低通滤波器,让数据更稳定 /*--------------------------以下为非测距逻辑------------------------*/ @@ -611,14 +612,28 @@ g_UWB_com_interval = 0; dis_after_filter=dist_cm; hex_dist = dist_cm+(int16_t)g_com_map[DIST_OFFSET]; + if(hex_dist-anchor_dist_last_frm[tag_id_recv-TAG_ID_START]<15000||misdist_num>4) + {int32_t filter_dist; + misdist_num=0; + if(hex_dist<1000000&&hex_dist>-10000) + { if(tag_id_recv-TAG_ID_START<=TAG_NUM_IN_SYS) - if(abs(hex_dist-his_dist[tag_id_recv-TAG_ID_START])<1000&&hex_dist<100000) + { + if(abs(hex_dist-his_dist[tag_id_recv-TAG_ID_START])<10000) { g_Tagdist[tag_id_recv-TAG_ID_START] = hex_dist; anchor_dist_last_frm[tag_id_recv-TAG_ID_START] = hex_dist; + + #ifdef TDFILTER + TrackingDiffUpdate(pUWBDistanceTrackingDiff, (float)hex_dist); + filter_dist=pUWBDistanceTrackingDiff->pos_predict/10; + #else + filter_dist=hex_dist/10; + #endif + anchor_dist_last_frm[tag_id_recv-TAG_ID_START]=filter_dist; + g_Tagdist[tag_id_recv]= anchor_dist_last_frm[tag_id_recv-TAG_ID_START]; } his_dist[tag_id_recv-TAG_ID_START]=hex_dist; - g_Tagdist[tag_id_recv]= anchor_dist_last_frm[tag_id_recv-TAG_ID_START]; g_flag_Taggetdist[tag_id_recv]=0; if(!g_com_map[MODBUS_MODE]) { @@ -639,7 +654,13 @@ Modbus_HoldReg[tag_id_recv*2]=anchor_dist_last_frm[tag_id_recv-TAG_ID_START]>>16; Modbus_HoldReg[tag_id_recv*2+1]=anchor_dist_last_frm[tag_id_recv-TAG_ID_START]; //dis_after_filter = LP_Frac_Update(p_Dis_Filter, dist_cm); - + } + } + }else{ + misdist_num++; + } + if(anchor_dist_last_frm[tag_id_recv-TAG_ID_START]>1000) + {anchor_dist_last_frm[tag_id_recv-TAG_ID_START]=anchor_dist_last_frm[tag_id_recv-TAG_ID_START];} } }else{ /* Clear RX error events in the DW1000 status register. */ -- Gitblit v1.9.3