BLE(iBeacons)三边测量

我是德国富特旺根大学的一名学生。

我在我的最后一个任期内,现在正在撰写我的论文。 我对iBeacon及其背后的技术非常感兴趣。 我目前的项目是将信标技术与GPS,无线定位,GSM和NFC等其他技术进行比较。 对于我的论文,我将创建不同的用例并比较结果。

在过去的几天里,我试图确定我在一个房间里的位置。 我使用三个信标的相对距离(准确度),并将每个信标都放在我的房间中。 我得到三个圆圈并计算6个交点。 当弧度(准确度)太低时,我会人为增加此值。 然后我看看6点(交点)中哪一点最近。 (三个最近的点)用这些点我得到一个三角形,并与此我计算中间点。

我的问题是,结果并不是最好的。

我在此找到了更好的解决方案:

https://gis.stackexchange.com/questions/40660/trilateration-algorithm-for-n-amount-of-points

但是我在Objective C中实现这一点时遇到了麻烦,但我理解这个解决方案。 我如何在Objective C中导入或获取它。我找到了一些库(C,C ++),但我不确定这些库中哪一个库是最好的。

对我来说最好的解决方案是一个Objectice C数学库,它可以用这些点计算(x1,x2,x3, - ,y1,y2,y3,...,r1,r2,r3)。

我现在计算的图形


我一直在努力解决同样的问题,然后我发现这个解决方案是用python编写的。 我尝试将代码移植到objective-c中,并使用相同的情况进行测试,结果是准确的。 我修改了代码,以便它可以接受二维矢量。

测试案例是:

P1 = (3,0) r1 = 6.4031
P2 = (9,0) r2 = 4.1231
P3 = (4,8) r3 = 5.6568

我通过代码运行这些数据:

//P1,P2,P3 is the point and 2-dimension vector
NSMutableArray *P1 = [[NSMutableArray alloc] initWithCapacity:0];
[P1 addObject:[NSNumber numberWithDouble:3]];
[P1 addObject:[NSNumber numberWithDouble:0]];


NSMutableArray *P2 = [[NSMutableArray alloc] initWithCapacity:0];
[P2 addObject:[NSNumber numberWithDouble:9]];
[P2 addObject:[NSNumber numberWithDouble:0]];

NSMutableArray *P3 = [[NSMutableArray alloc] initWithCapacity:0];
[P3 addObject:[NSNumber numberWithDouble:4]];
[P3 addObject:[NSNumber numberWithDouble:8]];

//this is the distance between all the points and the unknown point
double DistA = 6.4031;
double DistB = 4.1231;
double DistC = 5.6568;

// ex = (P2 - P1)/(numpy.linalg.norm(P2 - P1))
NSMutableArray *ex = [[NSMutableArray alloc] initWithCapacity:0];
double temp = 0;
for (int i = 0; i < [P1 count]; i++) {
    double t1 = [[P2 objectAtIndex:i] doubleValue];
    double t2 = [[P1 objectAtIndex:i] doubleValue];
    double t = t1 - t2;
    temp += (t*t);
}
for (int i = 0; i < [P1 count]; i++) {
    double t1 = [[P2 objectAtIndex:i] doubleValue];
    double t2 = [[P1 objectAtIndex:i] doubleValue];
    double exx = (t1 - t2)/sqrt(temp);
    [ex addObject:[NSNumber numberWithDouble:exx]];
}

// i = dot(ex, P3 - P1)
NSMutableArray *p3p1 = [[NSMutableArray alloc] initWithCapacity:0];
for (int i = 0; i < [P3 count]; i++) {
    double t1 = [[P3 objectAtIndex:i] doubleValue];
    double t2 = [[P1 objectAtIndex:i] doubleValue];
    double t3 = t1 - t2;
    [p3p1 addObject:[NSNumber numberWithDouble:t3]];
}

double ival = 0;
for (int i = 0; i < [ex count]; i++) {
    double t1 = [[ex objectAtIndex:i] doubleValue];
    double t2 = [[p3p1 objectAtIndex:i] doubleValue];
    ival += (t1*t2);
}

// ey = (P3 - P1 - i*ex)/(numpy.linalg.norm(P3 - P1 - i*ex))
NSMutableArray *ey = [[NSMutableArray alloc] initWithCapacity:0];
double p3p1i = 0;
for (int  i = 0; i < [P3 count]; i++) {
    double t1 = [[P3 objectAtIndex:i] doubleValue];
    double t2 = [[P1 objectAtIndex:i] doubleValue];
    double t3 = [[ex objectAtIndex:i] doubleValue] * ival;
    double t = t1 - t2 -t3;
    p3p1i += (t*t);
}
for (int i = 0; i < [P3 count]; i++) {
    double t1 = [[P3 objectAtIndex:i] doubleValue];
    double t2 = [[P1 objectAtIndex:i] doubleValue];
    double t3 = [[ex objectAtIndex:i] doubleValue] * ival;
    double eyy = (t1 - t2 - t3)/sqrt(p3p1i);
    [ey addObject:[NSNumber numberWithDouble:eyy]];
}


// ez = numpy.cross(ex,ey)
// if 2-dimensional vector then ez = 0
NSMutableArray *ez = [[NSMutableArray alloc] initWithCapacity:0];
double ezx;
double ezy;
double ezz;
if ([P1 count] !=3){
    ezx = 0;
    ezy = 0;
    ezz = 0;

}else{
    ezx = ([[ex objectAtIndex:1] doubleValue]*[[ey objectAtIndex:2]doubleValue]) - ([[ex objectAtIndex:2]doubleValue]*[[ey objectAtIndex:1]doubleValue]);
    ezy = ([[ex objectAtIndex:2] doubleValue]*[[ey objectAtIndex:0]doubleValue]) - ([[ex objectAtIndex:0]doubleValue]*[[ey objectAtIndex:2]doubleValue]);
    ezz = ([[ex objectAtIndex:0] doubleValue]*[[ey objectAtIndex:1]doubleValue]) - ([[ex objectAtIndex:1]doubleValue]*[[ey objectAtIndex:0]doubleValue]);

}

[ez addObject:[NSNumber numberWithDouble:ezx]];
[ez addObject:[NSNumber numberWithDouble:ezy]];
[ez addObject:[NSNumber numberWithDouble:ezz]];


// d = numpy.linalg.norm(P2 - P1)
double d = sqrt(temp);

// j = dot(ey, P3 - P1)
double jval = 0;
for (int i = 0; i < [ey count]; i++) {
    double t1 = [[ey objectAtIndex:i] doubleValue];
    double t2 = [[p3p1 objectAtIndex:i] doubleValue];
    jval += (t1*t2);
}

// x = (pow(DistA,2) - pow(DistB,2) + pow(d,2))/(2*d)
double xval = (pow(DistA,2) - pow(DistB,2) + pow(d,2))/(2*d);

// y = ((pow(DistA,2) - pow(DistC,2) + pow(i,2) + pow(j,2))/(2*j)) - ((i/j)*x)
double yval = ((pow(DistA,2) - pow(DistC,2) + pow(ival,2) + pow(jval,2))/(2*jval)) - ((ival/jval)*xval);

// z = sqrt(pow(DistA,2) - pow(x,2) - pow(y,2))
// if 2-dimensional vector then z = 0
double zval;
if ([P1 count] !=3){
    zval = 0;
}else{
    zval = sqrt(pow(DistA,2) - pow(xval,2) - pow(yval,2));
}

// triPt = P1 + x*ex + y*ey + z*ez
NSMutableArray *triPt = [[NSMutableArray alloc] initWithCapacity:0];
for (int i = 0; i < [P1 count]; i++) {
    double t1 = [[P1 objectAtIndex:i] doubleValue];
    double t2 = [[ex objectAtIndex:i] doubleValue] * xval;
    double t3 = [[ey objectAtIndex:i] doubleValue] * yval;
    double t4 = [[ez objectAtIndex:i] doubleValue] * zval;
    double triptx = t1+t2+t3+t4;
    [triPt addObject:[NSNumber numberWithDouble:triptx]];
}

NSLog(@"ex %@",ex);
NSLog(@"i %f",ival);
NSLog(@"ey %@",ey);
NSLog(@"d %f",d);
NSLog(@"j %f",jval);
NSLog(@"x %f",xval);
NSLog(@"y %f",yval);
NSLog(@"y %f",yval);
NSLog(@"final result %@",triPt);

我使用上面的测试用例数据绘制了笛卡尔图,并且得到了未知点位于(8,4)的结果,然后使用上面的代码进行测试并得到结果(7.999978,4.000021710625001)。

然后我使用数据做了第二次测试:

P1 = (2,0) r1 = 5.831
P2 = (8,0) r2 = 5.831
P3 = (8,10) r3 = 5.831

手动结果是(5,5),使用代码的结果是(5,5)。 所以,我相信代码是正确的。

链接地址: http://www.djcxy.com/p/85017.html

上一篇: BLE (iBeacons) Trilateration

下一篇: Trilateration with more than 3 circles