LabVIEW for LEGO MINDSTORMS and LabVIEW for Education

Showing results for 
Search instead for 
Did you mean: 

Creating New Blocks for LEGO MINDSTORMS NXT

I apologize for not being clear enough.  I have all the needed toolkits installed, but unfortunately I didn't have your main sub-VI to test the code.  The name of this sub-VI is  If you want to post this sub-VI, I will already have all the needed supporting files that are used.
As far as the "Tacho Limit" variable you spoke of, which VI or toolkit is that a part of?  Is that a parameter you're speaking of, or a VI function itself?
Peter L.
Applications Engineer
National Instruments
Message 11 of 45
Hello again Peter
I hope this sub-VI will help you to solve my problem.
The variable "Tacholimit" is one of the variables connected to the NXT-motor. It is controlled by the variable "UpdateFlags". There is one sub-VI in the toolkit called "" (it is not a online vi). This vi has another sub_vi called "". When looking inside it one can see that the distancecontroler uses, among others, the variables "Tacholimit" and "UpdateFlags". In the online sub-vis is not the variable "UpdateFlags" accessable (I haven´t found it). To be able to build a distancecontroller in the online mode I understand that I have to be able to write to this variable.
The best thing would be if one could just turn the "" into an online-vi with exact the same function (with access to the PID-parameters also). If you and your colleagues are working with a patch for the toolkit please try to include this function.
Thanks for your help.
0 Kudos
Message 12 of 45


That was the right sub-VI that I needed.  I actually should have been able to identify the problem without it, but I didn't come to that realization until after I tested it with it.  The issue you're facing is one of dataflow.  In your code that doesn't include a custom sub-VI, your Setpoint control and Stop control are both located within the While loop.  What this means is that after all initialization is done, then the While loop begins executing and Setpoint is read every time the loop iterates.  The subsequent PID code can then be called on each iteration and the motor can be changed.

In the second version (using a custom sub-VI), you have left Setpoint and Stop outside the sub-VI, and thus outside the While loop.  The code is actually doing exactly what was asked of it.  That is, the initialization routine is happening, then the Setpoint and Stop controls are being read once, then the sub-VI takes "dataflow" control of the program.  The controls are never again looked at.  This is also why the Stop button is not working.  Once it's been read, it is never looked at again, so the sub-VI doesn't stop execution and kick the dataflow back up to the parent VI when the button is pressed.

You are thus left with a few different ways of accomplishing this.  Either the controls can be down at the sub-VI level, meaning you'd need front panel access to that sub-VI, or you need to keep an iterating while loop up at the parent level.  Keep in mind, then, that anytime a While loop is within a sub-VI and you don't have a way of stopping it, the execution of the program will stay forever at the sub-VI level.  Another thing you can explore is the option of using local variables which effectively port information from a control in one part of a program to a different part of the program where that data is also needed.

Regarding the UpdateFlags variable, you are right in your assessment of the situation.  I've spoken with the developers of the NXT Toolkit code, and they are aware of this difference in available function options between the NXT and the direct commands.  I must say that I'm impressed at your PID implementation, however, which allows you to accomplish the same task!


Peter L.
Applications Engineer
National Instruments
0 Kudos
Message 13 of 45
I'm in the process of building a NXT block using LabVIEW 7.1. I've got the LabVIEW code running on the NXT, but the process of converting it to a NXT block is somewhat mysterious. (I've read the PDF about how to do it, but it's still mysterious.)

In particular, I can't quite figure out the VI vs. SubVI aspect of this. The PDF says to put code in the SubVI so that there won't be multiple copies of it. Then it warns about reentrancy concerns -- what if multiple instances of the block are running at the same time?

One theory I've come up with is that if I'm not using local variables, I'm safe and can put the whole thing in the SubVI. But I have no idea if my theory's correct.

What are the things that are shared when multiple instances of a block are running? What's the basis for deciding what to put in the implementation VI vs. what to put in the SubVI?

On another topic, the PDF says you have to use a particular conector pane pattern (p. 9), which has 4 connectors on each side, 2 on the top, and 2 on the bottom.

Does this mean that we're limited to 4 in and 4 out? Can we use the 4 in the middle also?

I hope you can have as many as you want, but the PDF seems to be saying not.

Another question: I created the LabVIEW code for my block and successfully imported it into the NXT software.  It, of course, does not work correctly in all respects on this initial try.  So now I want to edit my LabVIEW code and re-import it.  What's the right (i.e. quick, easy, works well) way to do this.  I tried the import tool that I downloaded and installed in the NXT software, but it doesn't seem to want to re-import my block, nor does it seem to give me a way to delete the NXT software's current copy of my block.

Anyway, thanks in advance for your help...

0 Kudos
Message 14 of 45
A VI and a subvi are exactly the same except that a subvi is called by either a vi or another subvi.

About reentrancy:
If you are not explicitly setting a vi to reentrant, it is not reentrant.
And you only do this when it has to be called from several places and they have to run at the same time.
A normal subvi is not reentrant what also means that if two callers try to get to the same subvi at almost the same time,
only one of them will succeed, and the other one will be waiting for its turn.
Normally you don't notice this waiting but if you have a lot of waits you can see this.
It is the way that LabVIEW takes care of your local variables, and shiftregisters.

Abot the connector, yes you can use all twelve connections but not more.
and if you need more parameters think of clustering them. Most of the time routines with so many parameters are not weel designed
or have more than one function and that also warns for a design flaw.

greetings from the Netherlands
Message 15 of 45
Hello ,
i tried somthing with an Array, but it won't wotk.
i put the result from an  I2C NXTCommLSRead into an indexed ARRAY. So far so good. Now i want to read out the Values.
I used one Indexed Array and expaned it to 5 Values. To the inputs i connected a Konstant . To each input one Konstant and to the output a Variable Labview don't reported any error. After i transfered it to the NXT the NXT reported error in File. So i copied the ARRAY the first Array gets 0 to the input and the second get 1 to the input and it works.
Does anyone have an idea ?
0 Kudos
Message 16 of 45
Index array always works.
If you index out of range ( a too high  or too low (negative) index)  the index array function returns the default value.
And for integer values that is zero.

I don't really understand why you get a file error.

greetings from the Netherlands
0 Kudos
Message 17 of 45
I am creating a block and I am having trouble with the Draw vi. I use an invoke node to get the value of a numeric, and then use the value to change what picture appears on the block. It is not working and I am not sure why. I have attached the Draw vi.
0 Kudos
Message 18 of 45

Hy evry body,

I am a little bit lost in this amout of information, I just want to know if i can create Blocks for LEGO MINDSTORMS NXT without using Labview, for example I want to use C++ or C# to do this.

Sorry if my reply is in the wrong place


0 Kudos
Message 19 of 45

You must use LabVIEW 7.1 to create blocks for the LEGO MINDSTORMS NXT Software; using C variants or any other programming environment will not work.  You may request a free copy of the Student Edition of LabVIEW 7.1 through NI's website:
James Blair
Message 20 of 45