04-22-2020 11:28 PM
I am using a laser beam to detect if a fish swims between two tanks (A and B). Every time the fish swims between either one of the tanks it breaks the laser beam. When the laser is broken it has an output of 5V and when it is not broken its output is 0V. How do I set a trigger that only changes from false to true when the voltage goes above a threshold, but stay either true when the voltage goes below again and does not change to false until the voltage goes above the threshold again? I thought it would be rather simple to do but can't find any examples online on how to do it.
I am using a NI USB-6008 with the DAQmx driver.
Solved! Go to Solution.
04-23-2020 12:07 AM
Keep the previous value in a shift register (initialized with FALSE) and OR that with the comparison result. The output goes back to the shift register.
04-23-2020 12:38 AM
Thank you for your quick answer!
I made a quick simple program to see if I could get a Boolean switch to turn on and off every time I went above a threshold of 5 with a slide controller. I must not understand your explanation completely because I can only get the switch to stay on and not turn off again.
04-23-2020 01:03 AM - edited 04-23-2020 01:04 AM
04-23-2020 01:45 AM
@Math808 wrote:
How do I set a trigger that only changes from false to true when the voltage goes above a threshold, but stay either true when the voltage goes below again and does not change to false until the voltage goes above the threshold again?
Ah sorry, I did not completely understand your requirements. What is "stays "either" true". Is there an "or" somewhere?
My suggestion will stay true forever. Don't forget to initialize the shift register.
Can you lost all possible states and transitions of your system?
04-23-2020 03:25 AM
04-23-2020 01:37 PM
Thank you for the great answers, it is much appreciated.
We have decided to make it even more complicated. To make sure we know the fish actually went from tank A to tank B and vice versa and is not just breaking the laser in the middle and swimming back to tank A, we are putting in two lasers horizontally between the tanks. This means if tank A is the true condition, it should only switch to tank B or the false condition if laser 1 is broken followed by laser 2 and then laser 1 is restored followed by laser 2, or in other terms, voltage input 1 increases above threshold followed by voltage input 2 going above the threshold then voltage input 1 goes below threshold followed by voltage input 2 going below the threshold. It should then again be able to switch to tank B or the false condition if the opposite happens: if laser 2 is broken followed by laser 1 and then laser 2 is restored followed by laser 1.
I was thinking of making a queued state machine, but that would only give me one direction.
Best regards
Mathias
04-23-2020 01:52 PM - edited 04-23-2020 02:12 PM
If you just want to indicate which tank the Fish currently is and the sensor spacing is smaller than the fish:
>>>Simple: Whatever sensor went from TRUE to FALSE last?
04-23-2020 03:11 PM - edited 04-23-2020 03:17 PM
We are creating whats called a shuttle-box or a choice system. In short, the system consists of two mesocosm tanks (A and B) between which a fish can swim freely. When the fish enters tank A suspended sediment levels continue to rise and when it enters tank B sediment levels continue to reduce. By swimming back and forth, the fish can behaviorally choose the maximal sediment load it encounters as it hunts for food or shelter. That means when the fish is tank A I need to turn on a set of pumps going into the tank and when it goes over to tank B I need to turn does pumps off and a new set of pumps turn on.
Yes, there is only one fish and I will know the starting position of the fish. The distance between the lasers is much smaller than the fish. The tunnel between the two tanks will be perfectly sized for the fish so it will not be able to only break one of the sensors or something like that. It can only break them in one of the before mention sequences depending on which tank it is traveling to and from.
I think I see what you mean that makes sense, so I should set up a condition where if sensor 1 went from true to false last it is in tank A and if sensor 2 went from true to false last it is in tank B?
04-23-2020 03:19 PM
Maybe something like this?
(Whenever both sensors are OFF, it detects which one turned off last....)