To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.robotics.nxtOpen lugnet.robotics.nxt in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / NXT / 837
836  |  838
Subject: 
pbLua Beta 13c first impressions
Newsgroups: 
lugnet.robotics.nxt
Date: 
Wed, 1 Aug 2007 01:57:19 GMT
Viewed: 
22705 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



Message has 2 Replies:
  Re: pbLua Beta 13c first impressions
 
(...) Walt, thanks for having a look at pbLua and giving it a try. Most importantly, thanks for providing feedback in a forum where we can all learn from what you have done... (...) Soon. It's next on the list of things to do. (...) pbLua has all (...) (17 years ago, 1-Aug-07, to lugnet.robotics.nxt)
  Re: pbLua Beta 13c first impressions
 
Walt, Thanks for mentioning my pbLua installation instructions (that are available also in my "Advanced NXT - The Da Vinci Inventions Book" alongside with a lot of samples for pbLua programs, by the way ;-) ). Keep in mind, though, that they have (...) (17 years ago, 1-Aug-07, to lugnet.robotics.nxt)

3 Messages in This Thread:


Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    
Active threads in NXT programmable brick

 
Verified and Trusted Team of Hackers
21 hours ago
Custom Search

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