Tigge / openant

ANT and ANT-FS Python Library
MIT License
174 stars 80 forks source link

OpenAnt at higher sampling Rates #41

Closed iammorten closed 4 years ago

iammorten commented 4 years ago

Hi there!

First of all I would like to thank you very much for the library, after the inital setup and understanding ANT+ it seems really easy.

In my application I do have a problem when going into higer messaging rates. I have a powermeter device which has an additional "FastMode" in which Torquevalues are transmitted at a rate of 50Hz. I do receive the correct data pages but in very unregular intervals between 1 and 15Hz. I already was checking the correct message rate with the software of the device-company and with Antware II. Both allow me to read data at the high rate. The settings and the USB-Stick are the same I´m using with openant, but I can´t manage to receive all data-messages.

I somehow suspect the USB-driver to maybe be the problem. Could you tell me for which version of PyUSB - openant was developed? Currently I´m using the latest version with. The driver used by openant is the USB3Driver.

I would be happy for any ideas - as I really would like to use openant for my project.

Here also some config details: channel.set_period(655) # of 32768 channel.set_search_timeout(30) # in s channel.set_rf_freq(57) # 2457 MHz channel.set_id(54968, 11, 5) # SerialNumber, DeviceType, Transmissiontype

Thank you very much in advance

iammorten commented 4 years ago

Hi! If somebody has a similar problem check this out: https://www.thisisant.com/forum/viewthread/7284/

It works now :).

Tigge commented 4 years ago

Glad to see you got this to work - also glad to see this project is usable to people. Unfortunately I don't have time, or use the hardware that much anymore, so not much work go into this anymore - but if there are pull request I try to give those a bit of time to see if there is something I can merge.

iammorten commented 4 years ago

Hi Gustav!

Completely understand that old projects needs to come to an end at a certain point. Nevertheless thank you for this library. It´s great to work with it.

Unfortunatelly I´m not very skilled with Git... I mainly use it to download things.

If you would like to consider my changes they are not much:

in ant/base/ant.py Line 167: # time.sleep(0.1) Line 192: (event_type, event) = self._events.get()

in ant/easy/node.py Line 116: (data_type, channel, data) = self._datas.get()

I´m currently running in Python 2.7 on a Raspberry 3 Model B - just as a side info.


Another thing which might be interesting for you. For some reason the pyUSB library is not always working 100% perfect. Many ppl are receiving an timeout error like this: WARNING:ant.base.ant:<class 'usb.core.USBError'>, (110, u'Operation timed out')

While this is normal behaviour when there is nothing to read, it sometimes happens that the USB Device (in our case the ANT+ sticks) are simply never sending any data. In my case this happens very regular - like every second time I´m restarting my application (guess pyUSB doesn´t release some resources properly. I made a little work around for this:

in ant/base/ant.py I added a variable self.USB_OK = false in the init(self) function. As soon as ANY message is received by the _worker(self) method it is set to self.USB_OK = true.

It should receive a message immediatelly after calling self.reset_system(). If not something is wrong with the USB communication. From the userprogram you can query the USB_OK after creating a new node [ node = Node() ]. If it it false you know the USB device has some kind of problem and you can restart the entire thing until you receive something from the ANT+ Stick.

In my case this workarround work really nicely.


I always can send some code if you are interested in more detail.

All the best - and again thank you :)