To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.off-topic.testOpen lugnet.off-topic.test in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Off-Topic / Testing / 5499
5498  |  5500
Subject: 
test
Newsgroups: 
lugnet.off-topic.test
Date: 
Tue, 31 Jul 2007 20:07:45 GMT
Viewed: 
4003 times
  
pbLua beta 13c

Ralph Hempel has given us pbLua which is a terrific free tool for programming
the NXT.  As a novice programmer, I had a bit of trouble getting it to work so I
want to pass along my notes to other novices who might be interested.  Feel free
to correct anything.  I still can't get some features to work in pbLua, so I
would appreciate feedback.

If you started playing with your NXT by getting used to the LEGO NXT MINDSTORMS
software, then you might be surprised that some of the replacements for that
stock software, such as pbLua, do not duplicate everything that the stock
software provides.  One of these differences is that pbLua doesn't (yet) provide
a file system on the NXT, so you will need a communications program.  You will
either type commands on your keyboard that get executed on the NXT immediately,
or you will download a program you have written to the NXT and it will run
immediately.

You can communicate like that between your PC and the NXT with either the USB
cable or over Bluetooth.

Two references to use in installing pbLua are Ralph's web site at
http://www.hempeldesigngroup.com/lego/pbLua/index.html and  Matthias Paul
Scholz's pbLua installation guide at
http://mynxt.matthiaspaulscholz.eu/tools/Installing_pbLua.pdf where he describes
using Windows HyperTerminal for communications.  By combining these two
documents, you should cover all the initial steps for installation.

Note that in Matthias' instructions he says to use the LEGO NXT MINDSTORMS
software to download nxt-lua.rfw which came in the pbLua distribution.  You
actually have to rename nxt-lua.bin (which came in the beta 13c distribution) to
nxt-lua.rfw before downloading it.  When you power on the NXT you should see
"pbLua Beta 13c" on the NXT display.  Then connect with HyperTerminal and if you
see ">" in the HyperTerminal window then you are connected.

Type:
     nxt.DisplayText("Hello World     ")
from your keyboard, followed by Enter, and you should see the "pbLua Beta 13c"
screen on the NXT change to "Hello World."

The final test for communications setup is to download a program.  Matthias
suggests downloading some of the sample programs that come with the pbLua
distribution.  Those programs define very useful functions, but it may not be
clear to a novice how to test them.  Many require parameters to be passed to
them that are not obvious.  An easy first test is to use Notepad to create the
following program, then use HyperTerminal to download and run it on the NXT:

1 function helloWorld()
2     nxt.DisplayText("Hello World 2   ")
3 end
4 helloWorld()
5

The line numbers are not part of the program but are there to call attention to the empty fifth line.  You are defining a function and then calling it.  The added empty line acts like a trigger to launch the function, the same as using the Enter key after you type commands from the keyboard.  You should see "Hello World 2   " on the NXT display.

It's easy to test simple Lua commands in a Windows command window and then try
the same thing with pbLua.  That way you know whether a problem is specific to
pbLua.  For example, I downloaded lua5_1_2_Win32_bin.zip from
http://luabinaries.luaforge.net/ , unzipped the files in a convenient folder,
and double clicked "lua5.1.exe" which opened a command window.  The result is
the same Lua ">" prompt shown in Matthias' HyperTerminal screen shot for pbLua.

I plan to wander through the exercises in the lua-users.org Tutorial at
http://lua-users.org/wiki/TutorialDirectory trying things in both Lua and pbLua
to get comfortable with the language and the possible differences such as the
integer and floating point math operations described below.  Ralph's pbLua API
at http://www.hempeldesigngroup.com/lego/pbLua/nxtFunctionDefs.html  describes
all the NXT commands he has provided.

The difference will be that Lua doesn't know anything about NXT specifics.  But
Lua and pbLua should behave the same with other things and you can become
familiar with the language syntax by going through the Lua tutorial.

I'm still confused by some of the math functions. The pbLua API states that
integer math should be same as in Lua, but it works in pbLua only when all the
inputs and the result are integers.  So " = 8 / 2 " correctly returns " 4 "
because all the numbers are integers.

But " = 5 / 6 " in Lua returns the correct response "0.83333333333333" while I
got the response "0" in pbLua.  Ralph describes some special things you have to
do to perform floating point math, but I have not been able to get very far.

I tried:
x = nxt.tofloat(5,0)
y = nxt.tofloat(6,0)
= nxt.div(x,y)
1062557013

x = nxt.tofloat(5)
y = nxt.tofloat(6)
= nxt.div(x,y)
1062557013

The API says "You can now also make floating point numbers directly, like this:
n = -37.123"

However, when you enter that and then try:
= n
-1108639220

i,f = nxt.toint(n)
= i
0
=f
-114994

Likewise for multiplication, nxt.mul(x,y) returns strange values.

Testing trig functions, sine works and cosine doesn't:
= nxt.sin(0)
0

= nxt.cos(0)
1065353216

= nxt.pi()
1078530011

Obviously I need to investigate further.  As mentioned above, corrections are
welcome.

Hope this helps other novices.  I'll keep posting as I figure things out.

Walt White



1 Message in This Thread:

Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

Custom Search

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR