wyc / nxt-python

Automatically exported from code.google.com/p/nxt-python
GNU General Public License v3.0
0 stars 0 forks source link

get_sensor_info() times out for Ultrasonic sensor on windows 7 and a possible solution #35

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago

here is a stack trace:

    sensor = Ultrasonic( BRICK, inPort)
  File "nxt-my\nxt\sensor\generic.py", line 95, in __init__
    super(Ultrasonic, self).__init__(brick, port, check_compatible)
  File "nxt-my\nxt\sensor\digital.py", line 73, in __init__
    sensor = self.get_sensor_info()
  File "nxt-my\nxt\sensor\digital.py", line 156, in get_sensor_info
    version = self.read_value('version')[0].split('\0')[0]
  File "nxt-my\nxt\sensor\digital.py", line 143, in read_value
    raise I2CError, "read_value timeout"

this is with Mindstorm 1.0 and  nxt-python-2.2.1 on Windows-7, brick is 
connected via USB

The problem seems to go away if I insert a 10 ms delay between i2c write and 
read in _i2c_query in sensor/digital.py

        self.brick.ls_write(self.port, msg, n_bytes)
        sleep(0.01)
        try:
            self._ls_get_status(n_bytes)

If I skip the version check, I can still use the sensor without the delay. (but 
get_sensor_info() still does not work).

A similar problem happens when trying to get info from hitechnic color sensor. 
get_sensor_info() times out...

But if I skip the version check, then I get a timeout when trying to retrieve 
color information.. 

Inserting a delay of 15ms solves the problem..

And the last tidbit: if I initialize the color sensor as Ultrasonic one and 
skip the version check, then get_distance() works even without delay.

Original issue reported on code.google.com by jokeg...@gmail.com on 4 Dec 2011 at 7:56

GoogleCodeExporter commented 9 years ago
Thanks for the concise, complete report! The way this should be fixed is by 
increasing the value in digital.py here:
http://code.google.com/p/nxt-python/source/browse/trunk/nxt/sensor/digital.py#84

Set it to 30 or so and see if it solves your problem, and if so, experiment 
with different values until you find the threshold. If not, you might put a 
small delay (1-5ms) in the loop instead of the pass and see if that helps. Let 
me know how it goes and I'll see about fixing this in the trunk. Thanks!

Original comment by marcus@wanners.net on 5 Dec 2011 at 8:42

GoogleCodeExporter commented 9 years ago
Hi,
I just got my new toys yesterday, so I'm quite teh n00b.

Just wanted to let you know I encountered the same error on Ubuntu 11.10.
Altering the for-loop (in digital.py#84) to run to 13 fixed the problem for me. 
On 12 it still times out.

Original comment by jovliegen on 27 Dec 2011 at 6:42

GoogleCodeExporter commented 9 years ago
Bumping to 30 in trunk, will add to next bugfix. If the OP could please look at 
this again and let me know whether it's fixed, I would appreciate it.

Original comment by marcus@wanners.net on 22 Mar 2012 at 11:49