anchor calculate the distance with TWR

Post Reply
Posts: 186
Joined: Mon Dec 28, 2015 5:07 am

anchor calculate the distance with TWR

Post by justinleeyang » Sat Apr 09, 2016 2:55 pm


see the lps-code-firmware, find that calculate the distacne node is tag, we want anchor to do the thing. so we change code, when tag receive answer, packet the poll_tx, answer_rx and the final_tx to send to anchor, but the issue is final_tx wiht tag, I must get timestamp before transmit final, have some problem ? the current get transmit throught txcallback function. I suspect my final_tx will generate some problem.

for anchor receive the distance, try another method, tag send the distance to anchor throught poll message.
when tag poll send to anchor, packet the prior distance information, the code as follow.
define the structre include distance(tag calculate distance)

Code: Select all

typedef struct {
  double distance;
} __attribute__ ((packed)) pollDistance_t;
rxcallback function:

Code: Select all

case POLL:
      debug("POLL from %02x at %04x\r\n", rxPacket.sourceAddress[0], (unsigned int)arival.low32);
      rangingTick = HAL_GetTick();
			pollDistance_t *pollReport = (pollDistance_t *)(rxPacket.payload+2);
			gDistance = pollReport->distance;
			printf("anchor address %d, distance with tag address %d: %5dmm\r\n", rxPacket.destAddress[0], rxPacket.sourceAddress[0], (unsigned int)(gDistance*1000));

      poll_rx = arival;

      txPacket.payload[TYPE] = ANSWER;
      txPacket.payload[SEQ] = rxPacket.payload[SEQ];

      dwSetData(dev, (uint8_t*)&txPacket, MAC802154_HEADER_LENGTH+2);

      dwWaitForResponse(dev, true);
main funtion while(1)

Code: Select all

         txPacket.payload[TYPE] = POLL;
         txPacket.payload[SEQ] = ++curr_seq;

         memcpy(txPacket.sourceAddress, address, 8);
         memcpy(txPacket.destAddress, base_address, 8);
	pollDistance_t *pollReport = (pollDistance_t *)(txPacket.payload+2);
	//pollReport->distance = 1234.5;
	pollReport->distance = gDistance;

Post Reply