| | |
| | | #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 410 |
| | | #define RESP_RX_TO_FINAL_TX_DLY_UUS 6410 |
| | | |
| | | /* Receive response timeout. See NOTE 5 below. */ |
| | | #define RESP_RX_TIMEOUT_UUS 600 |
| | |
| | | NEARPOLL, |
| | | } tag_state=GETNEARMSG; |
| | | static dwt_config_t config = { |
| | | 5, /* Channel number. */ |
| | | 2, /* Channel number. */ |
| | | DWT_PRF_64M, /* Pulse repetition frequency. */ |
| | | DWT_PLEN_128, /* Preamble length. */ |
| | | DWT_PAC8, /* Preamble acquisition chunk size. Used in RX only. */ |
| | |
| | | sync_anc_id = ancid; |
| | | } |
| | | } |
| | | #define RESP_MSG_POLL_RX_TS_IDX 26 |
| | | #define RESP_MSG_RESP_TX_TS_IDX 30 |
| | | #define RESP_MSG_ANC_DISTOFFSET 34 |
| | | #define FREQ_OFFSET_MULTIPLIER (998.4e6/2.0/1024.0/131072.0) |
| | | #define FREQ_OFFSET_MULTIPLIER_110KB (998.4e6/2.0/8192.0/131072.0) |
| | | #define HERTZ_TO_PPM_MULTIPLIER_CHAN_1 (-1.0e6/3494.4e6) |
| | | #define HERTZ_TO_PPM_MULTIPLIER_CHAN_2 (-1.0e6/3993.6e6) |
| | | #define HERTZ_TO_PPM_MULTIPLIER_CHAN_3 (-1.0e6/4492.8e6) |
| | | #define HERTZ_TO_PPM_MULTIPLIER_CHAN_5 (-1.0e6/6489.6e6) |
| | | int32_t test2; |
| | | float clockOffsetRatio; |
| | | double rtd_init, rtd_resp; |
| | | double distance; |
| | | int32_t twociceju; |
| | | uint32_t anc_pollrx1,anc_resptx1,tag_resprx1; |
| | | int16_t anc_distoffset1; |
| | | void CalculateDists_two(uint32_t resprx,uint8_t* resptx,uint8_t* pollrx,uint8_t * distoffset) |
| | | { |
| | | |
| | | memcpy(&anc_pollrx1,pollrx,4); |
| | | memcpy(&anc_resptx1,resptx,4); |
| | | memcpy(&tag_resprx1,&resprx,4); |
| | | memcpy(&anc_distoffset1,distoffset,2); |
| | | |
| | | |
| | | clockOffsetRatio = test2 * (FREQ_OFFSET_MULTIPLIER * HERTZ_TO_PPM_MULTIPLIER_CHAN_2 / 1.0e6) ; |
| | | rtd_init = tag_resprx1 - poll_tx_ts; |
| | | rtd_resp = anc_resptx1 - anc_pollrx1; |
| | | tof = ((rtd_init - rtd_resp * (1 - clockOffsetRatio)) / 2.0) * DWT_TIME_UNITS; |
| | | distance = tof * SPEED_OF_LIGHT; |
| | | if(distance>-1000&&distance<100000) |
| | | twociceju= distance*100+anc_distoffset1; |
| | | } |
| | | uint8_t acc_buff1[4100]; |
| | | uint16_t changdu; |
| | | uint16_t fp1; |
| | | void NearPoll(void) |
| | | { |
| | | |
| | |
| | | flag_getresponse=0; |
| | | start_count=HAL_LPTIM_ReadCounter(&hlptim1); |
| | | recbase_num=0; |
| | | timeout=ceil((float)nearbase_num*SLOT_SCALE)+3; |
| | | timeout=ceil((float)nearbase_num*SLOT_SCALE)+13; |
| | | end_count=start_count+(timeout<<5); |
| | | if(end_count>=32768) |
| | | { |
| | |
| | | dwt_write32bitreg(SYS_STATUS_ID, SYS_STATUS_RXFCG | SYS_STATUS_TXFRS);//清楚寄存器标志位 |
| | | frame_len = dwt_read32bitreg(RX_FINFO_ID) & RX_FINFO_RXFLEN_MASK; //获得接收到的数据长度 |
| | | dwt_readrxdata(rx_buffer, frame_len, 0); //读取接收数据 |
| | | test2 = dwt_readcarrierintegrator(); |
| | | fp1 = dwt_read16bitoffsetreg(0x15, 5); |
| | | dwt_readaccdata(acc_buff1,4064,0); |
| | | dwt_setrxtimeout(0);//DELAY_BETWEEN_TWO_FRAME_UUS*(nearbase_num+1-recbase_num)+10);//设定接收超时时间,0位没有超时时间 |
| | | dwt_rxenable(0);//打开接收 |
| | | if (rx_buffer[MESSAGE_TYPE_IDX] == NEAR_RESPONSE&&!memcmp(&rx_buffer[TAG_ID_IDX],&dev_id,2)&&rx_buffer[GROUP_ID_IDX]==group_id) //判断接收到的数据是否是response数据 |
| | |
| | | nearbase_num=1; |
| | | memcpy(&tx_near_msg[ANCHOR_ID_IDX],&rec_nearbaseid,2); |
| | | } |
| | | // CalculateDists_two(resp_rx_ts,&rx_buffer[RESP_MSG_RESP_TX_TS_IDX],&rx_buffer[RESP_MSG_POLL_RX_TS_IDX],&rx_buffer[RESP_MSG_ANC_DISTOFFSET]); |
| | | if(rec_nearbaseid==nearbaseid_list[0]) |
| | | { |
| | | //////////////////////////////////时间同步 |
| | |
| | | } |
| | | // dwt_write32bitreg(SYS_STATUS_ID,SYS_STATUS_RXFCG| SYS_STATUS_ALL_RX_ERR); |
| | | } |
| | | CalculateDists_two(resp_rx_ts,&rx_buffer[RESP_MSG_RESP_TX_TS_IDX],&rx_buffer[RESP_MSG_POLL_RX_TS_IDX],&rx_buffer[RESP_MSG_ANC_DISTOFFSET]); |
| | | usart_send[0] = 0x55; |
| | | usart_send[1] = 0xAA; |
| | | usart_send[2] = 1;//正常模式 |
| | | changdu=1+2+2+4+2+10+4064; |
| | | memcpy(&usart_send[3],&changdu,2); |
| | | memcpy(&usart_send[5],&dev_id,2); |
| | | memcpy(&usart_send[7],&twociceju,4); |
| | | memcpy(&usart_send[11],&fp1,2); |
| | | USART_puts(usart_send,23); |
| | | USART_puts(acc_buff1,4064); |
| | | usart_send[0] = 0x55; |
| | | usart_send[1] = 0xBB; |
| | | USART_puts(usart_send,2); |
| | | if(mainbase_lost_count>tag_frequency*BASELOST_STOPMOTOR_TIME) |
| | | { |
| | | motor_state=0; |
| | |
| | | } |
| | | } |
| | | #ifdef USART_INTEGRATE_OUTPUT |
| | | usart_send[0] = 0x55; |
| | | usart_send[1] = 0xAA; |
| | | usart_send[2] = 4;//正常模式 |
| | | usart_send[3] = report_num*6+2;//正常模式 |
| | | checksum = Checksum_u16(&usart_send[2],report_num*6+2); |
| | | memcpy(&usart_send[4+report_num*6],&checksum,2); |
| | | USART_puts(usart_send,6+report_num*6); |
| | | // usart_send[0] = 0x55; |
| | | // usart_send[1] = 0xAA; |
| | | // usart_send[2] = 4;//正常模式 |
| | | // usart_send[3] = report_num*6+2;//正常模式 |
| | | // checksum = Checksum_u16(&usart_send[2],report_num*6+2); |
| | | // memcpy(&usart_send[4+report_num*6],&checksum,2); |
| | | // USART_puts(usart_send,6+report_num*6); |
| | | #endif |
| | | |
| | | for(i=0; i<MAX_NEARBASE_NUM; i++) |