| | |
| | | uint32_t g_UWB_com_interval = 0; |
| | | float dis_after_filter; //当前距离值 |
| | | LPFilter_Frac* p_Dis_Filter; //测距用的低通滤波器 |
| | | |
| | | float range_lost_time = 0; |
| | | |
| | | |
| | | static uint64_t get_tx_timestamp_u64(void) |
| | |
| | | /* Apply default antenna delay value. See NOTE 1 below. */ |
| | | dwt_setrxantennadelay(RX_ANT_DLY); //设置接收天线延迟 |
| | | dwt_settxantennadelay(TX_ANT_DLY); //设置发射天线延迟 |
| | | // dwt_configcontinuousframemode(12480); |
| | | // dwt_writetxdata(13, usart_send, 0);//将Poll包数据传给DW1000,将在开启发送时传出去 |
| | | // dwt_writetxfctrl(13, 0);//设置超宽带发送数据长度 |
| | | // dwt_starttx(DWT_START_TX_IMMEDIATE);//开启发送,发送完成后等待一段时间开启接收,等待时间在dwt_setrxaftertxdelay中设置 |
| | | |
| | | //while(1) |
| | | //{} |
| | | /* 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. */ |
| | | //设置接收超时时间 |
| | |
| | | distance = tof * SPEED_OF_LIGHT; |
| | | if(distance>-10&&distance<1000) |
| | | nearbase_distlist[i] = distance*100+anc_distoffset[i]; |
| | | range_lost_time=0; |
| | | }else{ |
| | | // nearbase_distlist[i] = 0x1ffff; |
| | | } |
| | |
| | | |
| | | } |
| | | u16 numceshi; |
| | | float range_lost_time = 0; |
| | | u16 rec_nearbaseid,rec_nearbasepos; |
| | | extern u16 poll_startcount; |
| | | u16 Poll_30s_id[200],Poll_30s_dist[200]; |
| | | u8 Poll_30s_num; |
| | | void NearPoll(void) |
| | | { |
| | | |
| | |
| | | memcpy(&tx_near_msg[ANCHOR_ID_IDX],&mainbase_id,2); |
| | | dwt_writetxdata(13+4*nearbase_num, tx_near_msg, 0);//将Poll包数据传给DW1000,将在开启发送时传出去 |
| | | dwt_writetxfctrl(13+4*nearbase_num, 0);//设置超宽带发送数据长度 |
| | | current_count=HAL_LPTIM_ReadCounter(&hlptim1); |
| | | while(current_count<poll_startcount||current_count>poll_startcount+16384) |
| | | { |
| | | current_count=HAL_LPTIM_ReadCounter(&hlptim1); |
| | | if(current_count<poll_startcount-300) |
| | | { |
| | | break; |
| | | } |
| | | } |
| | | |
| | | dwt_starttx(DWT_START_TX_IMMEDIATE | DWT_RESPONSE_EXPECTED);//开启发送,发送完成后等待一段时间开启接收,等待时间在dwt_setrxaftertxdelay中设置 |
| | | HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, GPIO_PIN_RESET); |
| | | numceshi++; |
| | | tx_near_msg[TAGCONFIGSUCCESS_INDEX] =0; |
| | | para_update = 0; |
| | |
| | | flag_getresponse=0; |
| | | start_count=HAL_LPTIM_ReadCounter(&hlptim1); |
| | | recbase_num=0; |
| | | timeout=nearbase_num*SLOT_SCALE+20; //单位0.1ms |
| | | timeout=nearbase_num*SLOT_SCALE+100; //单位0.1ms |
| | | end_count=start_count+(timeout<<2); |
| | | if(end_count>=32768) |
| | | {end_count-=32768;} |
| | |
| | | current_count=HAL_LPTIM_ReadCounter(&hlptim1); |
| | | while (!((status_reg = dwt_read32bitreg(SYS_STATUS_ID)) & (SYS_STATUS_RXFCG | SYS_STATUS_ALL_RX_ERR)))//不断查询芯片状态直到成功接收或者发生错误 |
| | | { |
| | | if(flag_finalsend&&flag_ancreadpara) |
| | | { |
| | | dw_systime=dwt_readsystimestamphi32(); |
| | | if(dw_systime>temp1&&dw_systime<temp2) |
| | | { |
| | | |
| | | dwt_forcetrxoff(); |
| | | flag_rxon=0; |
| | | if(flag_ancreadpara) //只有在读取参数的时候需要回复 |
| | | { |
| | | u16 calCRC; |
| | | tx_near_msg[MESSAGE_TYPE_IDX] = MBX_PRAAREPLY; |
| | | memcpy(&tx_near_msg[MESSAGE_PARAREPLY_IDX],g_com_map,SENDANCPARA_LEN); |
| | | calCRC = CRC_Compute((uint8_t*)g_com_map,SENDANCPARA_LEN); |
| | | memcpy(&tx_near_msg[MESSAGE_PARAREPLY_IDX+SENDANCPARA_LEN],&calCRC,2); |
| | | dwt_writetxdata(14+SENDANCPARA_LEN, tx_near_msg, 0);//将发送数据写入DW1000 |
| | | dwt_writetxfctrl(14+SENDANCPARA_LEN, 0);//设定发送数据长度 |
| | | |
| | | dwt_setdelayedtrxtime(final_tx_time); |
| | | result=dwt_starttx(DWT_START_TX_DELAYED);//设定为延迟发送 |
| | | } |
| | | flag_finalsend=0; |
| | | break; |
| | | } |
| | | } |
| | | current_count=HAL_LPTIM_ReadCounter(&hlptim1); |
| | | if(current_count>=end_count&¤t_count<end_count+15000) |
| | | break; |
| | |
| | | recbase_num++; |
| | | memcpy(&rec_nearbaseid,&rx_buffer[ANCHOR_ID_IDX],2); |
| | | rec_remotepara_state = rx_buffer[MOTORSTATE_INDEX]>>4; |
| | | TagFreqProcess(rx_buffer[TAGFREQ_IDX]); |
| | | freqlost_count = 0; |
| | | // TagFreqProcess(rx_buffer[TAGFREQ_IDX]); |
| | | // if(rec_nearbaseid==0x9002) |
| | | // {rec_remotepara_state = rx_buffer[MOTORSTATE_INDEX]>>4;} |
| | | if(rec_remotepara_state != 0) |
| | | { |
| | | para_update = rec_remotepara_state; |
| | |
| | | if((rx_buffer[MOTORSTATE_INDEX]&0xf)!=3) |
| | | motor_state=rx_buffer[MOTORSTATE_INDEX]&0xf; |
| | | |
| | | |
| | | mainbase_lost_count=0; |
| | | flag_finalsend=1; |
| | | memcpy(&mainbase_dist,&rx_buffer[DIST_IDX],4); |
| | | final_tx_time = (resp_rx_ts + ((RESP_RX_TO_FINAL_TX_DLY_UUS+DELAY_BETWEEN_TWO_FRAME_UUS*nearbase_num+500) * UUS_TO_DWT_TIME)) >> 8; |
| | | temp1=final_tx_time-((850*UUS_TO_DWT_TIME)>>8); |
| | | temp2=final_tx_time+((100*UUS_TO_DWT_TIME)>>8); |
| | | // dwt_setdelayedtrxtime(final_tx_time);//设置final包发送时间T5 |
| | | final_tx_ts = (((uint64_t)(final_tx_time & 0xFFFFFFFE)) << 8) + TX_ANT_DLY;//final包实际发送时间是计算时间加上发送天线delay |
| | | final_msg_set_ts(&tx_near_msg[FINAL_MSG_POLL_TX_TS_IDX], poll_tx_ts);//将T1,T4,T5写入发送数据 |
| | | final_msg_set_ts(&tx_near_msg[FINAL_MSG_RESP_RX_NEARBASE_IDX], resp_rx_ts); |
| | | final_msg_set_ts(&tx_near_msg[FINAL_MSG_FINAL_TX_TS_IDX], final_tx_ts); |
| | | tx_near_msg[MESSAGE_TYPE_IDX]=MBX_FINAL; |
| | | tx_near_msg[GROUP_ID_IDX] = group_id; |
| | | |
| | | dwt_writetxdata(28+nearbase_num*4, tx_near_msg, 0);//将发送数据写入DW1000 |
| | | dwt_writetxfctrl(28+nearbase_num*4, 0);//设定发送数据长度 |
| | | flag_getresponse=1; |
| | | memcpy(&rec_tagpos_binary,&rx_buffer[NEARMSG_EMPTYSLOTPOS_INDEX],4); |
| | | |
| | | }else{ |
| | | rec_nearbasepos=FindNearBasePos(rec_nearbaseid); |
| | | SetANCTimestap(rec_nearbasepos,&rx_buffer[RESP_MSG_POLL_RX_TS_IDX],&rx_buffer[RESP_MSG_RESP_TX_TS_IDX],resp_rx_ts,&rx_buffer[RESP_MSG_ANC_DISTOFFSET]); |
| | |
| | | } |
| | | } |
| | | nearbase_num = next_nearbase_num; |
| | | if(mainbase_lost_count>1&&exsistbase_list[0] != 0) |
| | | if(mainbase_lost_count>1)//&&exsistbase_list[0] != 0) |
| | | { |
| | | last_lpcount+= HAL_LPTIM_ReadCounter(&hlptim1)%(g_com_map[COM_INTERVAL]*16); |
| | | last_lpcount-= HAL_LPTIM_ReadCounter(&hlptim1)%(g_com_map[COM_INTERVAL]*16); |
| | | } |
| | | last_nearbase_num = next_nearbase_num; |
| | | for(i=0;i<last_nearbase_num-1;i++) |
| | |
| | | } |
| | | delay_us(100); |
| | | g_Resttimer=0; |
| | | if(freqlost_count>FREQ_LOST_TIME) |
| | | { |
| | | if(regpoll_count++>11) //待机状态1分钟上传一次基站状态 |
| | | { |
| | | regpoll_count = 0; |
| | | Registor_Poll(); |
| | | } |
| | | }else{ |
| | | if(regpoll_count++>59)//测距状态1分钟上传一次基站状态 |
| | | { |
| | | regpoll_count = 0; |
| | | Registor_Poll(); |
| | | } |
| | | } |
| | | // if(freqlost_count>FREQ_LOST_TIME) |
| | | // { |
| | | // if(regpoll_count++>11) //待机状态1分钟上传一次基站状态 |
| | | // { |
| | | // regpoll_count = 0; |
| | | // Registor_Poll(); |
| | | // } |
| | | // }else{ |
| | | // if(regpoll_count++>59)//测距状态1分钟上传一次基站状态 |
| | | // { |
| | | // regpoll_count = 0; |
| | | // Registor_Poll(); |
| | | // } |
| | | // } |
| | | NearPoll(); |
| | | dwt_entersleep(); |
| | | bat_percent=Get_VDDVlotage(); |