Wednesday, January 10, 2007

Introducing nxtsh - the command line interface to our favorite brick

First of all happy new year to everyone here. A lot of my christmas vacation was spent on making a shell that allows for easy file manipulation on the NXT brick from linux. My other computer is a linux machine, and I want to be able to use that when my wife wants to use the mac.

So I dug up Douglas P. Laus excellent NXT_Python module that does everything you need in terms of managing files on the brick, and then I added a shell on top. You can find it here: http://www.danbbs.dk/~kibria/nxt/nxtsh.py.

A couple of notes:
  • You need the NXT_Python package, and you need the packages that NXT_Python requires. You can find these at Douglas' page.
  • The pyusb link on Douglas' page seems broken - use the SourceForge page instead if you have problems
  • This can as far as I can see only run as root when using USB due to a restriction in the pyusb module used by NXT_Python.
If you find this useful or have suggestions, drop me a note. I might update this further (command completion and readline support springs to mind), but I made it so I could play with nbc, so don't hold your breath.

Wednesday, December 27, 2006

How I got around not having paper building instructions

While the new electronic building instructions seems quite clever at a glance, and certainly is more durable than the usual paper instructions from LEGO, I really miss the paper version. Why ? I don't have enough desk space at my computer to build the 'bots. So I have to sit at my dinner table, and I don't own a wireless mouse (or keyboard - not that it would help).

I figured I could just use my Apple remote control, rewire the play button to some other keyboard button by using ControllerMate and then use the remote to flip pages but ...

Inside NXT-G it is not possible to keyboard-navigate between the pages in the instructions - at least not with the keys on my keyboard. It is mouse-only, making the ControllerMate solution impossible (and making the wireless keyboard option from above moot).

However I found out that this part of the NXT-G is rendered by the gecko rendering engine also used by Firefox. This means that the instructions can be opened in firefox - the instruction pane in NXT-G can be found in /Applications/LEGO MINDSTORMS NXT/engine/EditorVIs/Academy Content/index.html . In firefox you can navigate the pages by using tab / alt-tab to move between the front and back arrow buttons in the page and enter to activate them. So I:

  1. Opened my instructions in Firefox
  2. Remapped alt-tab to the back button on the remote so that I could toggle from the "flip forward" to the "flip back" arrow using ControllerMate
  3. Remapped tab to the forward button on the remote to do the opposite of (2)
  4. Remapped enter to the play/pause on the remote
... and violá, I now have a set of remote controlled building instructions, readable at the 1.5 meter distance to my dinner table (with Firefox maximized). Only problem is that iTunes insists to follow the remote commands even when it is not in front, so no music while building robots...

Monday, December 25, 2006

Remembering where we went

You can have a robot remember how long it rolls before something happens and then roll back to its initial position. It is not very well documented but quite easy. You just need to use some of the blocks from the advanced pane in NXT-G (the one with 3 colored squares on). Here is a five-block program that will make the tribot drive until it detects an object using the US sensor, and then drive back to where it came from.
The steps are

  1. We use a rotation sensor from the sensors menu and set it to reset the sensor on motor B
  2. Set motor B and C to drive unlimited ...
  3. ... until the US sensor senses something closer than e.g. 50 cm.
  4. Then we read the rotation sensor. Here we use the data hub on the sensor to find out how many degrees the sensor has rotated since last reset. This is why we needed to reset the sensor just before we started to move forward.
  5. The last move block is set to run a specific number of degrees backwards. The actual amount doesn't matter, because it will read the actual amount from the data hubs "duration" entry. This is tied by a datawire to the rotation sensor, which in turn knows how many degrees that the motor turned when it went forward. That way it will turn backwards just as many degrees and therefore end up where it started.
The documentation for datahubs and datawires is in my mind quite incomprehensible when you first read it, but once you learn how to use it, it is a very powerful tool. I found the tutorial at http://www.bnxt.com/tutorial/NXT-G/DataWires.aspx to be quite instructive.

You can download the .rbt file here: forwards_and_backwards.rbt

Catchy Robot


I just got my NXT LEGO set, and I had to challenge the system and myself a bit, so I set out to create a version of the tribot that could catch balls. That was challenging in several ways:

  • The robot had to detect that the ball was approaching (and at what speed). I solved that by tilting the ultrasonic sensor, and then sample the distance to the ball twice with a 100 ms interval after it came withing 50 cm. That way I could get a quite reliable estimate at the speed, and hence when the claws should close.
  • The robot had to know wether it caught the ball, so that it would only return if it actually had something to return with. I solved that by installing a bar over the claws that gets pushed up by the ball when the 'bot catches it. It triggers a small lever to push the push button sensor when the wheels and axels turn.
  • The original tribot actually twists quite a bit in the construction, so the "ball detector" didn't work reliably until I reinforced it, so that the claws ended up the same place each time it caught the ball.
I think in all it came out quite well. You can see a movie of the bot here:

http://www.youtube.com/watch?v=w2n24bk81iQ