【问题标题】:comparing GPS cordinates with a certain margin in c [duplicate]将GPS坐标与c中的某个边距进行比较[重复]
【发布时间】:2015-07-12 10:39:28
【问题描述】:

我一直在尝试用 arduino 制作一个使用两个 gps 模块的设备。因此,一个发送 gps 线,另一个接收并将其当前位置与发送者的位置进行比较,一旦接收者距离发送者几米,一个 LED 指示灯将亮起,指示发送就在附近,如果您要离开发件人 LED 将关闭。所以我的问题是我无法弄清楚如何比较电线的接收值和当前值以准确工作。这就是我一直在努力的工作我不知道我是否会以错误的方式完成这个我不知道你是否可以做某种半径并使用它如果有人可以帮助我解决这个问题我将不胜感激。从发送方接收到的示例数据 Lat:12.76433041 Lon:-54.74539143 从接收方 Lat:12.76433854 Lon:-54.74539435。

 int destLat;
 int currLat;
 int destLon;
 int currLng;

  currLat = gps.location.lat();
  destLat = Lat;
  currLng = gps.location.lng();
  destLon = Lon; 

  bool AreSame(float currLat, float destLat)
    if fabs(currLat - destLat) < EPSILON;
    {
      if fabs(currLng - destLon) < EPSILON;
      digitalWrite (4, HIGH);
    }

【问题讨论】:

  • 您尚未描述您所看到的实际行为。此外,我认为您的 GPS 接收器无法可靠地解析“距离发送者几米”。
  • 我已经看到 gps 可以在距离发件人几米的地方解析它。我收到的数据有 8 个小数点的精度,例如来自发送方 Lat:12.76433041 Lon:-54.74539143 来自接收方 Lat:12.76433854 Lon:-54.74539435

标签: gps arduino compare double floating-accuracy


【解决方案1】:

你要找的是两个地理坐标之间的“距离”。

这不是一个简单的任务。有几个公式可以近似这一点,但我认为你不会找到可以给你带来小于 1 米的误差的东西。

另外,正如 Jim 所说,GPS 测量本身的误差在大多数情况下会高于几米。一些 GPS 接收器将在运行时提供估计的水平误差。我假设您使用的是便宜的。您应该考虑到准确度还取决于接收器的质量,所以不要期望有很好的结果。

您需要使用的确切公式超出了我的知识范围,我只能给出一些关键字作为参考,您可能想研究“haversine”和“great circle distance”。

您仍然可以“欺骗”一点。假设设备的所有使用都将在同一个本地区域执行,您可以通过实验确定“epsilon”的值。

启动您的 arduino,向北 X 米记录纬度差异,这就是您的 E1。回到起点,向东走X米,记录经度差,这里是E2。

然后一个超级粗略的公式来测试一个设备是否比第二个设备距离超过 X 米:

sqrt(ΔLat**2 + ΔLong**2) < sqrt(E1**2 + E2**2). 

这当然是假设接收器的误差不是太高。

【讨论】:

    【解决方案2】:

    这个:

       if fabs(currLat - destLat) < EPSILON;
        {
          if fabs(currLng - destLon) < EPSILON;
          digitalWrite (4, HIGH);
        }
    

    应该更像:

       if (fabs(currLat - destLat) < EPSILON) /* no semicolon needed here */
        {
          if (fabs(currLng - destLon) < EPSILON)  /* or here */
              digitalWrite (4, HIGH); /* runs when both conditions are true */
        }
    

    【讨论】:

    • 我不认为我在这方面的方法会起作用你知道 c 上的任何半径函数可以用来解决我的问题吗非常感谢。
    • @Ismar,请查看我标记为与您重复的问题的答案。
    【解决方案3】:

    在 Python 中,使用 pyproj module 很容易。

    from pyproj import Geod  # sudo pip3 install pyproj
    geoid = Geod(ellps='WGS84')  # See pyproj documentation for other fun options
    def odometer(start, end):
        """Calculate bearings and distance between two longitude/latitude tuples.
        Arguments:
          start (tuple of float): longitude and latitude of start position e.g., (-146.241122, -15.560615) Apataki Carenage
          end (tuple of float): longitude and latitude of end position, e.g., (150.142778,-30.290556) Mt. Kaputar
        Returns:
          float: True North bearing start -> end
          float: True North bearing end -> start
          float: distance start <-> end
        Raises:
          some error, I know not what.
        """
        try:
            bearing_to, bearing_fro, distance = geoid.inv(*start + end)
        except Exception as error:  # try to be more specific here!
            print("Can't calculate bearing or distance because:", error)
            return None
        bearing_to %= 360
        bearing_fro %= 360
        return bearing_to, bearing_fro, distance
    

    要记住的一点是0.000001 赤道的经度大约是 1 度。 10厘米。虽然您的 gps 单位可以返回此精度(或更高)的外观,但此精度的概率不存在。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-09-11
      • 2021-11-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-30
      • 1970-01-01
      相关资源
      最近更新 更多