Open svavassori opened 3 years ago
Hey, I don't have an active hive right now either...
That's a great idea of sharing unfiltered data. I did capture some on another laptop for just that purpose. I'll see if I can dig it up.
On Mon, Apr 12, 2021, 4:02 AM svavassori @.***> wrote:
First of all I'd like to thank you to put freely available the design of the board and the code to run it.
Looking at the Arduino code I saw that your counter is based on time threshold (200 ms and 600-650 ms) to avoid some bouncing in the reading.
This gave me the idea to try to detect the entering or the exiting pattern in a way that is robust with respect to the bouncing of a single sensor of the gate at a time. This gist ( https://gist.github.com/svavassori/431e78c2d9f1ff55adb63623408eb033 ) implements a state machine that detects the entering or exiting of a bee for a gate, the extension to multiple gate can be easily done be extending the State current[] array to the side desired.
Unfortunately I have no access to a beehive until some months, so I was wondering about these two possibilities:
- if you could test it on your board (the integration shouldn't be difficult) to see if it actually works, or
- if you could share some unfiltered captures of a single-gate sensors (in-out) in order to have real sequences, so I can test it by myself and see if it works.
Regards, SV
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/hydronics2/2019-easy-bee-counter/issues/17, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA3MOPGSXOUT6SIB3A3W6PTTIKSKJANCNFSM42YX36LA .
If you could find those, it would be awesome because it will also validate (or invalidate) the assumption of a single sensor change per gate.
Let's hope for the best!
Do you have any news about the raw capture of the gate?
Do you have any news about the raw capture of the gate?
Hi,
I am interested in the variant of the project, I have the system available on a hive from which I detect the data as a protocol created by hydronics2 ( very beautifull), you can check the data is as follows link : https://thingspeak.com/channels/1141102 as you can see I have some problems as the data between bees in and bees out are not very aligned, some days the variant is also 15000 bees, I think the problem is on the setting of the times, I made several changes without solving the problem. if you have the possibility to send the sketch already compiled on the arduino system, not in C, I will install it for testing.
@rodece I saw you have almost 20k bees as difference between out and in count over a 24h period, that's really strange. Usually out count should be a little higher than in because bees are dying outside and are born inside, so you have a net flux from inside to outside, but what you got is way too big for a single day.
Moreover it seems that the temperature sensor could be exposed to direct sunlight since it peaks at 11:00 instead of at 16:00-17:00
I don't have an Arduino here because I'm using an ESP32, but before plugging in the state machine, I would like to ask if you can run this sketch to get some raw data: https://gist.github.com/svavassori/37b6db89e4ab47f45748939dbb8f16b2, its output should be like:
1554582,00
1554593,00
1554604,01
1554615,11
...
It's a stripped down version of @hydronics2 one that prints to the serial line only the raw values of sensors at Gate 0 for each loop. In this way we can see how much debouncing (spurious state transition of the sensor) there are and if the precondition on which my solution is built is met (singe sensor transition at a time). If that condition isn't met, the current implementation will go in an error state and so wouldn't be of any use.
The idea is to record what it is read from the sensor (a dozen of bees entering and exiting should be enough) in order to understand the timings and the cases that we face and then to find a solution to properly count the bees (or at least reduce the false counts to a number so small that it doesn't impact on the final result. Please, pay attention that this version doesn't count, it simply prints the state of each sensor, so it is important also to observe the gate and count them manually (or record a short video) in order to know what was actually happening.
Since gate 0 is the first one, probably it won't be so frequently used by the bees, so closing some other gates with a stick of wood for a couple of minutes can help in getting the results in a shorter time. :-)
@svavassori
I saw you have almost 20k bees as difference between out and in count over a 24h period, that's really strange. Usually out count should be a little higher than in because bees are dying outside and are born inside, so you have a net flux from inside to outside, but what you got is way too big for a single day.
Yes, you are right, however in these days there was a high import, today the values are more correct.
Moreover it seems that the temperature sensor could be exposed to direct sunlight since it peaks at 11:00 instead of at 16:00-17:00
The sensor is installed behind the hive, but the apiary is installed in a wood and the sun only comes around 12 o'clock
I have two bee counters with feather M0, on the second I made the modification you requested and the data can be found in: https://github.com/rodece58/contavoli/tree/main/log_25_06 ( log and video have the same number), as you can see they make mistakes, I think due to the fact that the bees can also transit by walking on the sides of the gate and perhaps they are unable to engage the two sensors. I think try to tighten the gates and do the test again , I just have to check if the drones pass.
@rodece, thanks for your files, they have been very helpful to do an offline analysis.
As first I tried to run the state-machine as it is but it got stuck too many times to be happy with, so I changed its behavior to reset itself when the gate comes empty again: in this way it doesn't block and just skip the problematic parts. Unfortunately, by doing some stats, it came out that it counted:
This means a 41% of sequences aren't handled properly, and that is not a good number, so probably my assumption of a single-change isn't that right.
Then, I calculate the time it took for each detected bee to pass through the gate, in order to have an idea of the time it needs and the results are interesting, I plotted them in this simple frequency chart:
As it can be seen, filtering below 650 ms it would cut out more than 20% of the counted bees (13 over 56), so at least the idea of being time-independent does make sense, because of the variance of the distribution.
Another interesting thing of the raw data is that it can be seen there are some bees on the inside that check the gate (starts from the inside but then go back) while the bees that are coming in are pretty resolved and traverse the gate without too many doubts.
About tightening the gate, in order to let the drone pass you could tighten just the first and leave some others open. Of course this will imply we aren't counting all the bees, but just to test if it reduces the errors it could be enough.
I saw you uploaded the videos (thanks a lot!), I'll take a closer look later on, but at least they validate that it was mainly an incoming traffic. At first sight, in one of them it seems there are two bees entering at the same time, would that be possible or it's just the point of view of the camera?
I had a look at the size of the gate on the PCB schema and compared with other references: I think the gate is definitely too big and bees could probably pass on the sides without being detected by the sensors.
From the schema, the gate should be 9.85x15.3x8.4 mm (WxLxH) while the two sensors are around 2 mm wide, this means there is 4 mm on each side that can be used by the bee. Could you please check those measure (9.85x8.4) matches the build one?
Looking at this image, it can be seen how much space there is.
As reference, the classical metallic entrance has gates of 7.8x7 mm (WxH) and the grid of the queen excluder is spaced 4.1 mm, so if the above measures are correct, it means the gate should be shrunk by 1.1 mm on each side; some black tape should be enough for testing.
It could be that also the bottom would benefit of 1 mm lift, in order to avoid two bees passing on top-bottom, but first I would prefer to see how the counter behaves only with shrinking. This top-bottom dual-passing can be observed in the video @hydronics2 shared at second 13: in the center of image, in the gate right under the yellow capacitor, a bee with pollen on her legs is entering and while she is still in the gate, another bee exits from the top
@svavassori Good job !!! I confirm that the bees also walk on the sides of the gate, see video 4. I checked the port measurements and they are 97L x 87H under the sensor. I changed the dimensions of the doors with black plastic sheets, now they are 80L x 70H under sensor. I did the test on 3 hives with different traffic, the data have improved even if not completely. https://github.com/rodece58/contavoli/tree/main/log_30_06 On Saturday I try on the same hive as the first tests and load the log.
In log_arnia_1.txt
there aren't any inconsistent sequences, so it seems it is mostly working, however in the video I see 7 bees entering; it is possible that there is a time misalignment between the video and the raw data.
In video_arnia_3_new.mp4
there are too many bees to be able to count, and the increased wrong sequences is probably due to the fact that they are entering one behind the other. Another confirmation of that is in video_arnia_5_new.mp4
there are less errors and it is less crowded. This is a limitation of the system that I don't think is possible to resolve since we cannot ask bees to enter one-by-one with some space. :-) At the same time, I can imagine that with all the gates working, it wouldn't be that crowded.
Are they doing some washboarding on the top surface?
In video_arnia_5_new.mp4
it seems that sometimes two bees are trying to enter and when they reach the sensor only one of them passes. A small improvement would be to level with some strips the top part so the sensors don't extend from the surface, this will also reflect the 7 mm high right from the entrance.
When you will do your next Saturday test, I would also ask if you can change in the Arduino code the last delay(15)
to delay(9)
in order to increase a little the sampling frequency from 62 Hz up to 100 Hz. I don't expect any major benefits but it is just to see if it can help in differentiate some edge cases.
From the specs we have to do a minimum LED off time of 7.5 ms, so we have still some margin.
I make a tests, find the results on https://github.com/rodece58/contavoli/tree/main/log_03_07, I changed the delay as per your instructions. I have also modified the gate by inserting an internal 8mm tube, see attached photo, now only one bee passes !!! ;-) The data seems to have improved. As you said there is too much traffic on a gate, to reduce the errors perhaps it would be better to be able to enable an another 3 - 4 gates to check if the counter is working correctly.
I have also modified the gate by inserting an internal 8mm tube, see attached photo, now only one bee passes !!! ;-)
I saw from the videos that with the tube it seems they slips and it is problematic for them to enter upside down.
As you said there is too much traffic on a gate, to reduce the errors perhaps it would be better to be able to enable an another 3 - 4 gates to check if the counter is working correctly.
Sure, with less traffic should perform much better. The mention I did about closing some gates was to increase, if needed, the traffic through the monitored gate, not to let only that open :-)
Thanks for the new dataset, here is the relative frequency chart:
This confirms two things:
A gate traversal in 50 ms is very unlikely to be a real bee (walking 20cm/s is too fast), so anything below 100 ms would be suspicious, and probably is due to two bees at each side of the gate that accidentally trigger a sequence that matches an inbound (but it could be an outbound as well). Nonetheless this is not a big problem since it can be easily filtered by doing some stats and see what is a reasonable minimum time to get through the gate. A possible way to have some reasonable value about that threshold is use piece of transparent tube as gate and record a video on top of it with a millimeter band next or under. The visual assessment of the speed has to be done manually but it is a one-off.
On the other hand, that false positive made me think about the impossibility to guarantee a false positive free counter with a two sensor gate: two bees could just stay there for the right amount of time to be in the "likely" range and there will be no way to distinguish it from a real arrival or departure. It shouldn't impact a lot on the big numbers because I suppose it would average to zero between false arrivals and false departures and it will mostly happen when there is "traffic jam", but it is an intrinsic limit of this solution.
That led me think about using 3 or 4 sensors (inline) per gate: it should resolve this problem and probably, by using 4, it will also be able to differentiate:
It is possible that (2) could be exposed to a false positive in case two bees exits one after the other; hopefully in the majority of cases there will be a space between the two bees big enough to trigger an empty state in one of the inner sensors (at 10cm/s, 10ms is 1mm).
Unfortunately adding more sensors requires a new design and fabrication, so I looked around and it seems that nobody implemented it in that way. I don't know if @hydronics2 had any experience with that or if adding more sensors per gate simply increases complexity and cost without giving any major benefits.
Beautiful analysis !!!!
A possible way to have some reasonable value about that threshold is use piece of transparent tube as gate and record a video on top of it with a millimeter band next or under. The visual assessment of the speed has to be done manually but it is a one-off.
To check the speed I built a gate with the millimeter band, the videos can be found on: https://github.com/rodece58/contavoli/tree/main/bee_transit
That led me think about using 3 or 4 sensors (inline) per gate: it should resolve this problem and probably, by using 4, it will also be able to differentiate:
If you want I built a gate prototype with 4 sensors, see video, I could connect the first two on port 1, as originally, and the second pair on port 2 of the bee_counter. If you can make two sketch 1: with 3 sensors 2: with 4 sensors, I could then test it on the hive; I also inserted a plexiglass to make the video from above the gate. Tell me if I can start the modify and test in the lab.
Thanks for the videos, I'll calculate bee's speed during this weekend. It will take me a while but at least we will have some real data about bee's speed.
A thing I noticed by having a quick look at them is that a longer tunnel increases the chance two bees enter in different directions and one "wins" by pushing the other back :-)
By the way, I don't know if it's something that is depending on my VLC or other, but all the videos you uploaded start only with audio, then the video appears after 7-8s.
If you want I built a gate prototype with 4 sensors [...]
That would be really nice to try out!
About the 4 sensor prototype, if you are able to connect those sensors to gate 0 and 1, we can read all 4 and it will cover the 3 sensor variant (by simply ignoring one of the outermost). In case you are soldering the new sensors in parallel with the old ones, it will probably be useful to close the "original" gate 0 and 1 with black tape to avoid having those sensors doing some spurious read.
If I got it right the mapping will be something like this, please let me know if it's different:
inner -> inner gate 0 inner-center -> outer gate 0 outer-center -> inner gate 1 outer -> outer gate 1
This is the modified gist that reads from gate 0 and 1: https://gist.github.com/svavassori/7fc9af576663dc35193071d04cc8e4cf
Can you please measure the length of the 4 sensors? This is to double-check the queen case and if two bees can trigger it.
@svavassori really nice analysis. I went down a similar rabbit holes (design thinking) about the bee counter. You've done a great job articulating the design thinking. @rodece thanks for providing all the data and work!
Uneven Bees count IN vs OUT
Bee Speed Through The Gates
Size of gates
More sensors in the gates
@svavassori / @rodece it was great to hear you work through some of the problems/fixes/prototyping I was working on over the years. great job!
@svavassori ; tested the prototype with 4 sensors, the videos and logs can be found on: https://github.com/rodece58/contavoli/tree/main/log_4sens_13_07
By the way, I don't know if it's something that is depending on my VLC or other, but all the videos you uploaded start only with audio, then the video appears after 7-8s.
I had used VLC for the conversion and saw that it was losing the first few seconds of the video, now I have used another converter and it works.
Can you please measure the length of the 4 sensors?
The distance between the sensors is 5 mm. The size of the gate are 8 x 8 mm.
If I got it right the mapping will be something like this, please let me know if it's different:
I confirm that the sequence is correct
@hydronics2 it's a pleasure to help you and thanks for your beautiful open source work.
I'm sorry for all these days of silence but the analysis took me more time than expected.
@hydronics2 it's nice to hear you again!
The distance between the sensors is 5 mm. The size of the gate are 8 x 8 mm.
Actually I was referring to the whole length of the 4-sensor row. :-)
About the analysis, first I mangled a little the video (crop, rotate, enlarge and extract frames) in order to read more easily the different positions for each bees and I collect a total of 58 sequences with various length. I used 1mm granularity in order to avoid some parallax problem and I checked that the speed over 2 frames matched the sum of the single frames. For a video at 30 fps, 1 mm/frame is equivalent to 3 cm/s. This is the normalized frequency chart of bees' speed:
As it can be seen, the top speed is about 12 cm/s but it cannot be sustained through all the length of the gate, so it cannot be used as maximum average speed.
My initial idea was to integrate the speed for each bee to find the space as a function of time and then invert that function to calculate how much time would have been needed to traverse a gate of a given size according to the possible initial positions. However, since some bees stopped or walked back a little in some frames, it means the relation t → s(t) is not invertible, so I wrote a small program to calculate for each gate size (parameterized) the time needed to traverse it using the given sequence of speeds. The size of the gates I used varied from 17 to 24 mm with a increment of 1 mm, this is to simulate the length of a bee (12-15 mm) plus the length of the real gate (5-9 mm). Then, since we are interested in the minimum time, I took the lowest time for each gate size across all bees and these are the results:
<!DOCTYPE html>
gate [mm] | Time [frames] | avg. speed [mm/frame] | avg. speed [cm/s] -- | -- | -- | -- 17 | 6 | 2.83 | 8.50 18 | 7 | 2.57 | 7.71 19 | 7 | 2.71 | 8.14 20 | 8 | 2.50 | 7.50 21 | 8 | 2.63 | 7.88 22 | 9 | 2.44 | 7.33 23 | 9 | 2.56 | 7.67 24 | 9 | 2.67 | 8.00According to these data, it seems that in the best case (small bee and small gate) the minimum time to pass through the gate is 200 ms, but looking at the frequency chart I find a little odd that 100 and 150 ms are false positive and 200ms are good since they have the same frequency.
In addition I had a look at the new 4-sensors gate data to see if that would make sense and I found this sequence that shouldn't happen: inner sensors are occupied without having passed through outer sensors.
17317,00,00
17327,00,00
17337,00,00
17348,01,10
17358,00,00
17368,00,00
17378,01,00
17389,00,00
17399,00,00
At first I thought of a possible light leak from the other sensors of the board, but as it can be seen here, the board doesn't have any sensor attached to it, so they cannot leak.
That made me think that maybe the @hydronics2 schema is correct from the receiver point of view, but not for the emitter+receiver system. With that I mean that since each sensor is composed by the emitter and the receiver, the IR light reflection point should be in the middle of the two, and under normal condition, it doesn't leak in the other receiver, so it could be that the actual sensing area is smaller than I though.
For this reason, in order to estimate the actual sensing area of the 2-sensor and 4-sensor gate and to shed some light on the possible causes of that strange behavior, I would ask if @rodece could you do this test (it doesn't need the hive):
With this we can control what is happening at each moment when a bee is entering and hopefully understand better what is going on.
Great analysis again !!! :-)
Actually I was referring to the whole length of the 4-sensor row. :-)
The measurement between the beginning of the first sensor and the end of the last is 16 mm.
I made the tests you requested, the results on: https://github.com/rodece58/contavoli/tree/main/log_test_18_07
The activation distance of the first sensor is 1 mm. I also did the test with two bees spaced 1 mm . I also logged in for the quick pass. for 1 and 2 bees. Check if it's okay in case I do the test again.
Thanks for the quick response and videos!
Unfortunately the last one with the millimeter band is too low resolution (202x360) to be able to read it, nonetheless the relative logged data proved that the band is reflecting IR light and the sensors' output sequence is expected one: 0000 > 0001 > 0011 > 0111 > 1111 > 0111 > 0011 > 0001 > 0000
About the bees' logged data, they are exactly the same file and it seems they refer to the first one (1 bee "slow"), maybe it has been a copy/paste problem from output of the serial port. Nonetheless it has been useful to find out that the two gates aren't working the same way. As a matter of fact this is the strange thing in the sequence (with only interesting changes):
184904,00,00
184914,10,00
185081,11,00
185235,11,10
185246,01,10
185370,00,10 <-- This is strange, I would have expected 0111 or 0011
185402,00,11
185507,00,01
185600,00,00
I observed that also in the some previous captures, so it isn't by chance, and it is kind of problematic because if the bee can trigger up to 3 sensors, it should always trigger two, unless they are spaced unevenly. This makes me think that the leftmost sensor could be oriented slightly different from the others (looking outward).
The aim of the test is to understand at which distance each sensor is triggered (1 or 0), so the timing is of second importance. The following diagram should help to better explain the setup:
The millimeter paper should be put under the device and aligned with the gate and the moving strip to minimize errors when reading the distance. Once the bee is at the gate entrance, so before the first sensor is triggered, you can mark on the mm paper that point as reference for zero distance and then, with a 1 mm step (or less if possible) push the strip inside the gate and mark each time there is a change in the sensors (0000 > 0001 > 0011 > 0111 > 0110
... etc).
The result of the test should be a table like this:
<!DOCTYPE HTML>
Distance [mm] | Sensors’ output -- | -- 0 | 0000 1 | 0001 … | 0011 … | 0111 … | 0110 … | 1110 … | 1100 … | 1000 … | 0000With that table and knowing the length of the bee and the sensors' length, it possible to understand the actual sensing area of the sensors.
Extra points if you want also to repeat the test with a 1 mm thick white strip (like the one at the bottom of the image) instead of the bee to increase the resolution :-)
Unfortunately the last one with the millimeter band is too low resolution (202x360).
I've seen it too, unfortunately github only accepts files no larger than 20 Mb, so I had to convert them with youtube.
This makes me think that the leftmost sensor could be oriented slightly different from the others (looking outward). I have checked the sensor and it seems to me mounted correctly.
I did the tests you requested and these are the results:
with 15 mm long bee
Distance [mm] | Sensors’ output |
---|---|
0 | 0000 |
1 | 0001 |
5 | 0011 |
10 | 0111 |
11 | 0110 |
14 | 1110 |
16 | 1100 |
21 | 1000 |
25 | 0000 |
First of all I'd like to thank you to put freely available the design of the board and the code to run it.
Looking at the Arduino code I saw that your counter is based on time threshold (200 ms and 600-650 ms) to avoid some bouncing in the reading.
This gave me the idea to try to detect the entering or the exiting pattern in a way that is robust with respect to the bouncing of a single sensor of the gate at a time. This gist ( https://gist.github.com/svavassori/431e78c2d9f1ff55adb63623408eb033 ) implements a state machine that detects the entering or exiting of a bee for a gate, the extension to multiple gate can be easily done be extending the
State current[]
array to the desired size.Unfortunately I have no access to a beehive until some months, so I was wondering about these two possibilities:
Regards, SV