Loginskip to content

Advanced NXT-G Block Techniques - Part III

news/
software/
NXT Repository/Programming/
NXT Repository/Tutorials/

In one of my previous posts I discussed how the NXT-G compiler does code optimization. Among the optimizations done automatically by the NXT-G compiler is ignoring implmentation VI diagram parts which are never reached by the program. In particular, say you have a Switch connected to a constant - only the case given by the constant will be compiled. One can take advantage of this when creating NXT-G blocks with multiple possibile actions. For instance, my Fixed-Point operations block has 6 actions - addition, subtraction, multiplication, division and conversion from Numeric to Fixed-Point and vise versa. The “FP Block.vi” implementation VI has all 6 in a switch, with a constant holding the current action. Note that this constant MUST resides in the “top” VI, not a SubVI, otherwise it will be common to all copies of the block in the NXT-G diagram.

This nice feature, however, posses some difficulties. To manipulate the value of controls in the Config VI and Draw VI of your block, you invoke the “Get Control Value” of the VI:

However, this DOES NOT work for constants, even after you figured out what is the label of your constant (right-click the constant and select “Properties” to set it).

A similar problem occours in writing new values. The “Set Block Param.VI” supplied by the toolkit does not work for constants.

Using VI scripting I’ve written two VIs that allow reading and writing a constant value in implementation VIs. Reading is done by “Get Const Value.VI”:

and writing by a similar “Write Const Value.VI”. Both VIs can be downloaded here.