Korving-F / ublox

Python library for the UBX protocol
MIT License
37 stars 14 forks source link

Possible to read multiple messages? #4

Open kevincroissant opened 5 years ago

kevincroissant commented 5 years ago

Hi,

Hopefully I am misunderstanding how to use this and this is a simple answer. I'm trying to read the NAV-PVT and NAV-DOP messages from my NEO-M8N (via the EVK-M8N eval kit). When I do x.read(), I only get NAV-PVT. I turned on NAV-PVT and NAV-DOP in U-Center (UBX > CFG > MSG), and when I tried running a while loop like:

while(True):
    print(x.read())

I only get 01 07 (PVT):

>>> while(True):
...     print(x.read())
... 
Receiving
01 07
<ubx.UbxMessage object at 0x7f7f9adfcb70>
Receiving
01 07
<ubx.UbxMessage object at 0x7f7f9adfcb70>
Receiving
01 07

x.enable_message(1,4) does not seem to do anything:

>>> x.enable_message(1,4)
Transmitting
06 01
Receiving
05 01
Acknowledged. CLS:0x6 ID:0x1
<ubx.UbxMessage object at 0x7f7f9b053208>
>>> x.read()
Receiving
01 07

and after running it, if I look in u-center, NAV-DOP was disabled ?? If I go into U-Center again and disable PVT and enable DOP, x.read() will give me the DOP message:

x.read() Receiving 01 04 <ubx.UbxMessage object at 0x7ff83e846240>

I'm using Python 3.5.3 and the latest ublox library from your git repo. Any ideas? I need to be able to read DOP and PVT as they come in real time. Thank you!

Korving-F commented 5 years ago

Hi! It doesn't look like you're using it wrong, it might just a design flaw on my end I think but there are other things to consider as well. There are two main ways you can get data from the module: through periodic messages & through direct polling. This code only allows for the former atm. For my own project a problem arose using this approach: I only wanted to read data every 5-10 minutes and when you enable periodic messages it fills up the local message queue in a couple of seconds. Any reads later would then only pull the next message from that queue which is then 5-10 minutes old. So by default I flush the message queue before any read, ensuring fresh data.

I recreated your problem, enabling both NAV_DOP and NAV_PVT, and reads give indeed only PVT messages. I am not quite sure why this happens, but I suspect that it's some sort of statistical thing because of the message size differences.

In any case, here are some possible solutions:

  1. Check for explicit ubx_id. This worked for me, but obviously is dangerous if the message is not actually enabled.
>>> while(True):
...     y = x.read()
...     if(y.ubx_id == '04'):
...         break
...
Receiving
01 02
Receiving
01 04
>>> y
<ubx.UbxMessage object at 0x7f7a9dcf7be0>
  1. Remove the flush from the read, grabbing the next message from the queue. Like I said; be aware of the fact that this queue might contain old data if you don't access it enough. You might want to throw in the occasional flushed read if you're not reading a lot. (I would recommend this approach though)
    >>> x.read(reset=False)
    Receiving
    01 07
    <ubx.UbxMessage object at 0x7f7a9dc69438>
    >>> x.read(reset=False)
    Receiving
    01 02
    <ubx.UbxMessage object at 0x7f7a9dc79c50>
    >>> x.read(reset=False)
    Receiving
    01 04
    <ubx.UbxMessage object at 0x7f7a9dc921d0>

It's been a while since I actively dealt with this so take it with a grain of salt, but as I remember the M8 module came with some other issues. For one there is only battery backed non-volatile memory available, resetting the device's configuration if it loses power for too long (as opposed to earlier modules). Maybe this messed up configurations when you checked in µ-center?

Second thing is that by default a bunch of NMEA messages are enabled to send periodically. This code doesn't provide support for these, and if you want to exclusively use the UBX messages you might want to consider running the disable_NMEA() function before doing anything else. This iterates over all NMEA class/id combinations and tries to disable sending these. Hopefully this reduces some of the noise on the wire as well.

Hope that this was a little helpful. Like I said in other issues: I don't have too much time at the moment for support / development etc. But if you have any questions I will at least try to answer ^_^

Cheers