Skip to content

Commit 8eecc44

Browse files
author
marcusw
committed
v2.0.2 release: Tag for v2.0.2 from r291 of v2.0 branch.
1 parent 7acccde commit 8eecc44

File tree

9 files changed

+39
-291
lines changed

9 files changed

+39
-291
lines changed

README

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Requirements:
1414
* USB communications:
1515
PyUSB (http://sourceforge.net/projects/pyusb/)
1616

17-
Installation (if using source package):
17+
Installation:
1818

1919
* Untar/unzip source package
2020
* In package directory, run "python setup.py install" (as root), or if
@@ -27,12 +27,15 @@ Installation (if using source package):
2727

2828
Getting Started:
2929

30-
Take a look at the examples directory (this is, unfortunately, not included
31-
in the windows installer packages...you will find it in a corresponding source
32-
package or SVN checkout). Feel free to copy that code into your scripts and
33-
don't be afraid to experiment! If you are having trouble with something, you may
34-
find the solution in the docstrings (ex. help('nxt.sensor.Ultrasonic')) or even
35-
in the source code (especially for digital sensors).
30+
Take a look at the examples directory. This shows by example how to do most
31+
things in nxt-python. Feel free to copy that code into your scripts and don't be
32+
afraid to experiment! If you are having trouble with something, you may find the
33+
solution in the docstrings (ex. help('nxt.sensor.Ultrasonic')) or even in the
34+
source code (especially for digital sensors). Note that in PyPI packages, this
35+
directory is omitted; if you are developing for NXT-Python, you should get one
36+
of the packages from the googlecode site at nxt-python.googlecode.com. You can
37+
also find documentation, tutorials, FAQs, a link to the mailing list, and a neat
38+
web interface to the SVN there.
3639

3740
Notes/FAQ:
3841
(I have tried to put the most important stuff first, but it would be a good
@@ -59,14 +62,12 @@ their specific application.
5962
I2C communication errors. I have been unable to find the source of this problem
6063
(it seems to be inside the nxt firmware itself) or a good workaround. If some
6164
python master out there comes up with a fix, I would be very, very happy to get
62-
it. Thanks!
65+
it. Thanks! This problem seems to have gone away recently, but I am unsure why.
6366
The Synchronized Motor support has not been extensively tested for accuracy.
6467
It seems to mostly work well but the accuracy of the braking function and the
6568
closeness of the two motors to each other have not been assesed.
6669
Support for a number of sensors has not been tested at all, due to lack of
67-
hardware. I have started a project to test this code, but the going is slow
68-
and I have decided to go ahead and release rather than waiting several more
69-
months. If you have a problem with a digital sensor, see the troubleshooting
70+
hardware. If you have a problem with a digital sensor, see the troubleshooting
7071
guide below and don't forget to report your trouble!
7172
NXT-Python has not been tested and may not work with custom nxt firmware
7273
versions (if you don't know what that means, you don't need to worry about it).

examples/alpharex.py

Lines changed: 0 additions & 151 deletions
This file was deleted.

examples/cnc.py

Lines changed: 0 additions & 53 deletions
This file was deleted.

nxt/brick.py

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# nxt.brick module -- Classes to represent LEGO Mindstorms NXT bricks
22
# Copyright (C) 2006 Douglas P Lau
33
# Copyright (C) 2009 Marcus Wanner, rhn
4-
# Copyright (C) 2010 rhn, Marcus Wanner, zonedabone
4+
# Copyright (C) 2010 rhn
55
#
66
# This program is free software: you can redistribute it and/or modify
77
# it under the terms of the GNU General Public License as published by
@@ -14,17 +14,15 @@
1414
# GNU General Public License for more details.
1515

1616
from time import sleep
17-
from threading import RLock
1817
from .error import FileNotFound, ModuleNotFound
1918
from .telegram import OPCODES, Telegram
2019
from .sensor import get_sensor
2120

2221
def _make_poller(opcode, poll_func, parse_func):
2322
def poll(self, *args, **kwargs):
2423
ogram = poll_func(opcode, *args, **kwargs)
25-
with self.lock:
26-
self.sock.send(str(ogram))
27-
igram = Telegram(opcode=opcode, pkt=self.sock.recv())
24+
self.sock.send(str(ogram))
25+
igram = Telegram(opcode=opcode, pkt=self.sock.recv())
2826
return parse_func(igram)
2927
return poll
3028

@@ -46,12 +44,12 @@ def __init__(self, brick, pattern):
4644
self.brick = brick
4745
self.pattern = pattern
4846
self.handle = None
49-
47+
5048
def _close(self):
5149
if self.handle is not None:
52-
self.brick.close(self.handle)
50+
self.brick.close(self.handle)
5351
self.handle = None
54-
52+
5553
def __del__(self):
5654
self._close()
5755

@@ -94,7 +92,7 @@ class FileReader(object):
9492
def __init__(self, brick, fname):
9593
self.brick = brick
9694
self.handle, self.size = brick.open_read(fname)
97-
95+
9896
def read(self, bytes=None):
9997
if bytes is not None:
10098
remaining = bytes
@@ -108,12 +106,12 @@ def read(self, bytes=None):
108106
remaining -= len(buffer_)
109107
data.append(buffer_)
110108
return ''.join(data)
111-
109+
112110
def close(self):
113111
if self.handle is not None:
114112
self.brick.close(self.handle)
115113
self.handle = None
116-
114+
117115
def __del__(self):
118116
self.close()
119117

@@ -122,7 +120,7 @@ def __enter__(self):
122120

123121
def __exit__(self, etp, value, tb):
124122
self.close()
125-
123+
126124
def __iter__(self):
127125
rem = self.size
128126
bsize = self.brick.sock.bsize
@@ -144,12 +142,12 @@ def __init__(self, brick, fname, size):
144142

145143
def __del__(self):
146144
self.close()
147-
145+
148146
def close(self):
149147
if self.handle is not None:
150148
self.brick.close(self.handle)
151149
self.handle = None
152-
150+
153151
def tell(self):
154152
return self._position
155153

@@ -159,14 +157,14 @@ def write(self, data):
159157
raise ValueError('Data will not fit into remaining space')
160158
bsize = self.brick.sock.bsize
161159
data_position = 0
162-
160+
163161
while remaining > 0:
164162
batch_size = min(bsize, remaining)
165163
next_data_position = data_position + batch_size
166164
buffer_ = data[data_position:next_data_position]
167-
165+
168166
handle, size = self.brick.write(self.handle, buffer_)
169-
167+
170168
self._position += batch_size
171169
data_position = next_data_position
172170
remaining -= batch_size
@@ -184,7 +182,7 @@ def _close(self):
184182
if self.handle:
185183
self.brick.close(self.handle)
186184
self.handle = None
187-
185+
188186
def __del__(self):
189187
self._close()
190188

@@ -202,23 +200,22 @@ def __iter__(self):
202200
self._close()
203201
break
204202

205-
203+
206204
class Brick(object): #TODO: this begs to have explicit methods
207205
'Main object for NXT Control'
208206

209207
__metaclass__ = _Meta
210208

211209
def __init__(self, sock):
212210
self.sock = sock
213-
self.lock = RLock()
214211

215212
def play_tone_and_wait(self, frequency, duration):
216213
self.play_tone(frequency, duration)
217214
sleep(duration / 1000.0)
218215

219216
def __del__(self):
220217
self.sock.close()
221-
218+
222219
find_files = FileFinder
223220
find_modules = ModuleFinder
224221
open_file = File

0 commit comments

Comments
 (0)