jremington / UWB-Indoor-Localization_Arduino

Open source Indoor localization using Arduino and ESP32_UWB tags + anchors
GNU General Public License v3.0
130 stars 33 forks source link

tag2D_3A implementation #9

Closed Kihoon-Shin closed 1 year ago

Kihoon-Shin commented 1 year ago

Hello, I'm doing tag2D_3A example with UWB I'm wondering if i'm doing it right what i want to do is 20230214_211311 to know the x, y position of tag. So, this is my main anchor setup code

#include <SPI.h>
#include "DW1000Ranging.h"
#include "DW1000.h"

// leftmost two bytes below will become the "short address"
char anchor_addr[] = "81:00:5B:D5:A9:9A:E2:9C"; //#1

//calibrated Antenna Delay setting for this anchor
uint16_t Adelay = 16676;

// previously determined calibration results for antenna delay
// #1 16630
// #2 16610
// #3 16607
// #4 16580

// calibration distance
float dist_m = 1.5; //meters

And this is my b anchor setup code

#include <SPI.h>
#include "DW1000Ranging.h"
#include "DW1000.h"

// leftmost two bytes below will become the "short address"
char anchor_addr[] = "82:00:5B:D5:A9:9A:E2:9C"; //#b

//calibrated Antenna Delay setting for this anchor
uint16_t Adelay = 16640;

// previously determined calibration results for antenna delay
// #1 16630
// #2 16610
// #3 16607
// #4 16580

// calibration distance
float dist_m = 1.5; //meters

And this is my c anchor setup code

#include <SPI.h>
#include "DW1000Ranging.h"
#include "DW1000.h"

// leftmost two bytes below will become the "short address"
char anchor_addr[] = "83:00:5B:D5:A9:9A:E2:9C"; //#c

//calibrated Antenna Delay setting for this anchor
uint16_t Adelay = 16603;

// previously determined calibration results for antenna delay
// #1 16630
// #2 16610
// #3 16607
// #4 16580

// calibration distance
float dist_m = 1.5; //meters

#define SPI_SCK 18
#define SPI_MISO 19
#define SPI_MOSI 23
#define DW_CS 4

// connection pins
const uint8_t PIN_SCK = 18;
const uint8_t PIN_MOSI = 23;
const uint8_t PIN_MISO = 19;
const uint8_t PIN_SS = 2;
const uint8_t PIN_RST = 15;
const uint8_t PIN_IRQ = 17;

And this is part of my ESP32_UWB_tag2D_3A code

#define N_ANCHORS 3
#define ANCHOR_DISTANCE_EXPIRED 5000   //measurements older than this are ignore (milliseconds)

// global variables, input and output

float anchor_matrix[N_ANCHORS][3] = { //list of anchor coordinates, relative to chosen origin.
  {0.0, 0.0, 0.97},  //Anchor labeled #1
  {-0.3, -0.3, 1.14},//Anchor labeled #2
  {0.3, -0.3, 0.6}, //Anchor labeled #3
};  //Z values are ignored in this code

uint32_t last_anchor_update[N_ANCHORS] = {0}; //millis() value last time anchor was seen
float last_anchor_distance[N_ANCHORS] = {0.0}; //most recent distance reports

float current_tag_position[2] = {0.0, 0.0}; //global current position (meters with respect to anchor origin)
float current_distance_rmse = 0.0;  //rms error in distance calc => crude measure of position error (meters).  Needs to be better characterized

I'm wondering if the anchor addresses and current_tag_position matrix are set correctly

jremington commented 1 year ago

I don't see an obvious problem. What happens when you set up the installation and run the code?

Kihoon-Shin commented 1 year ago

the output x, y position of the tag is not correct. I set it up as shown in the above picture and uploaded the code, is there anything wrong?

jremington commented 1 year ago

I don't know what you mean by "not correct". Post examples, and describe what you expected, and why you think it is not correct.

Think about how the X and Y axes are related to the coordinate system defined by those anchors. Please draw and post picture of those axes, with the anchors located on the diagram as points.

Incidentally, it is not a good idea to have the anchors so close together. The coordinate error is about 0.1 m, and your anchors are not much further apart than that. For my tests, I put the anchors on four corners of a room, about 5m x 5m.

jremington commented 1 year ago

For the 5x5 m test, just use the code you have, and make sure to put the correct coordinates of the anchors in the tag code, including the Z values. Are the Z values below actually correct for your earlier test? If not, that is a problem.

  {0.0, 0.0, 0.97},  //Anchor labeled #1
  {-0.3, -0.3, 1.14},//Anchor labeled #2
  {0.3, -0.3, 0.6}, //Anchor labeled #3

I recommend recalibrating the anchors using 5m distance.

Kihoon-Shin commented 1 year ago

Hello jremington. Thank you for your reply. I'm doing a "UWB-based human following robot" project. Like picture below, There is a human with Tag and a robot with three Anchors(Red). I want to know the relative position of a human with Tag on reference frame(Blue). 20230218_175031 With that relative position, I'll make robot follow human using PID control. The problem is I don't know how to set addresses of 3 anchors.

// leftmost two bytes below will become the "short address"
char anchor_addr[] = "81:00:5B:D5:A9:9A:E2:9C"; //#1

Is "81:00:5B:D5:A9:9A:E2:9C" the MAC address of a anchor? I know the Mac address is 48bit, but why is it 64bit? And Why did you use short address instead of full MAC address? And leftmost two bytes must be "81:00" for 1st anchor, "82:00" for 2nd anchor, "83:00" for 3rd anchor? I'm sorry I have so many questions in one comment.

jremington commented 1 year ago
  1. The address is an arbitrary number and can be anything you want.
  2. I use the short address because it is convenient, and the library has a function to return just that part from the full address.
  3. The short address can be anything you want, in 16 bits. The convention I selected to identify the anchors arbitrary, but convenient and easy for a human to decide which anchor is "1", which is "2" and so on.
Kihoon-Shin commented 1 year ago

Thanks for the reply. What did you use between Two-way ranging (TWR) or Time Difference Of Arrival (TDOA) for UWB positioning?

jremington commented 1 year ago

I used the default method in the DW1000 library and saw no need to experiment with the other options.