简体   繁体   English

如何使用蓝牙信号强度计算android设备之间的距离?

[英]How to calculate distance between android devices using Bluetooth signal strength?

double getDistance(int rssi, int txPower) {
    return Math.pow(10d, ((double) txPower - rssi) / (10 * 2));
}

I tried calculating distance between the Bluetooth devices using the above equation. 我尝试使用上述公式计算蓝牙设备之间的距离。 But it returns wrong results. 但是它返回错误的结果。 The results are in the format "3.4565216E9". 结果的格式为“ 3.4565216E9”。 But the results varies from "3.4565216E9" to "9.9645352E9" randomly. 但是结果从“ 3.4565216E9”到“ 9.9645352E9”随机变化。 Can someone suggest a different method 有人可以建议其他方法吗

A contour plot of radio signal strength indication (RSSI) even under ideal conditions is roughly maple leaf shaped. 即使在理想条件下,无线电信号强度指示(RSSI)的轮廓图也大致呈枫叶形状。 The variation you are seeing is almost certainly a consequence of whether you are in or between the high signal "fingers" of the leaf. 您所看到的变化几乎可以肯定是由于您处于叶片的高信号“手指”之中还是之间。

To get a useful result you must either use a rotating antenna and compute the RMS signal strength (think WW2 battleship radar) or a multi-pole antenna and phase trickery to get the same result. 为了获得有用的结果,您必须使用旋转天线并计算RMS信号强度(想想WW2战舰雷达),或者使用多极天线和相位欺骗来获得相同的结果。

After you get that to work you will have to do signal processing to reject reflections and when you get that to work stably you will have to conduct a full scale field test to work up a fall-off profile at 15 degree intervals from the sensor perpendicular so you can transform RSSI to range. 完成这项工作后,您将必须进行信号处理以抑制反射,而要使其稳定工作,则必须进行一次全面的现场测试,以在与传感器垂直方向间隔15度的间隔内得出衰减曲线因此您可以将RSSI转换为范围。

Since I don't think commercial BT hardware will allow you to entertain these options I suggest you not try to use RSSI for ranging. 由于我认为商用BT硬件不会允许您娱乐这些选项,因此建议您不要尝试使用RSSI进行测距。

If this is a university project then for the purposes of the exercise you need to fix the position and orientation of the transponder and antenna in a space you can mark up with polar coordinates, and map the contours. 如果这是一个大学项目,那么出于练习目的,您需要在可以用极坐标标记并绘制轮廓的空间中固定发送应答器和天线的位置和方向。 Tedious and time consuming? 乏味且耗时? Yes. 是。

There is no easy way to measure the distance using RSSI. 没有简单的方法可以使用RSSI测量距离。 One can take measurements of distance vs. RSSI and then construct a mathematical rule for it. 可以测量距离与RSSI的距离,然后为其建立数学规则。 However, that will be different for every different bluetooth chip inside phones. 但是,对于手机中的每个不同的蓝牙芯片而言,情况都会有所不同。

There is a library called Android Beacon Library: https://altbeacon.github.io/android-beacon-library/ 有一个名为Android Beacon库的库: https : //altbeacon.github.io/android-beacon-library/

These guys are trying to have a community where people experiment and find these readings, but still not many models have been registered. 这些家伙正在尝试建立一个人们可以尝试并找到这些读数的社区,但是仍然没有注册很多模型。 Nonetheless, you can use it to get a general sense of distance. 但是,您可以使用它来获得大致的距离感。 By default it uses Nexus 5 measurements unless if you specify other measurements. 默认情况下,除非您指定其他度量,否则它将使用Nexus 5测量。

The distance can be output as in this sample code: 可以按照以下示例代码输出距离:

        beaconManager.addRangeNotifier(new RangeNotifier() {
            @Override 
            public void didRangeBeaconsInRegion(Collection<Beacon> beacons, Region region) {
                if (beacons.size() > 0) {
                    Log.i(TAG, "The first beacon I see is about "+beacons.iterator().next().getDistance()+" meters away.");        
                }
            }
        });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM