NXT-G, NXC, I2C..What to use to make fastest operations?

Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.
peter-cocteau
Posts: 26
Joined: 04 Dec 2011, 12:12

NXT-G, NXC, I2C..What to use to make fastest operations?

Post by peter-cocteau »

Hi,

I'm actually working on my second NXT musical project: a LEGO musical workstation.
It would be made of two sections:

First Section: a sample based drum machine,very close to my NXT-606.

Image

NXT-606 is a Beat sequencer:
-16 steps sequencer, real time editing.
-memory: 96 measures
-24 sounds, 8bits quality (Drumbass, Snare, Fx,etc..)
-Tempo and Groove functions.
- Jack 6,35mm audio output. (NXT board hacked)
NXT-606 program was made with NXT-G.

If you don't know this COOL project, take a look to this video:
http://www.youtube.com/watch?v=CilCI2kSXnA

Second Section: a polyphonic synthetizer using one or several NXT SuperPro Prototype boards.

Image

Hitechnic SuperPro prototype board can generate many waveforms as a synth. It can be use as OSC(audible frequency) and LFO(low frequency oscillator) to control many things: Voltage Controled Amplifier, Voltage Controled Filter, etc...
I have to say I have a lot of ideas concerning Hitechnic boards and audio control process. :)

My questions:
-I always use NXT-G, it is friendly to me. I like to think about programing without knowledge of how to use NXC, java, basic, etc... In fact those things are chinese for me.
BUT do my program would operate faster by using another thing than NXT-G ?? Which programming language is the fastest ??

-It seems I2C communication between Hitechnic SuperPro board and NXT is quite slow by using NXT-G. I have not test with card but it seems SuperPro NXT-G block takes 45ms when LEGO Proximity sensor block(another I2C device) takes only 6ms to operate.
Which laguage is the best to reduce I2C operation time?

-What are your ideas about all this?

Thanks.

Peter.
Last edited by peter-cocteau on 04 Dec 2011, 22:08, edited 1 time in total.
spillerrec
Posts: 358
Joined: 01 Oct 2010, 06:37
Location: Denmark
Contact:

Re: NXT-G, NXC, I2C..What to use to make fastest operations?

Post by spillerrec »

The fastest thing would of cause be to create your own firmware and write everything in assembly. But this is insane. However something like nxtOSEK is directly executed on the brick IIRC so it should be pretty close. nxtOSEK is C/C++. The learning curve is probably a bit steep though.
Something easier is RobotC, but the biggest disadvantage is that it is not free. Performance is medium of the choices I guess.
NXC has a low learning curve as it runs on the standard firmware, however this also makes it rather slow compared to the others. Performance poor.
NXT-G should be just like bloated NXC, so performance is worse here. I cannot tell how much though, because I used NXT-G for a week before getting tired of it...

There is definitively a difference of performance of the languages, mainly because of firmware and/or compiler efficiency. There is a chart out there with some comparisons, I'm sure someone here has a link.

But the question is not what language which is the fastest, but what you want to use. In case you want to pay for RobotC, it should be a good choice performance-wise. Otherwise use NXC, and replace the slow parts with NBC using asm blocks.
You should also check the availability of drivers to the board in that programming language. You don't want to write it yourself if you can avoid it. I'm pretty sure it is available in NXC, not sure about RobotC, but pretty sure it is not in nxtOSEK.
I don't know the efficiency of the drivers either, so you might have to experiment a little.

However all those choices requires you to learn C, a written programming language. Do you want to spend time on learning this? Is it really necessary to reduce the time it takes to run the SuperPro NXT-G block? Depending on what you are trying it might be possible to do it with this delay anyway.
If you are not going to use C for anything else than this project, is it really worth it?


Well, I hoped this helped you a little in making your choice. It is indeed a cool project, so I look forward to see what you come up with.
My blog: http://spillerrec.dk/category/lego/
RICcreator, an alternative to nxtRICeditV2: http://riccreator.sourceforge.net/
inxt-generation
Posts: 290
Joined: 03 Oct 2011, 00:06
Location: Gallifrey
Contact:

Re: NXT-G, NXC, I2C..What to use to make fastest operations?

Post by inxt-generation »

spillerrec wrote:There is a chart out there with some comparisons, I'm sure someone here has a link.
http://www.teamhassenplug.org/NXT/NXTSoftware.html
A.K.A. NeXT-Generation.
"A kingdom of heaven for RobotC now has recursion!"
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: NXT-G, NXC, I2C..What to use to make fastest operations?

Post by HaWe »

the relative speed of course is a function of what you are supposed to do and compare.
In Steve Hassenplug's program it's mainly reading sensors, controlling a motor, and display something.

Code: Select all

Start loop
 Read light sensor(3)
 Read US sensor(4)
 Read & Display Rotation Sensor(B)
 Get random number (1-100) (RN to be used later)
 Display value of:(Light Sensor+US Sensor+Rotation Sensor)*100/(RN)
 Set motor speed for B and C to RN (Using Coast)
 If RN > 50, Increase A by 1
 If RN < 50, Decrease A by 1
 If RN = 50, no change to A
 Display A
 Set motor A speed to A (if A<0, set direction to reverse)
 Display Loop Count
Loop for 60 seconds
Stop Motors
Show display for 10 seconds
There's no integer or fp calculation, no use of transcendental functions (sin, yx, ln), no array copy and no advanced array operations (arithmetics and functions like mean/min/ sort, multiplying multidimensional arrays), or frequent calls of subroutines, which also all are significant in principle.

What is important to you? reading i2c? Then using highspeed i2c by NXC or RobotC could be faster than nxtOSEK which just uses slowspeed i2c (as I read somewhere here in the forums)
But does the HT SuperPro board support Highspeed i2c?
On the other hand, though RobotC is speed-optimized in relation to NXC, it's restricted in other respects (number of possible NXT-NXT BT-connections, max number of tasks, available memory size for code and variables).

Dick Swan (cave: RobotC developer!) also wrote an overview:
http://www.botmag.com/articles/10-31-07_NXT.shtml
edit: I actually doubt that acc to this this overview Robolab is 70x faster than NXT-G while NXC is only 35x faster but RobotC 130x as much (no idea by what program he was testing) ... :roll:

But also notice that all those publications are quite old!
peter-cocteau
Posts: 26
Joined: 04 Dec 2011, 12:12

Re: NXT-G, NXC, I2C..What to use to make fastest operations?

Post by peter-cocteau »

Thanks to all, I see things more clearly now.

Doc-Helmut, which language is this sample ?
I Don't know if HT SuperPro board support highspeed I2C,nothing appears in handbook about this subject.

Spillerrec, you're right I'm not sure I want to spend time to learn C. I have purchased HT board and will first try it with NXT-G. But I have to say I've already reach NXT-G speed limitation during NXT-606 programming. I'm afraid I2C communication is too slow to add a synth section.

My NXT-606 drumbox is a 16 step sequencer, it means it plays one sample every 125ms with a 120 tempo. 1/16th note duration is 94ms when tempo is 160. With swing function activated this duration is sometimes 60ms only.
In theory SuperPro block duration is 45ms...what is a very long time for me. I have to check this point.

thanks for the comparison link,it is very helpful.
It seems NXC is 5x faster than NXT-G and RobotC would be 135x faster than NXT-G !!!

SPEED(LOOPS/MIN): NXT-G:762 NXC:4825 ROBOTC:103k
(taken from: http://www.teamhassenplug.org/NXT/NXTSoftware.html)
Yes Doc, surprising isn't it? what would be a realistic speed ratio between languages?

NXC and RobotC support SuperPro board.

I forget to say I am a mac user, RobotC is supported only by windows... I Would have to use virtual PC to run it what's make things less friendly.
BTW i think RobotC is not so expensive but I'm surprised License is one year only..

I think NXC would be a good thing to learn this kind of programmation. It may be fast enough. But In my program I use lot of task, variables and single array, may be NXC is too limited ?

Well, I will going on thinking about all those things and will make test with board and NXT-G as soon as possible.

Peter.
Last edited by peter-cocteau on 04 Dec 2011, 21:57, edited 2 times in total.
spillerrec
Posts: 358
Joined: 01 Oct 2010, 06:37
Location: Denmark
Contact:

Re: NXT-G, NXC, I2C..What to use to make fastest operations?

Post by spillerrec »

peter-cocteau wrote:It seems NXC is 5x faster than NXT-G and RobotC would be 135x faster than NXT-G !!!
It is worth noting that since those articles the 1.2x firmwares were released and that the NXC compiler have been significantly improved, so the speeds are not accurate anymore. But the NXT-G < NXC < RobotC order most likely haven't changed anyway...
We need to make some new speed tests... And some up-to-date language comparisons...
peter-cocteau wrote:I think NXC would be a good thing to learn this kind of programmation. It may be fast enough. But In my program I use lot of task, variables and single array, may be NXC is too limited ?
NXC programs can use up to 128 tasks if I remember correctly, and the variables are limited by an max amount of about ~63k and a memory size of 32 KB. These are the limitations of the firmware, so NXT-G is subject to these too.
My blog: http://spillerrec.dk/category/lego/
RICcreator, an alternative to nxtRICeditV2: http://riccreator.sourceforge.net/
peter-cocteau
Posts: 26
Joined: 04 Dec 2011, 12:12

Re: NXT-G, NXC, I2C..What to use to make fastest operations?

Post by peter-cocteau »

Thanks, I have no memory limitation problem with NXT-G, NXC would be good.

Oh! Last Thing!! I wonder if it is possible to create a faster NXT-G block to support SuperPro Card. I think Hitechnic blocks are made with labview? may be there is a way to minimize operation time?
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: NXT-G, NXC, I2C..What to use to make fastest operations?

Post by HaWe »

Doc-Helmut, which language is this sample ?
it's no specific language, it's pseudo-code that first has to be "transformed" into those specific languages to be able to become compiled...
I think Hitechnic blocks are made with labview? may be there is a way to minimize operation time?
IIRC, NXT-G is a Labview derivative/descendant, so I guess it might be only a little acceleratable (if at all).

---

BTW: what is that kind of orange device in front of your NXT?
Image
peter-cocteau
Posts: 26
Joined: 04 Dec 2011, 12:12

Re: NXT-G, NXC, I2C..What to use to make fastest operations?

Post by peter-cocteau »

Orange device is just a red led, nothing important, just for pleasure.
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: NXT-G, NXC, I2C..What to use to make fastest operations?

Post by HaWe »

sorry? I mean this device:
Image
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest