Skip to content

Commit

Permalink
freeze: Branched the v2 code to create a new trunk.
Browse files Browse the repository at this point in the history
  • Loading branch information
marcusw committed Aug 23, 2010
0 parents commit 05259a1
Show file tree
Hide file tree
Showing 36 changed files with 3,654 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Wed, 18 Nov 2009 19:05:49 +0100 by rhn:
* Created this changelog
* Changed set_input_mode behaviour to take parameters. TODO: Make it remember last mode for analog sensors
* Made get_input_values() return RawReading, and added get_reading() returning named values.
* Changed the way digital sensors work, partially getting rid of metaclasses and breaking everything in the process (no access to hardware)
674 changes: 674 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
include docs/*.html *.url *.css *.txt
include README LICENSE
include examples/*.py
49 changes: 49 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
NXT-Python is a package for controlling a LEGO NXT robot using the Python
programming language. It can communicate using either USB or Bluetooth. It is
available under the Free Software Foundation's GPL license. It is based on
NXT_Python, where releases halted in May 2007.

This version is part of the 2.x series of releases. Programs designed for
NXT_Python or for the 1.x series will not work with this version. If you are
trying to get an old program to work, it most likely needs a 1.x series release,
which can be downloaded from the nxt-python googlecode downloads page.

Once your installation is working, I would really appreciate it if you could run
the nxt_sensor_report script and follow the instructions there to help improve
the digital sensor type checking system. It takes maybe 5-10 minutes and is a
way to really help out even if you have no technical skill or don't want to mess
with the code. Thanks!

For support, you can ask the friendly mailing list at:
http://groups.google.com/group/nxt-python
You can report bugs or suggest new features using the bug tracker here:
http://code.google.com/p/nxt-python/issues/list

Note: NXT-Python has not been tested and may not work with custom nxt firmware
versions (if you don't know what that means, you don't need to worry about it).
However, if the custom firmware uses the standard communcations protocol,
everything should more or less work. NXT-Python was primarily developed with
bricks using firmware version 1.5 and is compatible with bricks using protocol
version 1.124.

Requirements:

* Python 2.6 (http://www.python.org)
* PyBluez (Bluetooth library) (http://org.csail.mit.edu/pybluez/)
and / or
* PyUSB (USB library) (http://sourceforge.net/projects/pyusb/)

Installation:

* Untar/unzip source package
* In package directory, run "python setup.py install" (as root), or if
under windows, double-click install.bat.
* For USB on Linux, at a root terminal type:
groupadd lego
usermod -a -G lego [username]
echo 'BUS=="usb", SYSFS{idVendor}=="0694", GROUP="lego", MODE="0660"' > \
/etc/udev/rules.d/70-lego.rules

Contact:
NXT-Python's Head Developer:
Marcus Wanner ([email protected])
3 changes: 3 additions & 0 deletions build_dists.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@call setup.py sdist
@call setup.py bdist_wininst --bitmap=nxt-python.bmp
@call setup.py bdist_wininst --bitmap=nxt-python.bmp --plat-name=win-amd64
13 changes: 13 additions & 0 deletions docs/seealso.url
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[InternetShortcut]
URL=http://code.google.com/p/nxt-python/w/list
WorkingDirectory=C:\WINDOWS\
ShowCommand=7
IconIndex=1
IconFile=http://code.google.com/favicon.ico
Modified=20F06BA06D07BD014D
HotKey=1601
IDList=
[{000214A0-0000-0000-C000-000000000046}]
Prop3=19,2
[DEFAULT]
BASEURL=http://code.google.com/p/nxt-python/w/list
23 changes: 23 additions & 0 deletions examples/latency.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env python

import time
import nxt.locator
from nxt.sensor import *

b = nxt.locator.find_one_brick()

#Touch sensor latency test
touch = Touch(b, PORT_1)
start = time.time()
for i in range(100):
touch.get_sample()
stop = time.time()
print 'touch latency: %s ms' % (1000 * (stop - start) / 100.0)

#Ultrasonic sensor latency test
ultrasonic = Ultrasonic(b, PORT_4)
start = time.time()
for i in range(100):
ultrasonic.get_sample()
stop = time.time()
print 'ultrasonic latency: %s ms' % (1000 * (stop - start) / 100.0)
45 changes: 45 additions & 0 deletions examples/mary.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/env python
#
# Converted from mary.rb found in ruby_nxt package
# Plays "Mary Had A Little Lamb"
# Author: Christopher Continanza <[email protected]>

from time import sleep
import nxt.locator

FREQ_C = 523
FREQ_D = 587
FREQ_E = 659
FREQ_G = 784

b = nxt.locator.find_one_brick()

b.play_tone_and_wait(FREQ_E, 500)
b.play_tone_and_wait(FREQ_D, 500)
b.play_tone_and_wait(FREQ_C, 500)
b.play_tone_and_wait(FREQ_D, 500)
b.play_tone_and_wait(FREQ_E, 500)
b.play_tone_and_wait(FREQ_E, 500)
b.play_tone_and_wait(FREQ_E, 500)
sleep(0.5)
b.play_tone_and_wait(FREQ_D, 500)
b.play_tone_and_wait(FREQ_D, 500)
b.play_tone_and_wait(FREQ_D, 500)
sleep(0.5)
b.play_tone_and_wait(FREQ_E, 500)
b.play_tone_and_wait(FREQ_G, 500)
b.play_tone_and_wait(FREQ_G, 500)
sleep(0.5)
b.play_tone_and_wait(FREQ_E, 500)
b.play_tone_and_wait(FREQ_D, 500)
b.play_tone_and_wait(FREQ_C, 500)
b.play_tone_and_wait(FREQ_D, 500)
b.play_tone_and_wait(FREQ_E, 500)
b.play_tone_and_wait(FREQ_E, 500)
b.play_tone_and_wait(FREQ_E, 500)
b.play_tone_and_wait(FREQ_E, 500)
b.play_tone_and_wait(FREQ_D, 500)
b.play_tone_and_wait(FREQ_D, 500)
b.play_tone_and_wait(FREQ_E, 500)
b.play_tone_and_wait(FREQ_D, 500)
b.play_tone_and_wait(FREQ_C, 750)
15 changes: 15 additions & 0 deletions examples/message_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env python

#During this test you need to run any program on the brick
#which doesn't use the messaging system. Most programs fit
#this requirement.

import nxt.locator

b = nxt.locator.find_one_brick()
for box in range(10):
b.message_write(box, 'message test %d' % box)
for box in range(10):
local_box, message = b.message_read(box, box, True)
print local_box, message
print 'Test succeeded!'
14 changes: 14 additions & 0 deletions examples/spin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env python

import nxt.locator
from nxt.motor import *

def spin_around(b):
m_left = Motor(b, PORT_B)
m_left.turn(100, 360)
m_right = Motor(b, PORT_C)
m_right.turn(-100, 360)

b = nxt.locator.find_one_brick()
spin_around(b)

11 changes: 11 additions & 0 deletions examples/test_sensors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env python

import nxt.locator
from nxt.sensor import *

b = nxt.locator.find_one_brick()

print 'Touch:', Touch(b, PORT_1).get_sample()
print 'Sound:', Sound(b, PORT_2).get_sample()
print 'Light:', Light(b, PORT_3).get_sample()
print 'Ultrasonic:', Ultrasonic(b, PORT_4).get_sample()
11 changes: 11 additions & 0 deletions install.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
@echo off
@call setup.py install
if errorlevel 1 goto error
goto end
:error
echo -=-=-=-=-=-=-=-=-=-=-
echo There was an error during the installation. Please check the above text
echo for more information before you
pause
:end
@echo on
Binary file added nxt-python.bmp
Binary file not shown.
13 changes: 13 additions & 0 deletions nxt/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# nxt.__init__ module -- LEGO Mindstorms NXT python package
# Copyright (C) 2006 Douglas P Lau
# Copyright (C) 2009 Marcus Wanner
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
78 changes: 78 additions & 0 deletions nxt/bluesock.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# nxt.bluesock module -- Bluetooth socket communication with LEGO Minstorms NXT
# Copyright (C) 2006, 2007 Douglas P Lau
# Copyright (C) 2009 Marcus Wanner
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.

try:
import bluetooth
except ImportError:
import lightblueglue as bluetooth
import os
from .brick import Brick

class BlueSock(object):

bsize = 118 # Bluetooth socket block size
PORT = 1 # Standard NXT rfcomm port

def __init__(self, host):
self.host = host
self.sock = None
self.debug = False

def __str__(self):
return 'Bluetooth (%s)' % self.host

def connect(self):
if self.debug:
print 'Connecting via Bluetooth...'
sock = bluetooth.BluetoothSocket(bluetooth.RFCOMM)
sock.connect((self.host, BlueSock.PORT))
self.sock = sock
if self.debug:
print 'Connected.'
return Brick(self)

def close(self):
if self.debug:
print 'Closing Bluetooth connection...'
self.sock.close()
if self.debug:
print 'Bluetooth connection closed.'

def send(self, data):
if self.debug:
print 'Send:',
print ':'.join('%02x' % ord(c) for c in data)
l0 = len(data) & 0xFF
l1 = (len(data) >> 8) & 0xFF
d = chr(l0) + chr(l1) + data
self.sock.send(d)

def recv(self):
data = self.sock.recv(2)
l0 = ord(data[0])
l1 = ord(data[1])
plen = l0 + (l1 << 8)
data = self.sock.recv(plen)
if self.debug:
print 'Recv:',
print ':'.join('%02x' % ord(c) for c in data)
return data

def _check_brick(arg, value):
return arg is None or arg == value

def find_bricks(host=None, name=None):
for h, n in bluetooth.discover_devices(lookup_names=True):
if _check_brick(host, h) and _check_brick(name, n):
yield BlueSock(h)
Loading

0 comments on commit 05259a1

Please sign in to comment.