<tfoot id='cQkhv'></tfoot>

      <small id='cQkhv'></small><noframes id='cQkhv'>

      • <bdo id='cQkhv'></bdo><ul id='cQkhv'></ul>

      1. <i id='cQkhv'><tr id='cQkhv'><dt id='cQkhv'><q id='cQkhv'><span id='cQkhv'><b id='cQkhv'><form id='cQkhv'><ins id='cQkhv'></ins><ul id='cQkhv'></ul><sub id='cQkhv'></sub></form><legend id='cQkhv'></legend><bdo id='cQkhv'><pre id='cQkhv'><center id='cQkhv'></center></pre></bdo></b><th id='cQkhv'></th></span></q></dt></tr></i><div id='cQkhv'><tfoot id='cQkhv'></tfoot><dl id='cQkhv'><fieldset id='cQkhv'></fieldset></dl></div>

        <legend id='cQkhv'><style id='cQkhv'><dir id='cQkhv'><q id='cQkhv'></q></dir></style></legend>
      2. Python GPS 模块:读取最新的 GPS 数据

        Python GPS Module: Reading latest GPS Data(Python GPS 模块:读取最新的 GPS 数据)

        <small id='BTDfD'></small><noframes id='BTDfD'>

      3. <legend id='BTDfD'><style id='BTDfD'><dir id='BTDfD'><q id='BTDfD'></q></dir></style></legend>

            <tbody id='BTDfD'></tbody>
            1. <tfoot id='BTDfD'></tfoot>
              <i id='BTDfD'><tr id='BTDfD'><dt id='BTDfD'><q id='BTDfD'><span id='BTDfD'><b id='BTDfD'><form id='BTDfD'><ins id='BTDfD'></ins><ul id='BTDfD'></ul><sub id='BTDfD'></sub></form><legend id='BTDfD'></legend><bdo id='BTDfD'><pre id='BTDfD'><center id='BTDfD'></center></pre></bdo></b><th id='BTDfD'></th></span></q></dt></tr></i><div id='BTDfD'><tfoot id='BTDfD'></tfoot><dl id='BTDfD'><fieldset id='BTDfD'></fieldset></dl></div>
              • <bdo id='BTDfD'></bdo><ul id='BTDfD'></ul>
                • 本文介绍了Python GPS 模块:读取最新的 GPS 数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我一直在尝试使用 python 中的标准 GPS (gps.py) 模块 2.6.这应该充当客户端并从在 Ubuntu 中运行的 gpsd 读取 GPS 数据.

                  I have been trying to work with the standard GPS (gps.py) module in python 2.6. This is supposed to act as a client and read GPS Data from gpsd running in Ubuntu.

                  根据 GPSD 网页上关于客户端设计的文档(GPSD Client Howto),我应该能够使用以下代码(从示例中稍微修改)来获取最新的 GPS 读数(我主要感兴趣的是 lat long)

                  According to the documentation from GPSD webpage on client design (GPSD Client Howto), I should be able to use the following code (slightly modified from the example) for getting latest GPS Readings (lat long is what I am mainly interested in)

                  from gps import *
                  session = gps() # assuming gpsd running with default options on port 2947
                  session.stream(WATCH_ENABLE|WATCH_NEWSTYLE)
                  report = session.next()
                  print report
                  

                  如果我重复使用 next(),它会给我来自队列底部的缓冲值(从会话开始时开始),而不是最新的 Gps 读数.有没有办法使用这个库获取更新的值?在某种程度上,寻找 Stream 的最新值?

                  If I repeatedly use the next() it gives me buffered values from the bottom of the queue (from when the session was started), and not the LATEST Gps reading. Is there a way to get more recent values using this library? In a Way, seek the Stream to the latest values?

                  有没有人有一个代码示例使用这个库来轮询 gps 并获得我正在寻找的值?

                  Has anyone got a code example using this library to poll the gps and get the value i am looking for ?

                  这是我想要做的:

                  1. 开始会话
                  2. 等待用户在我的代码中调用 gps_poll() 方法
                  3. 在这个方法里面读取最新的TPV(Time Position Velocity)报告并返回lat long
                  4. 返回等待用户调用 gps_poll()

                  推荐答案

                  你需要做的是定期轮询'session.next()' - 这里的问题是你正在处理一个串行接口 - 你得到结果按照他们收到的顺序.由您来维护具有最新检索值的current_value".

                  What you need to do is regularly poll 'session.next()' - the issue here is that you're dealing with a serial interface - you get results in the order they were received. Its up to you to maintain a 'current_value' that has the latest retrieved value.

                  如果您不轮询会话对象,最终您的 UART FIFO 将填满,并且您无论如何都不会获得任何新值.

                  If you don't poll the session object, eventually your UART FIFO will fill up and you won't get any new values anyway.

                  考虑为此使用线程,不要等待用户调用 gps_poll(),您应该进行轮询,当用户想要一个新值时,他们使用返回 current_value 的 'get_current_value()'.

                  Consider using a thread for this, don't wait for the user to call gps_poll(), you should be polling and when the user wants a new value they use 'get_current_value()' which returns current_value.

                  在我的脑海中,它可能就像这样简单:

                  Off the top of my head it could be something as simple as this:

                  import threading
                  import time
                  from gps import *
                  
                  class GpsPoller(threading.Thread):
                  
                     def __init__(self):
                         threading.Thread.__init__(self)
                         self.session = gps(mode=WATCH_ENABLE)
                         self.current_value = None
                  
                     def get_current_value(self):
                         return self.current_value
                  
                     def run(self):
                         try:
                              while True:
                                  self.current_value = self.session.next()
                                  time.sleep(0.2) # tune this, you might not get values that quickly
                         except StopIteration:
                              pass
                  
                  if __name__ == '__main__':
                  
                     gpsp = GpsPoller()
                     gpsp.start()
                     # gpsp now polls every .2 seconds for new data, storing it in self.current_value
                     while 1:
                         # In the main thread, every 5 seconds print the current value
                         time.sleep(5)
                         print gpsp.get_current_value() 
                  

                  这篇关于Python GPS 模块:读取最新的 GPS 数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Adding config modes to Plotly.Py offline - modebar(将配置模式添加到 Plotly.Py 离线 - 模式栏)
                  Plotly: How to style a plotly figure so that it doesn#39;t display gaps for missing dates?(Plotly:如何设置绘图图形的样式,使其不显示缺失日期的间隙?)
                  python save plotly plot to local file and insert into html(python将绘图保存到本地文件并插入到html中)
                  Plotly: What color cycle does plotly express follow?(情节:情节表达遵循什么颜色循环?)
                  How to save plotly express plot into a html or static image file?(如何将情节表达图保存到 html 或静态图像文件中?)
                  Plotly: How to make a line plot from a pandas dataframe with a long or wide format?(Plotly:如何使用长格式或宽格式的 pandas 数据框制作线图?)
                    <tbody id='qKj2e'></tbody>

                      1. <small id='qKj2e'></small><noframes id='qKj2e'>

                      2. <tfoot id='qKj2e'></tfoot>
                          <bdo id='qKj2e'></bdo><ul id='qKj2e'></ul>
                          • <legend id='qKj2e'><style id='qKj2e'><dir id='qKj2e'><q id='qKj2e'></q></dir></style></legend>
                            <i id='qKj2e'><tr id='qKj2e'><dt id='qKj2e'><q id='qKj2e'><span id='qKj2e'><b id='qKj2e'><form id='qKj2e'><ins id='qKj2e'></ins><ul id='qKj2e'></ul><sub id='qKj2e'></sub></form><legend id='qKj2e'></legend><bdo id='qKj2e'><pre id='qKj2e'><center id='qKj2e'></center></pre></bdo></b><th id='qKj2e'></th></span></q></dt></tr></i><div id='qKj2e'><tfoot id='qKj2e'></tfoot><dl id='qKj2e'><fieldset id='qKj2e'></fieldset></dl></div>