From 0d1b2a9e6b47bf4850a69b5daeb7eb17eb0215a7 Mon Sep 17 00:00:00 2001 From: guanjiao <sqrgj@163.com> Date: 星期六, 15 九月 2018 20:44:01 +0800 Subject: [PATCH] 修改滤波参数 --- 源码/核心板/Src/application/dw_app.c | 62 ++++++++++++++++++++++--------- 1 files changed, 44 insertions(+), 18 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 822a810..84ee3d2 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" @@ -26,6 +26,10 @@ #include "dw_driver.h" #include "Spi.h" #include "led.h" +#include "serial_at_cmd_app.h" +#include "Usart.h" +#include "global_param.h" +#include "filters.h" /*------------------------------------ Marcos ------------------------------------------*/ @@ -45,13 +49,13 @@ #define POLL_TX_TO_RESP_RX_DLY_UUS 150 /* This is the delay from Frame RX timestamp to TX reply timestamp used for calculating/setting the DW1000's delayed TX function. This includes the * frame length of approximately 2.66 ms with above configuration. */ -#define RESP_RX_TO_FINAL_TX_DLY_UUS 4100 +#define RESP_RX_TO_FINAL_TX_DLY_UUS 1500 /* Receive response timeout. See NOTE 5 below. */ -#define RESP_RX_TIMEOUT_UUS 14700 +#define RESP_RX_TIMEOUT_UUS 2700 -#define POLL_RX_TO_RESP_TX_DLY_UUS 3600 +#define POLL_RX_TO_RESP_TX_DLY_UUS 420 /* This is the delay from the end of the frame transmission to the enable of the receiver, as programmed for the DW1000's wait for response feature. */ -#define RESP_TX_TO_FINAL_RX_DLY_UUS 500 +#define RESP_TX_TO_FINAL_RX_DLY_UUS 200 /* Receive final timeout. See NOTE 5 below. */ #define FINAL_RX_TIMEOUT_UUS 4300 @@ -74,18 +78,17 @@ /*------------------------------------ Variables ------------------------------------------*/ /* Default communication configuration. We use here EVK1000's default mode (mode 3). */ -static dwt_config_t config = -{ - 2, /* Channel number. */ - DWT_PRF_64M, /* Pulse repetition frequency. */ - DWT_PLEN_1024, /* Preamble length. */ - DWT_PAC32, /* Preamble acquisition chunk size. Used in RX only. */ - 9, /* TX preamble code. Used in TX only. */ - 9, /* RX preamble code. Used in RX only. */ - 1, /* Use non-standard SFD (Boolean) */ - DWT_BR_110K, /* Data rate. */ - DWT_PHRMODE_STD, /* PHY header mode. */ - (1025 + 64 - 32) /* SFD timeout (preamble length + 1 + SFD length - PAC size). Used in RX only. */ +static dwt_config_t config = { + 5, /* Channel number. */ + DWT_PRF_64M, /* Pulse repetition frequency. */ + DWT_PLEN_128, /* Preamble length. */ + 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) */ + 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. */ }; /* Frames used in the ranging process. See NOTE 2 below. */ @@ -127,6 +130,10 @@ uint8_t random_delay_tim = 0; double distance, dist_no_bias, dist_cm; + +uint32_t g_UWB_com_interval = 0; +float dis_after_filter; //当前距离值 +LPFilter_Frac* p_Dis_Filter; //测距用的低通滤波器 /*------------------------------------ Functions ------------------------------------------*/ @@ -221,7 +228,9 @@ /* Configure DW1000. See NOTE 6 below. */ dwt_configure(&config);//配置DW1000 + + /* Apply default antenna delay value. See NOTE 1 below. */ dwt_setrxantennadelay(RX_ANT_DLY); //设置接收天线延迟 dwt_settxantennadelay(TX_ANT_DLY); //设置发射天线延迟 @@ -232,10 +241,20 @@ dwt_setrxtimeout(RESP_RX_TIMEOUT_UUS); //设置接收超时时间 } +void tag_sleep_configuraion(void) +{ + dwt_configuresleep(0x940, 0x7); + dwt_entersleep(); +} + void Tag_App(void)//发送模式(TAG标签) { uint32_t frame_len; uint32_t final_tx_time; + + GPIO_ResetBits(SPIx_GPIO, SPIx_CS); + delay_us(2000); + GPIO_SetBits(SPIx_GPIO, SPIx_CS); /* Write frame data to DW1000 and prepare transmission. See NOTE 7 below. */ tx_poll_msg[ALL_MSG_SN_IDX] = frame_seq_nb; @@ -317,7 +336,8 @@ } LED0_BLINK; /* Execute a delay between ranging exchanges. */ - deca_sleep(RNG_DELAY_MS + random_delay_tim); //休眠固定时间 + dwt_entersleep(); + } void Anchor_App(void) @@ -333,7 +353,10 @@ /* Poll for reception of a frame or error/timeout. See NOTE 7 below. */ while (!((status_reg = dwt_read32bitreg(SYS_STATUS_ID)) & (SYS_STATUS_RXFCG | SYS_STATUS_ALL_RX_ERR)))//不断查询芯片状态直到接收成功或者出现错误 - { }; + { + UART_CheckReceive(); + UART_CheckSend(); + }; if (status_reg & SYS_STATUS_RXFCG)//成功接收 { @@ -430,7 +453,10 @@ dist_cm = dist_no_bias * 100; //dis 为单位为cm的距离 // dist[TAG_ID] = LP(dis, TAG_ID); //LP 为低通滤波器,让数据更稳定 + /*--------------------------以下为非测距逻辑------------------------*/ LED0_BLINK; //每成功一次通讯则闪烁一次 + g_UWB_com_interval = 0; + dis_after_filter = LP_Frac_Update(p_Dis_Filter, dist_cm); } } -- Gitblit v1.9.3