LabVIEW for LEGO MINDSTORMS and LabVIEW for Education

cancel
Showing results for 
Search instead for 
Did you mean: 

count iterations

hi all,

 

 

i have a very simple question,

 

i want to count iterations for my code, my code is weels forward (count +1) weels backwards (count +1)

that means after one main loop it should count 2 (forward and backwards).

 

 

how can i do it? can you correnct my .vi file?

Download All
0 Kudos
Message 1 of 7
(7,430 Views)

The JPG of the code that you posted shows some very odd-looking code indeed.  Wiring a "true" constant to a while loop's termination condition will cause that loop to get skipped completely. Wiring a "false" constant will cause the loop to run forever. So, the code you posted effectively does nothing, forever. That's probably not what you meant. Smiley Tongue

 

Can you tell us a little more about exactly what you are trying to get your NXT to do with this code?  Looks like maybe move forward, then backward, over and over...

 

------
James Blair
NI R&D
0 Kudos
Message 2 of 7
(7,419 Views)
Oops, my mistake. A "true" constant causes the loop to execute exactly one time, not zero times. Your code makes a little more sense now, but some of the loops are unnecessary.
------
James Blair
NI R&D
0 Kudos
Message 3 of 7
(7,417 Views)

hi, the code is for running forward and reverse infinitly, i only need to count the motor turns.

 

my intention is to implement the general idea on some other code i am working on.

 

can you tell me what is odd about that code and how do i fix it? 

 

 

0 Kudos
Message 4 of 7
(7,414 Views)

The thing that's odd is all of the extra while loops that aren't actually looping. You only need the outer loop to make sure the program runs continuously.

 

Attached is a screenshot of how I'd probably program this. The sequence frames guarantee that I'm counting actual turns of the motor as those turns happen.

------
James Blair
NI R&D
0 Kudos
Message 5 of 7
(7,407 Views)

Dear James,

 

 

thanks a lot for you'r help.

 

 

i tried you'r solution and got some errors.

 

plus the shift reg. are orange instead of blue like you got.

 

 

itai.

Download All
0 Kudos
Message 6 of 7
(7,378 Views)

The orange vs. blue wires are important and are, in fact, the cause of your errors.

 

The orange wire indicates a "double" data type, which is a floating point data type. Since the NXT doesn't support floating type, you get errors.

 

The blue wire indicates an "integer" data type, which doesn't use floating point. To change your orange wires to blue, right-click on the "0" constant and change the Representation to U32. You'll also need to do the same for the Numeric indicator.

 

See here for more info: http://zone.ni.com/reference/en-XX/help/371361F-01/lvhowto/changing_numeric_represent/

 

Hope that helps!

------
James Blair
NI R&D
0 Kudos
Message 7 of 7
(7,369 Views)