From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to create a negative feedback on a case structure to estimate gear changes from an array of speeds

Solved!
Go to solution

Hi I am new to programming and LabVIEW and I am trying create a program which can estimate gear changes based on what speed bracket the vehicle falls in. The speed is measured by an OBD device and results are logged to a spreadsheet. I have created a sample program which contains a loop which reads the array of speeds row by row. I have then set up a 2 case structures for 2 example speed brackets each bracket represents a gear (3rd gear 35-54kmph, 4th gear 55-79kmph). My problem is I wish to count how many times the speed changes from one bracket to another to symbolise a gear change. At the moment my program will just count the number of speeds within each bracket from the entire speed array.

So in summary I need help trying to create a negative feedback effect so that the first speed which falls within a speed bracket is counted as a gear change but none of the speeds following it are counted until a new speed bracket is entered.

I have attatched the log file and VI any suggestions would be greatly appreciated!

 

Thanks,

Michael

Download All
0 Kudos
Message 1 of 4
(3,380 Views)
Solution
Accepted by topic author mmahon365

Hi Michael,

 

I have made a few changes to your code

 

1. Replaced the 2 case structures with one, which outputs the current gear.

Using numerics (instead of booleans) as the case selector - you can only use integers; I see in the CSV file that all your speeds are integers anyway, but I added a bit of code which will convert to an integer, rounding down. So where the logic says 35-54kph inclusive, because anything between 54 & 55 will have been rounded down, this will also take in speeds up to 54.999999 (etc) if needs be.

I have then sent this "current gear" variable to a shift register, so each iteration of the while loop can compare the current gear with the previous gear. This case structure outputs a 0 if the speed is outside of the limits (35-80).

 

2. I have added code which basically says "Is the new gear different to the gear from the last iteration? YES - increment the number of gears variable. NO - Do not change the number of changes variable" This variable is also passed into a shift register, so that is can be passed from iteration to iteration.

 

3. I have gotten rid of the 2 shift registers which you had added, to index sectios of the array, as it is more efficient/less code to just use the iteration terminal. (Remember iterations of loops are zero indexed).

 

At the moment, the code which I have written outputs the total number of gear changes (0-3, 0-4, 3-4 4-3, 4-0, 3-0). If you only want the gear changes to be counted between 3 & 4, you could put a case structure around the section of code which I have added a decoration box around, and only run that code if the current/previous gear is not = 0.

 

 

I hope this helps - at least to give you an idea of how this can be accomplished.

 

Thanks,

Amy

Amy K
Applications Engineer
National Instruments UK & Ireland
Message 2 of 4
(3,303 Views)

Thanks very much Amy this is very helpful and a very clear explanation. Really appreciate the help.

 

Thanks,

Michael

0 Kudos
Message 3 of 4
(3,285 Views)

Brilliant, glad it helps!

 

Amy

Amy K
Applications Engineer
National Instruments UK & Ireland
0 Kudos
Message 4 of 4
(3,269 Views)