How to calculate precise location with trilat library using beacons technology

434 views Asked by At

I'm currently trying to develop a real-time location finding application with the use of beacons technology. So for that, I need to track beacon tags using a beacon scanner gateways. I am working with Node Js, and use the trilat library to calculate x,y coordinates. But each time it calculates only a centroid position!

Here's my code to calculate x and y coordinates, along with the distance calculate using RSSI value.

app.js

var trilat = require('trilat');

var gatway1rssi=-30;
var gatway2rssi=-79;
var gatway3rssi=-29;

var d1 = calc_dist(gatway1rssi);
var d2 = calc_dist(gatway2rssi);
var d3 = calc_dist(gatway3rssi);


//gatway coordinates

var gatway1_X_axis= 150;
var gatway1_Y_axis= 209.5;
var gatway2_X_axis= 305;
var gatway2_Y_axis= 169.5;
var gatway3_X_axis= 280;
var gatway3_Y_axis= 345;


var input = [
//      X     Y     R
    [ gatway1_X_axis,  gatway1_Y_axis, d1],
    [ gatway2_X_axis,  gatway2_Y_axis, d2],
    [ gatway3_X_axis,  gatway3_Y_axis, d3],
];
 
// [
//   [ 150, 209.5, 0.35481338923357547 ],
//   [ 305, 169.5, 100 ],
//   [ 280, 345, 0.31622776601683794 ]
// ]

var output = trilat(input);
console.log(output)
// [ 233.81590601205798, 219.6331375609171]


function calc_dist(rss){
     var  a='-39';//tx power 
     var n='2';//noise
     var cal_d = Math.pow(10,((rss-a)/(-10*n)));
     return cal_d;
  }

reference example image

1

There are 1 answers

0
Fabio Veronese On

The example you posted reports that the estimations for d1 and d3 are below 1 while d2 is 100. The trilateration algorithm is not exact, so it tries to minimize the overall error. This implies it places the possible solution point with similar error w.r.t. all the distance estimations i.e. approximately same distance from gateway1 and gateway3 (very close to both of them) while quite fare form gateway2.

Having understood this leads us to the real problem, i.e. the distance estimation. If you compute distance with a formula that exploits RSS, the stronger the signal, the smaller the distance. So the formula

var cal_d = Math.pow(10,((rss-a)/(-10*n)));

is somewhat inverted. I suggest you to revise this formula and check the signs as well as the a term value.