LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Simple Program Help

Greetings you coders of G, you princes of OOP!
 
I have a simple program I am working on and just something about it doesn't sit right with me. It works, but I know I'm not doing it a very elegant (or near best) way.
 
So here's the run down. I have 5 tanks, they are named "Tank1", "Tank2", "Tank3", "Tank4" and "Tank5". In the physical world they are not arranged in numerical order because we like to do things as confusingly as possible here. So the order of tanks is really 2-5-1-3-4.
 
This program is a subVI that is fed a string indicating which of the tanks we are currently at. It then is fed another string that tells which of the tanks we wish to travel to.
 
The program will then indicate whether we need to move up, down, or stay put reguarding the 2-5-1-3-4 order based on where we are and where we want to go (moving up being moving to the left, and right moving down).
 
Attached is the way that I did it, just looking for any suggestions, flames, or improvements. Thanks! 
 
0 Kudos
Message 1 of 7
(3,349 Views)

I'm sorry, but I'm working with LV7, and can't take a look at what you did.  Personally, though, I think I'd create a 1D array of elements {2,5,1,3,4}.  Using the provided inputs and a "Search 1D Array" node, you could find the indices of the two tanks.  Subtracting these would give you which direction (negative value for one direction, positive the other) and, if needed, how far to go.

Probably more elegant solutions (and I apologize if your current method already trumps mine, or if I'm missing some important detail), but those are my initial thoughts on it.

-Cory
Message 2 of 7
(3,340 Views)
I would use an array of Direction Engine.ctl rather than strings. It eliminates the case structures to select strings to compare to the array and eliminates spelling and duplication errors.

Lynn
Message 3 of 7
(3,333 Views)

Hey Coreys! Thanks for the response!

The first part of our programs are the same (the array bit), but the way you did the subtracting of the indices is much better than mine. I checked to see if they were equal, if they were, no move, if they weren't I did a second comparison to see if the first was greater than the second.  I had a case structure within a case structure and while I was coding that, it nagged me that there had to be a better way.

Thank you!

0 Kudos
Message 4 of 7
(3,330 Views)
Thank you for the replies Lynn and Tbob! I definately prefer the "all enum" route for it's neatness. The one catch I might have is this program is a subVI and the string is generated from a barcode scanner that actually reads "Tank1" and sends it to this VI. I should have pointed it out, but the enums there were just to allow "simulated" inputs so I wouldn't have to attached the rest of the program and complicate things. The two strings will come from another VI and won't be generated within this one.

 

Message Edited by jmpugh on 08-17-2007 03:58 PM

0 Kudos
Message 5 of 7
(3,325 Views)

Glad to hear I could help!

Sometimes all it takes is a second viewpoint (or possibly no view at all!) Smiley Very Happy

-Cory
Message 6 of 7
(3,322 Views)

You can eliminate half the code by defining the enum in the same order as the tanks, then comparing enums directly instead of array indeces.  See attached code.

 

Message Edited by tbob on 08-17-2007 01:54 PM

- tbob

Inventor of the WORM Global
Download All
Message 7 of 7
(3,321 Views)