|
1 | 1 | # RooDe
|
| 2 | + |
2 | 3 | People counter working with any smart home system which supports ESPHome and therefore Home Assistamt. All necessary entities are created automatically.
|
3 | 4 |
|
4 | 5 |
|
5 | 6 | [](https://discord.gg/RK3KJeSy)
|
6 | 7 |
|
7 | 8 |
|
| 9 | + |
| 10 | + |
| 11 | +## Algorithm |
| 12 | +The implemented Algorithm is an improved version of my own implementation which checks the direction of a movement through two defined zones. ST implemented a nice and efficient way to track the path from one to the other direction. I migrated the algorigthm with some changes into the Roode project. |
| 13 | +The concept of path tracking is the detecion of a human: |
| 14 | +* In the first zone only |
| 15 | +* In both zones |
| 16 | +* In the second zone only |
| 17 | +* In no zone |
| 18 | + |
| 19 | +That way we can ensure the direction of movement. |
| 20 | + |
| 21 | +The sensor creates a 16x16 grid and the final distance is computed by taking the average of the distance of the values of the grid. |
| 22 | +We are defining two different Region of Interest (ROI) inside this grid. Then the sensor will measure the two distances in the two zones and will detect any presence and tracks the path to receive the direction. |
| 23 | + |
| 24 | +However, the algorithm is very sensitive to the slightest modification of the ROI, regarding both its size and its positioning inside the grid. |
| 25 | + |
| 26 | +ST Microelectronics define the values for the parameters as default like this: |
| 27 | +- `ROI_width = 8 //min 4` |
| 28 | +- `ROI_height = 16 //min 4` |
| 29 | +- `center = {167,231}` |
| 30 | + |
| 31 | +The center of the ROI you set is based on the table below and the optical center has to be set as the pad above and to the right of your exact center: |
| 32 | + |
| 33 | + |
| 34 | + |
| 35 | +| 128 | 136 | 144 | 152 | 160 | 168 | 176 | 184 | 192 | 200 | 208 | 216 | 224 | 232 | 240 | 248 | |
| 36 | +| ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | |
| 37 | +| 129 | 137 | 145 | 153 | 161 | 169 | 177 | 185 | 193 | 201 | 209 | 217 | 225 | 233 | 241 | 249 | |
| 38 | +| 130 | 138 | 146 | 154 | 162 | 170 | 178 | 186 | 194 | 202 | 210 | 218 | 226 | 234 | 242 | 250 | |
| 39 | +| 131 | 139 | 146 | 155 | 163 | 171 | 179 | 187 | 195 | 203 | 211 | 219 | 227 | 235 | 243 | 251 | |
| 40 | +| 132 | 140 | 147 | 156 | 164 | 172 | 180 | 188 | 196 | 204 | 212 | 220 | 228 | 236 | 244 | 252 | |
| 41 | +| 133 | 141 | 148 | 157 | 165 | 173 | 181 | 189 | 197 | 205 | 213 | 221 | 229 | 237 | 245 | 253 | |
| 42 | +| 134 | 142 | 149 | 158 | 166 | 174 | 182 | 190 | 198 | 206 | 214 | 222 | 230 | 238 | 246 | 254 | |
| 43 | +| 135 | 143 | 150 | 159 | 167 | 175 | 183 | 191 | 199 | 207 | 215 | 223 | 231 | 239 | 247 | 255 | |
| 44 | +| 127 | 119 | 111 | 103 | 95 | 87 | 79 | 71 | 63 | 55 | 47 | 39 | 31 | 23 | 15 | 7 | |
| 45 | +| 126 | 118 | 110 | 102 | 94 | 86 | 78 | 70 | 62 | 54 | 46 | 38 | 30 | 22 | 14 | 6 | |
| 46 | +| 125 | 117 | 109 | 101 | 93 | 85 | 77 | 69 | 61 | 53 | 45 | 37 | 29 | 21 | 13 | 5 | |
| 47 | +| 124 | 116 | 108 | 100 | 92 | 84 | 76 | 68 | 60 | 52 | 44 | 36 | 28 | 20 | 12 | 4 | |
| 48 | +| 123 | 115 | 107 | 99 | 91 | 83 | 75 | 67 | 59 | 51 | 43 | 35 | 27 | 19 | 11 | 3 | |
| 49 | +| 122 | 114 | 106 | 98 | 90 | 82 | 74 | 66 | 58 | 50 | 42 | 34 | 26 | 18 | 10 | 2 | |
| 50 | +| 121 | 113 | 105 | 97 | 89 | 81 | 73 | 65 | 57 | 49 | 41 | 33 | 25 | 17 | 9 | 1 | |
| 51 | +| 120 | 112 | 104 | 96 | 88 | 80 | 72 | 64 | 56 | 48 | 40 | 32 | 24 | 16 | 8 | 0 | |
| 52 | + |
| 53 | + |
| 54 | + |
| 55 | + |
| 56 | + |
| 57 | +#### Threshold distance |
| 58 | + |
| 59 | +Another crucial choice is the one corresponding to the threshold. Indeed a movement is detected whenever the distance read by the sensor is below this value. The code contains a vector as threshold, as one (as myself) might need a different threshold for each zone. |
| 60 | + |
| 61 | +The SparkFun library also supports more formats for the threshold: for example one can set that a movement is detected whenever the distance is between two values. However, more information for the interested reader can be found on the corresponding page. |
| 62 | + |
| 63 | +With the updated code (however only for esp32 at the moment) the threshold is automatically calculated by the sensor. To do so it is necessary to position the sensor and, after turning it on, wait for 10 seconds without passing under it. After this time, the average of the measures for each zone will be computed and the thereshold for each ROI will correspond to 80% of the average value. Also the value of 80% can be modified in the code, by editing the variable `threshold_percentage` |
| 64 | + |
| 65 | +The calibration of the threshold can also be triggered by a MQTT message. An example for doing so is in the file `integration_with_home_assistant.md`. |
| 66 | + |
| 67 | + |
| 68 | + |
| 69 | +## Useful links |
| 70 | + |
| 71 | +[SparkFun library guide](https://learn.sparkfun.com/tutorials/qwiic-distance-sensor-vl53l1x-hookup-guide/all) with more information about the functions used in the code |
8 | 72 |
|
9 | 73 | ## Hardware
|
10 | 74 | There will be a specific Hardware setup (recommended brands etc.) soon!
|
11 |
| -* ESP8266 or ESP32 |
12 |
| -* 1x VL53L1X |
| 75 | +* ESP8266 or ESP32 (Wemos D1 mini case will be available) |
| 76 | +* 1x VL53L1X (GY-53 and cheap chinese sensors) |
13 | 77 | * Optional HC-SR501
|
14 | 78 | * Optional 128x32 OLED
|
15 | 79 | * Power Supply
|
16 | 80 | * Encolsure (see .stl files) - will be updated soon!
|
| 81 | +Pins: |
| 82 | +#define SDA_PIN D2 |
| 83 | +#define SCL_PIN D1 |
| 84 | + |
| 85 | +## Configuration |
| 86 | +### ESPHome |
| 87 | +Configue at least the secrets.yaml with your wifi SSID and password to connect. Check the peopleCounter.yaml to adapt the exposed sensors to your needs. |
| 88 | + |
| 89 | +### Entry/Exit inverted: |
| 90 | +Set #define INVERT_DIRECTION or comment it out to invert the direction. |
| 91 | + |
17 | 92 |
|
18 | 93 | ## Configuration
|
19 | 94 | Be sure to configure your wifi credentials and adapt the Config.h to set everyhting to your needs.
|
@@ -65,4 +140,4 @@ Calibration v2 calibrates both zones individually (thanks to @andrea-fox).
|
65 | 140 | * CALIBRATION_VAL to 4000
|
66 | 141 | ### Changelog v.0.9.4-release
|
67 | 142 | * Added standard deviation threhsold calculation
|
68 |
| -* Removed constant THRESHOLD_X |
| 143 | +* Removed constant THRESHOLD_X |
0 commit comments