‎04-03-2019 03:37 PM
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.
‎04-03-2019 03:45 PM
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
‎04-03-2019 03:51 PM
@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.
‎04-03-2019 04:03 PM - edited ‎04-03-2019 04:04 PM
@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.
‎04-03-2019 04:06 PM
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.
‎04-03-2019 04:28 PM
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:
I'd write this as a VI called an "Action Engine" that had two "Actions":
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"):
Bob Schor
‎04-03-2019 08:34 PM
@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!
‎04-03-2019 08:36 PM
@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!
‎04-04-2019 05:15 PM
@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