OpenEdv-开源电子网

 找回密码
 立即注册
正点原子全套STM32/Linux/FPGA开发资料,上千讲STM32视频教程免费下载...
查看: 3154|回复: 3

请教下dwm1000使用ds方式,增加标签后距离相差很大?

[复制链接]

260

主题

809

帖子

0

精华

金牌会员

Rank: 6Rank: 6

积分
1896
金钱
1896
注册时间
2012-10-28
在线时间
357 小时
发表于 2017-11-30 21:40:06 | 显示全部楼层 |阅读模式
10金钱
请教下,使用官网的ds方式,增加标签后距离相差很大?

刚开始时使用的一个基站对应一个标签,误差大概在 30cm左右,

目前使用一个基站对多高标签(目前测试的是2个标签),测得的距离貌似比实际距离多了10.5M左右,这个是怎么个情况啊 ?

标签程序如下:

/* 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. */
};


/* Default antenna delay values for 64 MHz PRF. See NOTE 1 below. */
#define TX_ANT_DLY 16436
#define RX_ANT_DLY 16436


/* As "TX then wait for a response" example sends a blink message encoded as per the ISO/IEC 24730-62:2013 standard which includes a bit signalling
* that a response is listened for, this example will respond with a valid frame (that will be ignored anyway) following the same standard. The
* response is a 21-byte frame composed of the following fields:
*     - byte 0/1: frame control (0x8C41 to indicate a data frame using 16-bit source addressing and 64-bit destination addressing).
*     - byte 2: sequence number, incremented for each new frame.
*     - byte 3/4: application ID (0x609A for data frames in this standard).
*     - byte 5 -> 12: 64-bit destination address.
*     - byte 13/14: 16-bit source address, hard coded in this example to keep it simple.
*     - byte 15: function code (0x10 to indicate this is an activity control message).
*     - byte 16: activity code (0x00 to indicate activity is finished).
*     - byte 17/18: new tag blink rate.
*     - byte 19/20: frame check-sum, automatically set by DW1000.
*/
/// *作为“TX然后等待响应”示例发送按照ISO / IEC 24730-62:2013标准编码的闪烁消息,其包括位信令
//?*响应被监听,这个例子将按照相同的标准响应一个有效的帧(无论如何将被忽略)。该
//?*响应是由以下字段组成的21个字节的帧:
//?* - 字节0/1:帧控制(0x8C41表示使用16位源寻址和64位目标寻址的数据帧)。
//?* - 字节2:  ID号,
//?* - 字节3/4:应用程序ID(本标准中的数据帧为0x609A)。
//?* - 字节5 - > 12:64位目标地址。
//?* - 字节13/14:16位源地址,在本例中用硬编码保持简单。
//?* - 字节15:功能码(0x10表示这是一个活动控制信息)。
//?* - 字节16:活动代码(0x00表示活动已完成)。
//?* - 字节17/18:新的标签闪烁频率。
//?* - 字节19/20:帧校验和,由DW1000自动设置。 * /

/* Frames used in the ranging process. See NOTE 2 below. */
static uint8 tx_poll_msg[] = {0x41, 0x88, TAG_USER_ID, 0xCA, 0xDE, 'W', 'A', 'V', 'E', 0x21,  0, 0};   // 倒数第3byte位标签编号,也就是TAG_USER_ID
static uint8 rx_resp_msg[] = {0x41, 0x88, TAG_USER_ID, 0xCA, 0xDE, 'V', 'E', 'W', 'A', 0x10, 0x02,  0, 0, 0, 0};
static uint8 tx_final_msg[] = {0x41, 0x88, TAG_USER_ID, 0xCA, 0xDE, 'W', 'A', 'V', 'E', 0x23,  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};

/* Length of the common part of the message (up to and including the function code, see NOTE 2 below).
        消息的公共部分的长度(直到并包括功能代码,参见下面的注2)*/
#define ALL_MSG_COMMON_LEN 10
       
       
/* Index to access some of the fields in the frames involved in the process.
索引来访问过程中涉及的帧中的一些字段        */
#define ALL_MSG_SN_IDX 2
#define FINAL_MSG_POLL_TX_TS_IDX 10
#define FINAL_MSG_RESP_RX_TS_IDX 14
#define FINAL_MSG_FINAL_TX_TS_IDX 18
#define FINAL_MSG_TS_LEN 4
       
/* Frame sequence number, incremented after each transmission..帧序列号,在每次传输后递增 */
//static uint8 frame_seq_nb = 0;

/* Buffer to store received messages.
* Its size is adjusted to longest frame that this example code is supposed to handle.
缓冲区来存储收到的消息。 它的大小被调整到这个示例代码应该处理的最长帧        */
#define RX_BUF_LEN 20
static uint8 rx_buffer[RX_BUF_LEN];

/* Hold copy of status register state here for reference so that it can be examined at a debug breakpoint.
在此处保存状态寄存器状态的副本,以便在调试断点处进行检查*/
static uint32 status_reg = 0;

/* UWB microsecond (uus) to device time unit (dtu, around 15.65 ps) conversion factor.
* 1 uus = 512 / 499.2 祍 and 1 祍 = 499.2 * 128 dtu.
UWB微秒(uus)到器件时间单位(dtu,大约15.65 ps)转换因子 */
#define UUS_TO_DWT_TIME 65536

/* Delay between frames, in UWB microseconds. See NOTE 4 below. */
/* 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 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 3100

/* Receive response timeout. See NOTE 5 below. */
#define RESP_RX_TIMEOUT_UUS 2700


/* Time-stamps of frames transmission/reception, expressed in device time units.
* As they are 40-bit wide, we need to define a 64-bit int type to handle them. */
static uint64_t poll_tx_ts;
static uint64_t resp_rx_ts;
static uint64_t final_tx_ts;

/* Declaration of static functions. */
static uint64_t get_tx_timestamp_u64(void);
static uint64_t get_rx_timestamp_u64(void);
static void final_msg_set_ts(uint8_t *ts_field, uint64_t ts);

//uint32_t BeginTime, EndTime;

uint8_t Tag_Number_ID = TAG_USER_ID;   // tag 编号,每个 tag 都有自己的编号,固定不变
uint8_t Tag_Number_ID_bak = 0xff;    // 赋初值





void bsp_distanceInit(void)
{
        reset_DW1000();

  // 开始初始化 dw1000 模块
        spi_set_rate_low();
        // dw1000 初始化完成后,吧spi设置为高
        dwt_initialise(DWT_LOADUCODE);
        spi_set_rate_high();

        dwt_configure(&config);

        /* Apply default antenna delay value. See NOTE 1 below. */
        dwt_setrxantennadelay(RX_ANT_DLY);
        dwt_settxantennadelay(TX_ANT_DLY);

        /* Set expected response's delay and timeout. See NOTE 4 and 5 below.
         * As this example only handles one incoming frame with always the same
         delay and timeout, those values can be set here once for all. */
//        dwt_setrxaftertxdelay(POLL_TX_TO_RESP_RX_DLY_UUS);
//        dwt_setrxtimeout(RESP_RX_TIMEOUT_UUS);
}




void bsp_distanceCode(void)
{
        /* Write frame data to DW1000 and prepare transmission. See NOTE 7 below. */
//        tx_poll_msg[ALL_MSG_SN_IDX] = frame_seq_nb;
        dwt_writetxdata(sizeof(tx_poll_msg), tx_poll_msg, 0);
        dwt_writetxfctrl(sizeof(tx_poll_msg), 0);

                                dwt_setrxaftertxdelay(POLL_TX_TO_RESP_RX_DLY_UUS);  //设定发送后打开接收的时间
                                dwt_setrxtimeout(RESP_RX_TIMEOUT_UUS);                          //设定接收超时的时间
               
        /* Start transmission, indicating that a response is expected so that reception is enabled automatically after the frame is sent and the delay
         * set by dwt_setrxaftertxdelay() has elapsed. */
        dwt_starttx(DWT_START_TX_IMMEDIATE | DWT_RESPONSE_EXPECTED); //立即发送,并在一段时间后打开接收

        /* We assume that the transmission is achieved correctly, poll for reception of a frame or error/timeout. See NOTE 8 below. */
        while (!((status_reg = dwt_read32bitreg(SYS_STATUS_ID)) & (SYS_STATUS_RXFCG | SYS_STATUS_ALL_RX_ERR)))
        { }

        /* Increment frame sequence number after transmission of the poll message (modulo 256). */
//        frame_seq_nb++;

                                if (status_reg & SYS_STATUS_RXFCG)
                                {
                                                uint32 frame_len;
            /* Clear good RX frame event and TX frame sent in the DW1000 status register. */
            dwt_write32bitreg(SYS_STATUS_ID, SYS_STATUS_RXFCG | SYS_STATUS_TXFRS);

            /* A frame has been received, read it into the local buffer. */
            frame_len = dwt_read32bitreg(RX_FINFO_ID) & RX_FINFO_RXFLEN_MASK;
            if (frame_len <= RX_BUF_LEN)
            {
                dwt_readrxdata(rx_buffer, frame_len, 0);
            }

            /* Check that the frame is the expected response from the companion "DS TWR responder" example.
             * As the sequence number field of the frame is not relevant, it is cleared to simplify the validation of the frame. */
        //    rx_buffer[ALL_MSG_SN_IDX] = 0;
                                //                Tag_Number_ID_bak = rx_buffer[ALL_MSG_SN_IDX];
                                               
                                                if(rx_buffer[ALL_MSG_SN_IDX] == TAG_USER_ID)   // id 号等于本机id继续发送响应信息,否则退出重新从头开始发送poll 包
                                                {
                                                        if (memcmp(rx_buffer, rx_resp_msg, ALL_MSG_COMMON_LEN) == 0)
                                                        {
                                                                        uint32 final_tx_time;

                                                                        /* Retrieve poll transmission and response reception timestamp. */
                                                                        poll_tx_ts = get_tx_timestamp_u64();
                                                                        resp_rx_ts = get_rx_timestamp_u64();

                                                                        /* 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;
                                                                        dwt_setdelayedtrxtime(final_tx_time);

                                                                        /* Final TX timestamp is the transmission time we programmed plus the TX antenna delay. */
                                                                        final_tx_ts = (((uint64_t)(final_tx_time & 0xFFFFFFFE)) << 8) + TX_ANT_DLY;

                                                                        /* Write all timestamps in the final message. See NOTE 10 below. 在最后的留言写所有的时间戳。见下文注10 */
                                                                        final_msg_set_ts(&tx_final_msg[FINAL_MSG_POLL_TX_TS_IDX], poll_tx_ts);
                                                                        final_msg_set_ts(&tx_final_msg[FINAL_MSG_RESP_RX_TS_IDX], resp_rx_ts);
                                                                        final_msg_set_ts(&tx_final_msg[FINAL_MSG_FINAL_TX_TS_IDX], final_tx_ts);

                                                                        /* Write and send final message. See NOTE 7 below. */
                                                                        tx_final_msg[ALL_MSG_SN_IDX] = TAG_USER_ID;  //frame_seq_nb;
                                                                        dwt_writetxdata(sizeof(tx_final_msg), tx_final_msg, 0);
                                                                        dwt_writetxfctrl(sizeof(tx_final_msg), 0);
                                                                        dwt_starttx(DWT_START_TX_DELAYED);

                                                                        /* Poll DW1000 until TX frame sent event set. See NOTE 8 below. */
                                                                        while (!(dwt_read32bitreg(SYS_STATUS_ID) & SYS_STATUS_TXFRS))
                                                                        { };

                                                                        /* Clear TXFRS event. */
                                                                        dwt_write32bitreg(SYS_STATUS_ID, SYS_STATUS_TXFRS);

                                                                        /* Increment frame sequence number after transmission of the final message (modulo 256). */
        //                frame_seq_nb++;
                                                                               
                                                        }
                                                }
                                                else{
                                                       
            /* Clear RX error events in the DW1000 status register. */
            dwt_write32bitreg(SYS_STATUS_ID, SYS_STATUS_ALL_RX_ERR);
                                               
                                                }
                                }

        else
        {
            /* Clear RX error events in the DW1000 status register. */
            dwt_write32bitreg(SYS_STATUS_ID, SYS_STATUS_ALL_RX_ERR);
        }

}






// ==============================================================================================
// ==============================================================================================

基站程序:

/* 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. */
};


/* Default antenna delay values for 64 MHz PRF. See NOTE 1 below. */
#define TX_ANT_DLY 16436
#define RX_ANT_DLY 16436


/* As "TX then wait for a response" example sends a blink message encoded as per the ISO/IEC 24730-62:2013 standard which includes a bit signalling
* that a response is listened for, this example will respond with a valid frame (that will be ignored anyway) following the same standard. The
* response is a 21-byte frame composed of the following fields:
*     - byte 0/1: frame control (0x8C41 to indicate a data

正点原子逻辑分析仪DL16劲爆上市
回复

使用道具 举报

530

主题

11万

帖子

34

精华

管理员

Rank: 12Rank: 12Rank: 12

积分
165524
金钱
165524
注册时间
2010-12-1
在线时间
2116 小时
发表于 2017-12-1 00:32:51 | 显示全部楼层
回复

使用道具 举报

260

主题

809

帖子

0

精华

金牌会员

Rank: 6Rank: 6

积分
1896
金钱
1896
注册时间
2012-10-28
在线时间
357 小时
 楼主| 发表于 2017-12-1 14:05:23 | 显示全部楼层

目前看来是要dwm1000 的人们不多啊
回复

使用道具 举报

9

主题

38

帖子

0

精华

新手上路

积分
48
金钱
48
注册时间
2018-2-8
在线时间
20 小时
发表于 2018-5-30 23:53:47 | 显示全部楼层
楼主有成功吗,能不能分享一下
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则



关闭

原子哥极力推荐上一条 /2 下一条

正点原子公众号

QQ|手机版|OpenEdv-开源电子网 ( 粤ICP备12000418号-1 )

GMT+8, 2025-6-2 20:16

Powered by OpenEdv-开源电子网

© 2001-2030 OpenEdv-开源电子网

快速回复 返回顶部 返回列表