As a mechanical engineer, you will learn the expansive language of programming. Programming is the process of writing a script for a computer to execute. This is usually used with Matlab, Labview, C++, or any other programming software. I will be walking you through how to use Boolean logic in a program script. Boolean logic works on a binary system, which tells the computer if something is good or bad. Examples of Boolean logic would be:
· Setting a range for a system (i.e. A musical instrument tuner)
· Dictate if a device is on or off. (i.e., A main pump goes out, then a standby pump will turn on)
· Dictate motor control logics (i.e., If you want a pump to go slow or fast)
As stated prior, Boolean logic works with a binary system. I will walk you through how to set up a Boolean logic system for setting a range on a system. We have three cases: case A, case B, and case C. Case A is true when input is 1, case B is true when input is 2, and case C is true when input is 3. Inputs can come into our program as any number but if it is not in our range, it will show that it is out of range.
- Establish the midpoint of each case. To do that, you take two cases, add their values together, and then divide by two.
- Using case A and case B: (2+1)/2=1.5
- With our midpoints and values, define the error of our three cases. To do that, use the upper midpoint and subtract our value from it. The result will be the range above and below the case value.
- Using case A: 1.5-1=.5. Therefore, case A is 1
- Relate input to our new value. Meaning, if you get an input, determine if it will be in case A, case B, case C, or none of the above.
- Using case A: .5<x<1.5 where x is our input
Now you have all of the cases specified, you can relate the cases to visual output (lights). Since
Boolean logic only works with on-or-off cases, you have to specify how the output (a light indicator) is related to the input. Using case A, you know the range is .5 to 1.5. So, if you have any value that is between those numbers, the case A light will light up. Here is how you would set up this logic.
- State the input is greater than .5 (x>.5)
- State the input is less than 1.5 in another branch (x<1.5)
- You now have two logics stating x>.5 and x<1.5. Since the output can only read one input, use the “and” statement to combine the two logics. The “and” statement takes the two logics, and makes an output that says our input can only be greater than .5 and less than 1.5 for case A to be true.
- Take output of your “and” statement, and send it to your case A light
Now repeat the process for the other cases. To do the out-of-range logic, you simply make two logics that state x>3.5 (our highest value) and x<.5 (our lowest value). Then follow steps 3 and 4 in the last list. Now you have a Boolean script that when you input a value, you will be told which of the four cases is true.
Comments (0)
You don't have permission to comment on this page.