RicEditor tutorial: Create a cannon game

How to set up the start up loop

When creating moving objects on the NXT screen, the important thing is to change the objects coordinates. This is done by changing the values of the parameters, since the parameters are the objects coordinates. The way this is done is shown in the start up loop below:
game_4vit

It is this loop that makes the “animation” in the picture. every 1/10 of a second the picture is drawn once again after the screen has been erased. And if, in meanwhile, an objects parameters has changed, this object will “move” to the new position. This loop is of course very important to the program, but once it is finished, we can leave it alone. It will continuously update our RIC file. The create Code button will help us make this start up loop. We start by pressing the Create Code button:
CreateCode

When you press this button the following window will appear on the screen:
set parameters

By default the parameters name is the same as the parameter number. But it is best to select more logical names as we did in the view RIC file part of this website:
parameter_table

We insert this for the parameters:
namingparameters

We press the OK button and then we’ll get a new VI or program with the start up loop inside:

startprogramWhen the program start the values in the front panel is passed via the build array command and further to the draw command. But by default all the values are zero. So we have to change them to our start up values:

startuovalues

PLEASE NOTE!!! A very common mistake for beginners of LabVIEW is that changing the values like this DOES NOT make these values the default values for the control. So, even if you save the file and open it again, the values are all zero, because zero is the default value. To make this current values the defalut, we right click the control, and select data operations/Make Current value default:

makecurrentvaluedefault

 

We have to do this for all the 7 controls and then we SAVE the file. The name of the file might be cannon_game.vi. But one thing is missing: the command advanced picture needs to know the name of our RIC file:

helpadvanced picture

Connector 3 asks for a filename. To fix this we select the wiring tool, right-click on this connector, and select create/constant:

create constantfilename

In the constant that pop up we enter the filename (i.e. cannon.ric):

filenamedoneNow the start up loop is finished! Now there is a lot of things we can do! I think we can start with moving the cannon around the screen with the NXT buttons.

The following two tabs change content below.
Svein-Tore Narvestad

Svein-Tore Narvestad

I have used LEGO Mindstorms as a teacher since 1999, and have used it widely. For example, to measure noise in kindergartens, to have the students create lemonade blenders using small pumps connected to the NXT, and in process control with industrial equipment: pneumatics, industrial sensors, etc.