|
你看看这里,需要标签发送给基站的时候增加代码
- #define DISTANCE3 0.27
- //**************************************************************//
- //distance1 anthor0 <--> TAG mm
- //distance2 anthor1 <--> TAG mm
- //distance3 anthor2 <--> TAG mm
- //**************************************************************//
- int framenum = 0 ;
- static void compute_angle_send_to_anthor0(int distance1, int distance2,int distance3)
- {
- #if 0 //compute angle for smartcar
- float dis3_constans = DISTANCE3;
- float cos = 0;
- float angle = 0 ;
- float dis1 = (float)distance1/1000; //m
- float dis2 = (float)distance2/1000; //m
- if(dis1 + dis3_constans < dis2 || dis2+dis3_constans < dis1)
- {
- }
- cos = (dis1*dis1 + dis3_constans* dis3_constans - dis2*dis2)/(2*dis1*dis3_constans);
- angle = acos(cos)*180/3.1415926;
- printf("cos = %f, arccos = %f\r\n",cos,angle);
- sprintf(dist_str, "angle: %3.2f m", angle);
- OLED_ShowString(0, 6," ");
- OLED_ShowString(0, 6,dist_str);
- if(dis1 > 1)
- {
- if(angle > 110)
- {
- printf("turn right\r\n");
- angle_msg[10] = 'R';
- }
- else if(angle < 75)
- {
- printf("turn left\r\n");
- angle_msg[10] = 'L';
- }
- else
- {
- printf("forward\r\n");
- angle_msg[10] = 'F';
- }
- }
- else
- {
- printf("stay here\r\n");
- angle_msg[10] = 'S';
- }
- angle_msg[LOCATION_FLAG_IDX] = 0;
- #else
- //location
- {
- uint8 len = 0;
- angle_msg[LOCATION_FLAG_IDX] = 1;
- angle_msg[LOCATION_INFO_START_IDX + (len++)] = 'm';
- angle_msg[LOCATION_INFO_START_IDX + (len++)] = 'r';
- angle_msg[LOCATION_INFO_START_IDX + (len++)] = 0x02;
- angle_msg[LOCATION_INFO_START_IDX + (len++)] = TAG_ID;//TAG ID
- angle_msg[LOCATION_INFO_START_IDX + (len++)] = (uint8)(framenum&0xFF);
- angle_msg[LOCATION_INFO_START_IDX + (len++)] = (uint8)((framenum>>8)&0xFF);
- angle_msg[LOCATION_INFO_START_IDX + (len++)] = (uint8)((distance1/10)&0xFF);
- angle_msg[LOCATION_INFO_START_IDX + (len++)] = (uint8)((distance1/10 >>8)&0xFF);
- angle_msg[LOCATION_INFO_START_IDX + (len++)] = (uint8)((distance2/10)&0xFF);
- angle_msg[LOCATION_INFO_START_IDX + (len++)] = (uint8)((distance2/10 >>8)&0xFF);
- angle_msg[LOCATION_INFO_START_IDX + (len++)] = (uint8)((distance3/10)&0xFF);
- angle_msg[LOCATION_INFO_START_IDX + (len++)] = (uint8)((distance3/10 >>8)&0xFF);
- if(ANCHOR_MAX_NUM > 3)
- {
- angle_msg[LOCATION_INFO_START_IDX + (len++)] = (uint8)((Anthordistance[3]/10)&0xFF);
- angle_msg[LOCATION_INFO_START_IDX + (len++)] = (uint8)((Anthordistance[3]/10 >>8)&0xFF);
- }
- else
- {
- angle_msg[LOCATION_INFO_START_IDX + (len++)] = (uint8)((distance1/10)&0xFF);
- angle_msg[LOCATION_INFO_START_IDX + (len++)] = (uint8)((distance1/10 >>8)&0xFF);
- }
- angle_msg[LOCATION_INFO_START_IDX + (len++)] = '\n';
- angle_msg[LOCATION_INFO_START_IDX + (len++)] = '\r';
- angle_msg[LOCATION_INFO_LEN_IDX] = len;
- //MAX LEN
- if(LOCATION_INFO_START_IDX + len -2 >ANGLE_MSG_MAX_LEN)
- {
- while(1);
- }
- //USART_puts((char*)angle_msg,len);
- }
- #endif
- //only anthor0 recive angle message
- //angle_msg[ALL_MSG_SN_IDX] = framenum;
- angle_msg[ALL_MSG_TAG_IDX] = TAG_ID;
- dwt_writetxdata(sizeof(angle_msg), angle_msg, 0);
- dwt_writetxfctrl(sizeof(angle_msg), 0);
- /* 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 );
- while (!(dwt_read32bitreg(SYS_STATUS_ID) & SYS_STATUS_TXFRS))
- { };
- framenum++;
- }
复制代码 |
|