LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Need help converting a C++ code to equivalent LABVIEW VI without using Call Library Node

Greetings,

 

I have developed a C++ code which basically provides green light timer to different roads by bubble sorting an array whose values are number of vehicles provided by image processing the traffic. I am not good at LABVIEW hence need some help converting this code to LABVIEW elements. I am attaching the code, kindly help me out.

 

If anyone needs explaination for the code kindly let me know.

 

Thank you

0 Kudos
Message 1 of 5
(2,395 Views)

Can you describe in words what the code is supposed to do?

 

LabVIEW has array sorting built-in (bubble sort is not very efficient anyway), so why not use that for the sorting step?

0 Kudos
Message 2 of 5
(2,387 Views)

As I said before I am not that good with LABVIEW so don't know most functionalities

 

Here is the logic for the program:

1. Input number of cars in each lane into the array(say 4 values for 4 roads)

2. Sort these values in decreasing order

3. First road  with highest number of cars gets green timer with 50 seconds

4. Next we sort the rest of the three roads and if the number of cars is more than the first road we provide it 50 seconds again, otherwise 35 seconds

5. Same thing we do for the leftover 2 roads, if condition is false then time is 20 seconds and 15 seconds respectively.

6. Once the whole operation is completed the counter is reset to count the number of cars again so is the green timer also reset of 0 seconds and the cycle repeats itself.

0 Kudos
Message 3 of 5
(2,377 Views)

Here is the logic for the program:

1. Input number of cars in each lane into the array(say 4 values for 4 roads)

2. Sort these values in decreasing order

3. First road  with highest number of cars gets green timer with 50 seconds

4. Next we sort the rest of the three roads and if the number of cars is more than the first road we provide it 50 seconds again, otherwise 35 seconds

5. Same thing we do for the leftover 2 roads, if condition is false then time is 20 seconds and 15 seconds respectively.

6. Once the whole operation is completed the counter is reset to count the number of cars again so is the green timer also reset of 0 seconds and the cycle repeats itself.


Input an array of 4 clusters integers and associated road IDs (make sure the count integer is 1st item in the cluster)

Sort the array of clusters in decreasing order

take the first element of the array and set the light green, wait 50 seconds,

 

Now, I lose it, why sort the remaing 3?  They were sorted as the first sort, just take the next item.  The second item cannot have more than the first road due to the sort.

 

But you can compare the value to the previous one by using a shift register on a for loop for dealing with each direction.

 

LabVIEW ChampionLabVIEW Channel Wires

0 Kudos
Message 4 of 5
(2,350 Views)

If you are using thie problem to learn LabVIEW programming, the best (and may the only way) to do this is to give it a try, yourself.  This problem can be (fairly) easily programmed in LabVIEW -- look online for a link to LabVIEW Basics tutorial, which should give you most of the information you need.

 

Some things to consider.  The basic idea is that you do something until you are all done -- this is a While loop, with the "All Done" condition wired to Stop.  Your basic data structure seems to be an array of 4 elements (number of cars).  There's an Array function that will sort this array -- if the sort is in the "wrong order", you can always use the "Reverse 1D Array" function.  It appears you don't process the array one element at a time, but rather split it into "biggest (first) element" and "remainder of the array" -- the Delete from Array function will perform this split for you.

 

I couldn't follow all of the conditions that you stated (I wasn't always sure what the "first" element meant).  It did look like once you dealt with the current largest and "rest of the array", you then did something similar with "rest of the array", that it, you split it into "largest" and "rest", then had rules for what to do.  With the exception of some of the timing (50 seconds, 35 seconds, 20 seconds), the processing of the "rest of the array" looks very similar to the processing of the original array.  if this is the case, the problem is recursive in nature, and LabVIEW can also handle recursive calls (though you can also just code the entire thing as one big procedure with nested Case statements depending on the depth of the problem).

 

Bob Schor

0 Kudos
Message 5 of 5
(2,335 Views)