LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Send a different value each time instead of an increment

Hello,

 

I have a question that I might be overthinking. I have a Labview code controlling a rotating mirror to turn to a certain angle. Originally I wrote the code with a while loop that it has a start angle (let's say 10), an increment (such as 2), and a final angle (like 20), the mirror will stay at 10, then 12, 14, and so on until it reaches 20 and everything is functioning well. But now I want the mirror turn to specific locations each time such as 10, 13, 17, 18, is there an easier way to do this? This is part of a bigger code that when this step finishes, the process then goes to the next case in a state machine.

 

I thought of an inefficient way was to repeat the code which is not good. Also thought of putting the values I want as an array but could not solve the problem when connecting the shift register. I also thought of putting the values into a text file and then input, but this seems to be too complicated.

 

Would anyone please provide some suggestions and comments? Thank you.

0 Kudos
Message 1 of 9
(2,927 Views)

Unless you can make a mathematical formula that describes your rotation, then either arrays or text file. For example let x equal the angle, for your first case

y = 2*x +10 (x=0,1,2,3,...)

 

for more complicated movement (quadratic)

y=1/2x^2+2*x+20

 

but this obviously won't work for a random list of numbers like your last example.

 

mcduff

0 Kudos
Message 2 of 9
(2,923 Views)

@KHHMD12 wrote:

Also thought of putting the values I want as an array but could not solve the problem when connecting the shift register. I also thought of putting the values into a text file and then input, but this seems to be too complicated.

 


Use an array, but not in a shift register. You can right click to change tunnels between "through" and "autoindexing". Autoindexing tunnels will automatically iterate through each value in the array as it steps through the loop.

0 Kudos
Message 3 of 9
(2,918 Views)

@BertMcMahan wrote:

@KHHMD12 wrote:

Also thought of putting the values I want as an array but could not solve the problem when connecting the shift register. I also thought of putting the values into a text file and then input, but this seems to be too complicated.

 


Use an array, but not in a shift register. You can right click to change tunnels between "through" and "autoindexing". Autoindexing tunnels will automatically iterate through each value in the array as it steps through the loop.



Hello,

Thank you and I forgot to mention I also tried autoindexing, but it seems that the loop is not reading each element in the array. Is there anything I didn't pay attention to? I searched and I thought after autoindexing it would read one value each time, but in my code it is not doing that.

0 Kudos
Message 4 of 9
(2,909 Views)

No, autoindexing does read one value at a time- your code must either be not creating the array right or some other issue is going on. If you post your code we can take a look at it.

0 Kudos
Message 5 of 9
(2,903 Views)

I'm not entirely sure what you want to do, so I'm going to "take a guess" and then describe how I would solve this (possibly-not-appropriate) problem:

  • You have a finite set of values (say 3, 1, 4, 1, 5, 9) (they don't all have to be different, but they do need to be in a specific order).
  • You want to get "the next value" over and over again, starting with 3, and after 9, doing 3 again (so your sequence will be 3,1,4,1,5,9,3,1,4,1,5,9 ...).

I'd write this as a VI called an "Action Engine" that had two "Actions":

  • Initialize, which takes an array [3, 1, 4, 1, 5, 9] and returns the first element.
  • Next, which returns the next element, taking care to "wrap around" properly.

You didn't attach any code, so I don't know what version of LabVIEW you are using, and can't "guess" how experienced you are, but I'm going to "guess" you might not know about Action Engines.  So let me describe this (you'll have to code it yourself, but it will be "good practice"):

  • I'd create a new VI using the default 4-2-2-4 Connector Pane.  I'd call it something like "Mirror Position", and would make an Icon using the Icon Editor so when I put it on the Block Diagram, I would know what it was (a big square box with the words "Mirror" and "Pos'n" on two lines works for me).
  • The bottom left and right connectors, of course, get Error In and Error Out;
  • The two two left connectors get "Initialize" (a Boolean) and Position Array (an Array of the Positions you want to step through).
  • The output has "Next Position", which is of the same type as the elements in Position Array (i.e. everything is a Dbl, or an I32, whatever).
  • On to the Block Diagram.  Drop a While Loop, put a Case Structure inside it, and wire the Error line through both of them (you probably know you need to actually "connect the wire" to the left edge of the While and Case, and can then drag the wire through the rest of the structure and connect to Error Out on the outside).
  • Wire a True to the While's Stop terminal.  This make it a "Do Once" loop.
  • Wire Initialize to the Case Statement selector.
  • Wire the Array to a Shift Register, and pass that through the Case Statement to the other side.
  • Create another to hold the size of the Array.
  • When Initialize is True (the "True" Case), you want to do the following:
    1. Get the Array Size and bring it to one of the unused Shift Registers -- label this "Array Size".
    2. Bring the While Index ("i") into the Case and pass it through a Quotient/Remainder function, with Array Size as the divisor and the Index as the dividend.  Use the Remainder to index the Array (you can wire this to the Array "passing through" between the Shift Register) and bring the output to the "Next" indicator.
  • The False case is almost identical -- the only difference is that instead of an Array Size function, you use the saved Array Size from the "True" case, saved on the second Shift Register.
  • To use this, the first time you call this function, you need to call it with your Array of Positions and the Initialize indicator set to True, and for every other call, you give it no inputs, only outputs.  It's a little awkward doing it this way, but with a small modification, you can change the Initialize case so that it gives you the last element of the Array (which you ignore), and then starts "repeating".  This allows you to call Mirror Position once at the beginning of your program, with True connected to Initialize and your Array also connected, and when you are using it (inside a loop in your code), you simply call it with no inputs wired, allowing the Initialize input to take its default, False, value.

Bob Schor

 

0 Kudos
Message 6 of 9
(2,897 Views)

@BertMcMahan wrote:

No, autoindexing does read one value at a time- your code must either be not creating the array right or some other issue is going on. If you post your code we can take a look at it.


Thank you again and I will check again once I have access!

0 Kudos
Message 7 of 9
(2,876 Views)

@Bob_Schor wrote:

I'm not entirely sure what you want to do, so I'm going to "take a guess" and then describe how I would solve this (possibly-not-appropriate) problem:

  • You have a finite set of values (say 3, 1, 4, 1, 5, 9) (they don't all have to be different, but they do need to be in a specific order).
  • You want to get "the next value" over and over again, starting with 3, and after 9, doing 3 again (so your sequence will be 3,1,4,1,5,9,3,1,4,1,5,9 ...).

 


I deleted part of the quote to save some space here. Thank you for the help and I didn't think of this wat before but it is definitely worth trying. I don't need to do the values over again but will only need 3,1,4,1,5,9 and finish. Your detailed explanation however gave me some ideas!

0 Kudos
Message 8 of 9
(2,875 Views)

@KHHMD12 wrote:

Your detailed explanation however gave me some ideas!

Great!  The goal was precisely to "give you some ideas" so you could solve the problem (which you know better than anyone else) yourself.

 

Bob Schor

0 Kudos
Message 9 of 9
(2,852 Views)