Subject:
|
Re: pbLua Beta 13c first impressions
|
Newsgroups:
|
lugnet.robotics.nxt
|
Date:
|
Wed, 1 Aug 2007 04:19:27 GMT
|
Viewed:
|
21200 times
|
| |
| |
Walt White wrote:
> pbLua beta 13c
>
> Ralph Hempel has given us pbLua which is a terrific free tool for
> programming
> the NXT.
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...
> One of these differences is that pbLua doesn't (yet)
> provide
> a file system on the NXT
Soon. It's next on the list of things to do.
> 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.
pbLua has all the NXT specific functions in its own table called nxt and
all the functions are described in the API part of the website
> 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.
pbLua uses long integers (32 bits) for math functions
> 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.
5/6 is zero in truncated integer division. The compromise I had to
come up with is to represent floats in 32 bits. So there is a confusing
hybrid number system called "flong" which means a number is sometimes
an integer and sometimes a long.
> I tried:
> x = nxt.tofloat(5,0)
> y = nxt.tofloat(6,0)
> = nxt.div(x,y)
> 1062557013
OK, that's expected. What happens if you then do:
i,f = nxt.toint( nxt.div(x,y) )
> 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
I'll check that out. I hope I have not broken anything...can you try
with a positive number first?
> Testing trig functions, sine works and cosine doesn't:
> = nxt.sin(0)
> 0
>
> = nxt.cos(0)
> 1065353216
>
> = nxt.pi()
> 1078530011
Same thing. nxt.pi() is a floating point number that is "in place"
of an integer number. You need to use nxt.toint() to get the integer
and float portion out.
And remember that the float part is accurate to 1 part in 1,000,000
so you need to divide by 1,000,000 to get the decimal part.
All this seems confusing, but if you remember that you should rarely
need to convert the float results to integer it is not too bad. Just
keep standard numbers as integers, and keep the floating point numbers
separate from them.
I'll put up a page on my website on this eventually...
Thanks again for writing up your experience.
Cheers, Ralph
|
|
Message is in Reply To:
| | pbLua Beta 13c first impressions
|
| 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 (...) (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
|
|
|
|