The main pages invite us all to share enhancements, so here goes…
Here’s a contribution we’ve put together to help BrickPi python developers.
We wanted to use the NXT motors as servo motors, and the BrickPi_Python software didn’t seem to help much. And we’re not very enthusiastic about working with low-level C-style code, however great it might be. So we’ve put together some software to build on the BrickPi.py module from BrickPi_Pthon, to make it object-oriented and to make it easier for me and my son to program.
The BrickPython package extends BrickPi_python, to introduce two things: objects, and coroutines.
As a taster, here’s code to detect presence via a sensor, open a door, wait and close it again; all while still permitting other things to happen:
def openDoorWhenSensorDetected(self):
motorA = self.motor('A')
sensor1 = self.sensor('1')
motorA.zeroPosition()
while True:
while sensor1.value() > 8:
yield
for i in motorA.moveTo( -2*90 ):
yield
for i in self.doWait( 4000 ):
yield
for i in motorA.moveTo( 0 ):
yield
The full application is a few lines longer – it’s here: https://github.com/charlesweir/BrickPython/blob/develop/ExamplePrograms/DoorControl.py .
You can find the BrickPython package at https://pypi.python.org/pypi/BrickPython . To keep it robust, it has a full set of unit tests. And there’s documentation and a ‘quick start’ guide at https://pythonhosted.org/BrickPython/index.html
There’s plenty more that could be done. But is it useful?
- Charles