Skip to content

Commit 438bf68

Browse files
committed
docs(touch_digit): add touch principle
1 parent ef7e353 commit 438bf68

File tree

5 files changed

+65
-9
lines changed

5 files changed

+65
-9
lines changed

docs/_static/ai/touch_kit_pad.png

4.01 MB
Loading

docs/en/ai/touch_digit_recognition.rst

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,35 @@ Touch Principle and Data Acquisition
99
Touch Principle
1010
^^^^^^^^^^^^^^^^^^
1111

12+
The `ESP_Touch_Kit_Touchpad <https://dl.espressif.com/dl/schematics/SCH_ESP-Touch-Kit-Touchpad_V1.0_20210406.pdf>`_ is used as the touch pad. This touchpad consists of a 6*7 array of touch channels.
13+
14+
.. figure:: ../../_static/ai/touch_kit_pad.png
15+
:align: center
16+
17+
Physical Touch Pad
18+
19+
When a finger moves across the touch pad, it changes the capacitance values of the touch channels, allowing us to detect the finger position by monitoring these capacitance changes.
20+
21+
Detection Algorithm
22+
^^^^^^^^^^^^^^^^^^^^
23+
24+
1. Due to hardware variations, each channel has different maximum and minimum trigger values. Therefore, the capacitance values need to be normalized. This is done by recording the maximum and minimum values as the finger slides across the pad.
25+
26+
2. During finger movement, one channel will show the highest rate of capacitance change. By identifying this channel and its adjacent channel with the next highest change rate, we can locate two neighboring channels.
27+
28+
3. Using a ratio-based calculation between these two channels' values, we can determine the relative coordinate of the finger along that direction (the offset from the center point between the two channels).
29+
30+
.. math::
31+
32+
x = \frac{Fa - Fb}{Fa + Fb}
33+
34+
4. By applying the above steps, we can obtain relative coordinates in both directions, thus determining the finger's position.
35+
36+
.. note::
37+
38+
An appropriate trigger threshold needs to be set to determine whether the finger is moving on the touch pad.
39+
40+
5. When finger lift-off is detected, the drawn data can be saved.
1241

1342
Data Collection
1443
^^^^^^^^^^^^^^^^^^^
@@ -284,7 +313,7 @@ To facilitate model debugging, ESP-DL provides the functionality to add test dat
284313
.. code-block:: bash
285314
286315
test outputs value:
287-
%23, shape: [1, 10], exponents: [0],
316+
%23, shape: [1, 10], exponents: [0],
288317
value: array([9.85415445e-34, 1.92874989e-22, 7.46892081e-43, 1.60381094e-28,
289318
3.22134028e-27, 1.05306175e-20, 4.07960022e-41, 1.42516404e-21,
290319
2.38026637e-26, 1.00000000e+00, 0.00000000e+00, 0.00000000e+00],

docs/zh_CN/ai/touch_digit_recognition.rst

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,35 @@ Touch 原理与数据采集
99
Touch 原理
1010
^^^^^^^^^^^^^
1111

12+
采用 `ESP_Touch_Kit_Touchpad <https://dl.espressif.com/dl/schematics/SCH_ESP-Touch-Kit-Touchpad_V1.0_20210406.pdf>`_ 作为 Touch 触摸板。该触摸板有 6*7 的 Touch 通道组成。
13+
14+
.. figure:: ../../_static/ai/touch_kit_pad.png
15+
:align: center
16+
17+
Touch 触控板实物图
18+
19+
当手指在 Touch 触摸板上移动时,会改变 Touch 通道的电容值,这时候我们就可以通过检测电容值的变化来判断手指的位置。
20+
21+
检测算法
22+
^^^^^^^^^^^^
23+
24+
1. 因为硬件差异,各个通道触发的最大值和最小值不同,所以需要对各个通道的电容值进行归一化处理。通过手指在上面滑动,来记录各个通道的最大值和最小值。
25+
26+
2. 在手指滑动的过程中,会有一路通道的电容值变化率最大,这时候再取相邻变化率最大的通道,可以获取到两条相邻的通道。
27+
28+
3. 将两个通道的值进行差比和运算,可以获取到手指在该方向上的相对坐标(较两通道中心点的偏移量)。
29+
30+
.. math::
31+
32+
x = \frac{Fa - Fb}{Fa + Fb}
33+
34+
4. 通过上述步骤,可以获取到手指在两个方向上的相对坐标,从而可以确定手指的位置。
35+
36+
.. note::
37+
38+
需要设定合适的触发阈值,来判断手指是否在 Touch 触摸板上移动。
39+
40+
5. 当检测到手指抬起,即可将绘制的数据进行保存。
1241

1342
数据采集
1443
^^^^^^^^^^^^
@@ -284,7 +313,7 @@ ESP-PPQ 环境配置
284313
.. code-block:: bash
285314
286315
test outputs value:
287-
%23, shape: [1, 10], exponents: [0],
316+
%23, shape: [1, 10], exponents: [0],
288317
value: array([9.85415445e-34, 1.92874989e-22, 7.46892081e-43, 1.60381094e-28,
289318
3.22134028e-27, 1.05306175e-20, 4.07960022e-41, 1.42516404e-21,
290319
2.38026637e-26, 1.00000000e+00, 0.00000000e+00, 0.00000000e+00],

examples/ai/esp_dl/touchpad_digit_recognition/main/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ extern "C" void app_main(void)
3333
ret = nvs_flash_init();
3434
}
3535
ESP_ERROR_CHECK(ret);
36-
/* Initialize button */
3736

37+
/* Initialize button */
3838
const button_config_t btn_cfg = {};
3939
const button_gpio_config_t btn_gpio_cfg = {
4040
.gpio_num = 0,

examples/ai/esp_dl/touchpad_digit_recognition/main/touch_digit.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,8 @@
2626

2727
static const char *TAG = "touch_digit";
2828

29+
#define REALLY_DATA_PRINT 0 // If you need to collect data using the host computer, please set this macro to true
2930
#define SCAN_TIME_MEASURE 0
30-
#define REALLY_DATA_PRINT 0
31-
#define TOUCH_DIGIT_DATA_PRINT 1
32-
#define NORMALIZE_DATA_PRINT 1
3331

3432
#define CHANNEL_NUM 13
3533
#define CHANNEL_LIST {1,2,3,4,5,6,7,8,9,10,11,12,13}
@@ -213,7 +211,7 @@ static void touch_digit_task(void *arg)
213211
}
214212
}
215213
printf("\n");
216-
#endif
214+
#else
217215

218216
#if SCAN_TIME_MEASURE
219217
uint32_t now_time = esp_timer_get_time();
@@ -247,7 +245,6 @@ static void touch_digit_task(void *arg)
247245
break;
248246
case END_WRITE:
249247
// send data to dl inference
250-
251248
g_image.print();
252249
image_data_t image_data;
253250
image_data.size = g_image.col_length * g_image.row_length;
@@ -263,6 +260,7 @@ static void touch_digit_task(void *arg)
263260
default:
264261
break;
265262
}
263+
#endif
266264
}
267265
}
268266
}
@@ -287,7 +285,7 @@ void touch_digit_recognition_task(void *arg)
287285

288286
while (1) {
289287
if (xQueueReceive(xImageQueue, &image_data, portMAX_DELAY) == pdTRUE) {
290-
// printf("Result:%d\n", touch_digit_recognition->predict(image_data.data));
288+
printf("Result:%d\n", touch_digit_recognition->predict(image_data.data));
291289
digital_tube_write_num(0, touch_digit_recognition->predict(image_data.data));
292290
delete [] image_data.data;
293291
}

0 commit comments

Comments
 (0)