From db022db0c2191a15c07055b81899e9a06f8e1928 Mon Sep 17 00:00:00 2001 From: YunHorn Technology Date: Tue, 13 Aug 2024 15:39:16 +0800 Subject: [PATCH] --- motion fall detection factor 3 added --- Core/Src/yunhorn_sts_presence_rss.c | 23 ++++++++++++----------- Core/Src/yunhorn_sts_process.c | 7 ++++--- LoRaWAN/App/lora_app.c | 5 +++-- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/Core/Src/yunhorn_sts_presence_rss.c b/Core/Src/yunhorn_sts_presence_rss.c index 1c2bfea..3cc244d 100644 --- a/Core/Src/yunhorn_sts_presence_rss.c +++ b/Core/Src/yunhorn_sts_presence_rss.c @@ -133,7 +133,7 @@ volatile uint8_t sts_fall_rising_detected_result = STS_PRESENCE_NORMAL; volatile uint8_t sts_fall_rising_detected_result_changed_flag =0; volatile uint8_t last_sts_fall_rising_detected_result= STS_PRESENCE_NORMAL; volatile float last_average_presence_distance; -volatile uint16_t sts_fall_rising_pattern_factor1=0, sts_fall_rising_pattern_factor2=0; +volatile uint16_t sts_fall_rising_pattern_factor1=0, sts_fall_rising_pattern_factor2=0, sts_fall_rising_pattern_factor3=0; volatile uint16_t sts_roc_acc_standard_variance=0; extern volatile uint8_t sts_presence_fall_detection; /* USER CODE END Includes */ @@ -580,6 +580,7 @@ int sts_presence_rss_fall_rise_detection(void) APP_LOG(TS_OFF, VLEVEL_L,"\r\nSensor at Ceiling Height: %u mm\r\n",(uint16_t)sts_sensor_install_height); APP_LOG(TS_OFF, VLEVEL_L,"\r\n|Motion Distance Zone| ##### |Height cm|\r\n"); uint8_t kk = (uint8_t)(sts_sensor_install_height/400+1); +#if 0 APP_LOG(TS_OFF, VLEVEL_L,"\r\n|-----------Ceiling-------Sensor---V-----|\r\n"); for (uint8_t k=0; k<=kk; k++) { @@ -593,6 +594,7 @@ int sts_presence_rss_fall_rise_detection(void) } } APP_LOG(TS_OFF, VLEVEL_L,"\r\n|-----------Floor Ground-----------^-----|\r\n"); +#endif //#endif average_distance = (1000.0f*average_distance)/average_result; // in meters average_score = (1000.0f*average_score)/average_result; @@ -641,6 +643,11 @@ void STS_YunhornCheckStandardDeviation(void) uint32_t roc_acc[DEFAULT_MOTION_DATASET_LEN]={0}, sum_roc_acc=0.0f, average_roc_acc=0.0f, variance_roc_acc=0.0f, standard_variance_roc_acc=0.0f;; //act as speed of change at given time slot acc_integration_sleep_ms(1000 / DEFAULT_UPDATE_RATE_PRESENCE); uint8_t SAMPLE_DATASET_NUM = MIN(motion_count,DEFAULT_MOTION_DATASET_LEN ); + APP_LOG(TS_OFF, VLEVEL_M, "\r\n Sample dataset for deviation process =%u \r\n",SAMPLE_DATASET_NUM); + + // initial state + sts_fall_rising_detected_result = STS_PRESENCE_NORMAL; + //SUM of samples for(i= 0; i< SAMPLE_DATASET_NUM; i++) { @@ -735,8 +742,10 @@ void STS_YunhornCheckStandardDeviation(void) //sts_fall_rising_pattern_factor1 = (int)(standard_variance_roc_distance); sts_fall_rising_pattern_factor1 = (int)(average_roc_distance); sts_fall_rising_pattern_factor2 = (int)(fabs(average_presence_distance - last_average_presence_distance)); + sts_fall_rising_pattern_factor3 = (int)(standard_variance_presence_score); APP_LOG(TS_OFF, VLEVEL_L,"\r\nAvg-Dist =%6u, Last_AVG-Dist =%6u \r\n", (int)(average_presence_distance), (int)(last_average_presence_distance)); + APP_LOG(TS_OFF, VLEVEL_L,"\r\nStandard Variance Presence_score=%u \r\n", (int)(standard_variance_presence_score)); APP_LOG(TS_OFF, VLEVEL_M, "\r\nThreshold 1: Acc = %6u ---- Measure 1 = %6u ---- \r\n", (int)(sts_fall_detection_acc_threshold), (int)(sts_fall_rising_pattern_factor1/10)); @@ -752,8 +761,6 @@ void STS_YunhornCheckStandardDeviation(void) { sts_fall_rising_detected_result = STS_PRESENCE_STAYSTILL; //sts_fall_rising_detected_result = STS_PRESENCE_NO_MOVEMENT; - } else { - sts_fall_rising_detected_result = STS_PRESENCE_NORMAL; } // @@ -815,21 +822,15 @@ void STS_YunhornCheckStandardDeviation(void) } last_sts_fall_rising_detected_result = sts_fall_rising_detected_result; + } else if ((average_presence_distance + sts_motion_feature[motion_feature_count].p_dist_standard) > last_average_presence_distance) { sts_fall_rising_detected_result = STS_PRESENCE_LAYDOWN; - } else { - sts_fall_rising_detected_result = STS_PRESENCE_NORMAL; } } last_sts_fall_rising_detected_result = sts_fall_rising_detected_result; last_average_presence_distance = average_presence_distance; -#if 0 - if (sts_fall_rising_detected_result != STS_PRESENCE_NORMAL) - { - STS_FallDetection_LampBarProcess(); - } -#endif + } diff --git a/Core/Src/yunhorn_sts_process.c b/Core/Src/yunhorn_sts_process.c index aef4e23..0c589d0 100644 --- a/Core/Src/yunhorn_sts_process.c +++ b/Core/Src/yunhorn_sts_process.c @@ -240,7 +240,7 @@ void STS_YunhornSTSEventP1_Process(void) sts_reed_hall_2_result = HALL2_STATE;// sts_hall2_read; if (sts_reed_hall_2_result != last_sts_reed_hall_2_result) { - sts_reed_hall_changed_flag = TRUE; + sts_reed_hall_changed_flag |= TRUE; } last_sts_reed_hall_2_result = sts_reed_hall_2_result; @@ -270,11 +270,12 @@ void STS_YunhornSTSEventP2_Process(void) sts_presence_rss_fall_rise_detection(); sts_rss_result_changed_flag = (sts_rss_result == last_sts_rss_result)? 0:1; - APP_LOG(TS_OFF, VLEVEL_M, "\r\n STS_RSS RESULT CHANGED FLAG=%u \r\n",sts_rss_result_changed_flag ); + APP_LOG(TS_OFF, VLEVEL_M, "\r\n STS_RSS Motion Detection changed flag=%u \r\n",sts_rss_result_changed_flag ); last_sts_rss_result = sts_rss_result; //sts_fall_rising_detected_result_changed_flag = (sts_fall_rising_detected_result == last_sts_fall_rising_detected_result)?0:1; - sts_fall_rising_detected_result_changed_flag = (sts_fall_rising_detected_result != 0)?1:0; + sts_fall_rising_detected_result_changed_flag = (sts_fall_rising_detected_result != last_sts_fall_rising_detected_result)?1:0; + APP_LOG(TS_OFF, VLEVEL_M, "\r\n STS_RSS Fall Detection changed flag FLAG=%u \r\n",sts_fall_rising_detected_result_changed_flag ); last_sts_fall_rising_detected_result = sts_fall_rising_detected_result; diff --git a/LoRaWAN/App/lora_app.c b/LoRaWAN/App/lora_app.c index 1f62fa5..31e7428 100644 --- a/LoRaWAN/App/lora_app.c +++ b/LoRaWAN/App/lora_app.c @@ -70,7 +70,7 @@ volatile uint8_t sts_unconscious_or_motionless_level_threshold=6; //6*128 volatile uint8_t sts_motionless_duration_threshold_in_min=1; // test mode, 1 min, normal 10 min. long occupation 30 min volatile uint16_t sts_unconscious_level_threshold=600; volatile uint8_t sts_alarm_mute_reset_timer_in_10sec=6; -extern volatile uint8_t sts_fall_rising_detected_result; +extern volatile uint8_t sts_fall_rising_detected_result, sts_fall_rising_detected_result_changed_flag; extern volatile uint32_t event_start_time, event_stop_time; extern volatile uint16_t sts_unconscious_threshold; volatile uint8_t sts_occupancy_overtime_state = 0; @@ -1709,9 +1709,10 @@ static void OnYunhornSTSOORSSWakeUpTimerEvent(void *context) { UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_YunhornSTSEventP2), CFG_SEQ_Prio_0); APP_LOG(TS_OFF,VLEVEL_M,"\r\n Wakeup Timer ======== RSS result changed flag=%d \r\n", sts_rss_result_changed_flag); - if ((STS_LoRa_WAN_Joined != 0)&&(sts_rss_result_changed_flag==1)) + if ((sts_rss_result_changed_flag == 1) || (sts_fall_rising_detected_result_changed_flag == 1)) { sts_rss_result_changed_flag = 0; + sts_fall_rising_detected_result_changed_flag = 0; APP_LOG(TS_OFF,VLEVEL_M,"\r\n Wakeup Timer ======== Send Tx Result\r\n"); SendTxData(); //UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_LoRaSendOnTxTimerOrButtonEvent), CFG_SEQ_Prio_0);