LATE BREAKING NEWS!

November 15, 2008 - A new version of pbLua - Beta 16a is available for download

This version cleans up a few minor bugs, adds support for converting floats and integers to raw strings, and fixes a long-standing issue with the reliablilty of both the USB and Bluetooth consoles.

It is strongly suggested that you upgrade.

May 04, 2008 - A new version of pbLua - Beta 15c is available for download

This version is an enhancement to Beta 15b. It fixes a problem when printing strings that are longer than 255 bytes. The strings are OK, just the output is wrong :-(

This version also supports shifting values left or right as bitwise values. If you need to preserve the sign bit on right shifts, use the divide operator instead!

April 14, 2008 - A new version of pbLua - Beta 15b is available for download

This version is an enhancement to Beta 15a. It adds support for conditional operations on floats as well as allowing floats to be printed using the Lua concatenation ".." operator.

April 11, 2008 - A new version of pbLua - Beta 15a is available for download

This version is a breaking change from all previous versions, so you should definitely upgrade. The floating point math has been redone so that it is now a separate datatype instead of blended in with integers.

There's a new tutorial on pbLua Floating Point Math that explains exactly how to create and use floats, and it has lots of examples to get you familiar with how it all works.

We're counting down to the FLL Festival in Atlanta next week!

April 7, 2008 - A new version of pbLua - Beta 14n is available for download

I can't help myself. I added another function called nxt.Checksum that returns the sum of the bytes in a string. Hmmm, I wonder what that might be useful for?

There's a new tutorial on the pbLua File System that explains exactly how to create, write, and read files. If you make it to the end of the tutorial, there's even a little section on how you can make the NXT run a pbLua file automagically at boot time!

There will be yet another release just before the FIRST festival in Atlanta that buttons up some nagging floating point number issues. Stay tuned!

This version has a consolidated set of example functions that go with the new tutorial section on the website. It's been a busy few months and once again, the support of Christian Mock in testing and reporting bugs has been invaluable.

We are getting very close to nailing down the final version of pbLua so any and all help is appreciated with testing. Feel free to email me to report bugs or problems with the documantation. I'm also happy to provide some limited programming assistance to users new to Lua and the NXT.

Introduction

This is the official place for news and downloads of pbLua, an exciting new text-based language for the Mindstorms NXT. Way back in 1998, I got one of the first Mindstorms RCX programmable bricks and promptly set about writing a text based language for it. The result was pbForth, which was used in many different applications around the world. The pbForth code was compiled on the RCX by the RCX - no external computer was needed. pbForth was very fast, but the language was frankly scary to read and learn.

Fast forward to 2005. Lego releases the next generation robotics kit - the Mindstorms NXT. Inside the NXT brick is a 32 bit ARM7 microcontroller with 256K of FLASH and 64K of RAM. The 3 motors in the kit are powerful, and have built in rotation sensors. There are 4 sensors in the kit, including touch, light, sound, and even an ultrasonic range finder.

The programming system is redesigned from the ground up and is GUI based. It's ideal for 95% of all robots you are likely to build, and it is especially kid-friendly. But for dinosaurs like me, it's not text based.

As many of you know, I was one of the 4 users selected for the Mindstorms User Panel that was profiled in the February 2006 issue of Wired Magazine. I was called a "firmware expert" in the article, and I guess that's what I do for a living. At the time I was already thinking about what kind of language would be ideal for programming the new NXT.

And that's when I discovered Lua. It's a really beautiful little language that's used in all kinds of applications. But more importantly for our purposes, it has these characteristics:

  1. It's written in portable C, with minimal runtime requirements
  2. It can be compiled on the fly on the target machine, which is the NXT in our application
  3. It's a small, easy to read, and easy to write language
  4. It has extensive documentation available online and in dead-tree format, and a very friendly newsgroup

To see how simple Lua is to read and write, Steve Hassenplug designed a short line following program. I've taken the liberty of adding some comments so that even a non-Lua programmer can understand what's going on:

-- All NXT api functions are in the nxt table, so nxt.apiname() is the
-- standard way to access those functions

function FollowLine()
    -- Set up sensor 3 to be an active light sensor
  nxt.InputSetType(3,0)
  nxt.InputSetState(3,1,0)
  nxt.InputSetDir(3,1,1)

  -- Motors 1 and 2 are in Brake Mode and have regulation enabled

  nxt.OutputSetRegulation( 1, 1, 1 )
  nxt.OutputSetRegulation( 2, 1, 1 )

  -- Set up the light and dark thresholds and the motor speeds
  local T1 = 600
  local T2 = 630
  local SpeedSlow = 50
  local SpeedFast = 100

  -- LoopCount is just to see how fast Lua is running the line
  -- following loop for 10 seconds
  local LoopCount = 0

  -- Read the msec timer and get ready to run the loop for 10 seconds
  local t=nxt.TimerRead()+10000

  while t > nxt.TimerRead() do

    -- Read the light sensor and save the result
    local SV = nxt.InputGetGetStatus(3)

    -- If the sensor is reading below the threshold (white) turn towards
    -- the line
    if SV < T2 then
      nxt.OutputSetSpeed(1,32,SpeedFast)
    else
      nxt.OutputSetSpeed(1,32,SpeedSlow)
    end

    -- If the sensor is reading above the threshold (black) turn away
    -- from the line
    if SV > T1 then
      nxt.OutputSetSpeed(2,32,SpeedFast)
    else
      nxt.OutputSetSpeed(2,32,SpeedSlow)
    end

    -- Count the number of times we've run the loop
    LoopCount = LoopCount + 1

  end

  -- Make room on the LCD for a line of text, and print the number
  -- of times we ran through the loop
  nxt.DisplayScroll()
  nxt.DisplayText(string.format("%i",LoopCount))

  -- Don't forget to turn the motors off!
  nxt.OutputSetSpeed(1,0,0)
  nxt.OutputSetSpeed(2,0,0)

end

-- Now run the FollowLine function we just defined!
FollowLine()

Now that's readable code! Oh, and it runs the main loop 61,000 times in 10 seconds - so it's fast too!