### good ### keep this ---20240809 16pm

This commit is contained in:
Yunhorn 2024-08-09 16:33:22 +08:00
parent ae712e0eca
commit 3fde971aeb
4 changed files with 67 additions and 60 deletions

View File

@ -55,7 +55,7 @@
//volatile distance_measure_cfg_t distance_cfg={1.5, 2.0, 1, 63, 2, 10, 0.5, 1.3, 0.2}; //volatile distance_measure_cfg_t distance_cfg={1.5, 2.0, 1, 63, 2, 10, 0.5, 1.3, 0.2};
// SPARK FUN EXAMPLE // SPARK FUN EXAMPLE
// GOOD --- volatile distance_measure_cfg_t distance_cfg={0.4, 3.5, 4, 63, 0, 10, 0.5, 1.3, 0.2}; // GOOD --- volatile distance_measure_cfg_t distance_cfg={0.4, 3.5, 4, 63, 0, 10, 0.5, 1.3, 0.2};
volatile distance_measure_cfg_t distance_cfg={0.8, 3.5, 4, 63, 2, 10, 0.5, 1.3, 0.2}; volatile distance_measure_cfg_t distance_cfg={0.8, 3.5, 2, 63, 2, 10, 0.5, 1.3, 0.2};
//volatile distance_measure_cfg_t distance_cfg={1.5, 3.3, 2, 63, 4, 10, 0.8182f, 0.4, 0.2}; //volatile distance_measure_cfg_t distance_cfg={1.5, 3.3, 2, 63, 4, 10, 0.8182f, 0.4, 0.2};
extern volatile uint16_t sts_distance_rss_distance, sts_sensor_install_height; extern volatile uint16_t sts_distance_rss_distance, sts_sensor_install_height;

View File

@ -123,8 +123,8 @@ volatile uint8_t detected_hs_zone=0;;
volatile uint16_t motion_count=0, motion_feature_count=0; volatile uint16_t motion_count=0, motion_feature_count=0;
typedef struct typedef struct
{ {
uint32_t presence_score; // 1000* uint16_t presence_score; // 1000*
uint32_t presence_distance; // 1000*, in mm uint16_t presence_distance; // 1000*, in mm
} STS_presence_result_t; } STS_presence_result_t;
static STS_presence_result_t sts_motion_dataset[DEFAULT_MOTION_DATASET_LEN]; static STS_presence_result_t sts_motion_dataset[DEFAULT_MOTION_DATASET_LEN];
@ -309,7 +309,7 @@ static void print_result(acc_detector_presence_result_t result)
//uint32_t detected_zone = (uint32_t)((float)(result.presence_distance - DEFAULT_START_M) / (float)DEFAULT_ZONE_LENGTH); //uint32_t detected_zone = (uint32_t)((float)(result.presence_distance - DEFAULT_START_M) / (float)DEFAULT_ZONE_LENGTH);
// 2024-08-05 // 2024-08-05
uint32_t detected_zone = (uint32_t)((float)(result.presence_distance) / (float)DEFAULT_ZONE_LENGTH); uint32_t detected_zone = (uint32_t)((float)(result.presence_distance) / (float)DEFAULT_ZONE_LENGTH);
APP_LOG(TS_OFF, VLEVEL_H,"Motion in zone: %u, distance: %d, score: %d\n", (unsigned int)detected_zone, APP_LOG(TS_OFF, VLEVEL_H,"\r\nMotion in zone: %u, distance: %d, score: %d\n", (unsigned int)detected_zone,
(int)(result.presence_distance * 1000.0f), (int)(result.presence_distance * 1000.0f),
(int)(result.presence_score * 1000.0f)); (int)(result.presence_score * 1000.0f));
} }
@ -430,18 +430,13 @@ int sts_presence_rss_fall_rise_detection(void)
//APP_LOG(TS_OFF, VLEVEL_L, "\r\nHS_ZONE=%u", (int)detected_hs_zone); //APP_LOG(TS_OFF, VLEVEL_L, "\r\nHS_ZONE=%u", (int)detected_hs_zone);
detected_hs_zone = 6 - detected_zone; detected_hs_zone = 6 - detected_zone;
motion_in_hs_zone[detected_hs_zone][(motion_detected_count)]++; motion_in_hs_zone[detected_hs_zone][(motion_detected_count)]++;
}
sts_motion_dataset[motion_count].presence_distance = 1000*result.presence_distance;
sts_motion_dataset[motion_count].presence_score = 1000*result.presence_score;
if (sts_presence_fall_detection == TRUE) sts_motion_dataset[motion_count].presence_distance = 1000*result.presence_distance;
{ sts_motion_dataset[motion_count].presence_score = 1000*result.presence_score;
if (motion_count ++ == DEFAULT_MOTION_DATASET_LEN)
{ motion_count++;
// STS_YunhornCheckStandardDeviation(); no Deviation in middle 2024 -7-22
motion_count = 0;
}
} }
} }
@ -506,21 +501,13 @@ int sts_presence_rss_fall_rise_detection(void)
detected_hs_zone = 6 - detected_zone; detected_hs_zone = 6 - detected_zone;
motion_in_hs_zone[detected_hs_zone][(motion_detected_count)]++; motion_in_hs_zone[detected_hs_zone][(motion_detected_count)]++;
}
if (sts_presence_fall_detection == TRUE)
{
sts_motion_dataset[motion_count].presence_distance = 1000*result.presence_distance; sts_motion_dataset[motion_count].presence_distance = 1000*result.presence_distance;
sts_motion_dataset[motion_count].presence_score = 1000*result.presence_score; sts_motion_dataset[motion_count].presence_score = 1000*result.presence_score;
if (motion_count ++ == DEFAULT_MOTION_DATASET_LEN)
{
STS_YunhornCheckStandardDeviation(); motion_count++;
motion_count = 0;
}
} }
} }
//acc_integration_sleep_ms(1000 / DEFAULT_UPDATE_RATE_PRESENCE); // 15 ms, DEFAULT_UPDATE_RATE); //acc_integration_sleep_ms(1000 / DEFAULT_UPDATE_RATE_PRESENCE); // 15 ms, DEFAULT_UPDATE_RATE);
@ -528,6 +515,11 @@ int sts_presence_rss_fall_rise_detection(void)
} }
//APP_LOG(TS_OFF, VLEVEL_L,"Second Half, Fall Rise Detection, Motion Count = %u \r\n", (int)motion_count); //APP_LOG(TS_OFF, VLEVEL_L,"Second Half, Fall Rise Detection, Motion Count = %u \r\n", (int)motion_count);
motion_count = motion_count%DEFAULT_MOTION_DATASET_LEN; // get all required number of motion data
if (sts_presence_fall_detection == TRUE)
STS_YunhornCheckStandardDeviation();
uint8_t thiscnt= motion_detected_count; uint8_t thiscnt= motion_detected_count;
if (motion_detected_count++ == 10) { if (motion_detected_count++ == 10) {
@ -558,21 +550,28 @@ int sts_presence_rss_fall_rise_detection(void)
} }
#ifndef MAX
#define MAX( a, b ) ( ( ( a ) > ( b ) ) ? ( a ) : ( b ) )
#endif
//#ifdef LOG_RSS //#ifdef LOG_RSS
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");
for (uint8_t k=0; k<12; k++) {
if (motion_in_hs_zone[k][thiscnt]>0) {
APP_LOG(TS_OFF, VLEVEL_L,"\r\n| %2u | %4u | %4u |\r\n", k, (uint8_t)motion_in_hs_zone[k][thiscnt], (int)(k+1)*40); 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);
APP_LOG(TS_OFF, VLEVEL_L,"\r\n|-----------Ceiling-------Sensor---V-----|\r\n");
for (uint8_t k=0; k<=kk; k++)
{
if (motion_in_hs_zone[kk-k][thiscnt]>0) {
APP_LOG(TS_OFF, VLEVEL_L,"\r\n| %2u | %4u | %4u |\r\n", kk-k, (uint8_t)motion_in_hs_zone[kk-k][thiscnt], (int)(kk-k+1)*40);
} }
else else
{ {
APP_LOG(TS_OFF, VLEVEL_L,"\r\n| %2u | | |\r\n", k); APP_LOG(TS_OFF, VLEVEL_L,"\r\n| %2u | | |\r\n", kk-k);
} }
} }
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_distance = (1000.0f*average_distance)/average_result; // in meters
average_score = (1000.0f*average_score)/average_result; average_score = (1000.0f*average_score)/average_result;
@ -643,7 +642,8 @@ void STS_YunhornCheckStandardDeviation(void)
//STANDARD VARIANCE sigma //STANDARD VARIANCE sigma
standard_variance_presence_distance = (uint32_t)sqrt(variance_presence_distance); standard_variance_presence_distance = (uint32_t)sqrt(variance_presence_distance);
standard_variance_presence_score = (uint32_t)sqrt(variance_presence_score); standard_variance_presence_score = (uint32_t)sqrt(variance_presence_score);
APP_LOG(TS_OFF, VLEVEL_M, "\r\n Standard Variance_Presence_Distance=%u \r\n Standard Variance Presence Score=%u\r\n",
standard_variance_presence_distance, standard_variance_presence_score);
// ROC distance // ROC distance
// SUM // SUM
@ -653,11 +653,11 @@ void STS_YunhornCheckStandardDeviation(void)
sum_roc_distance += ((uint32_t)roc_distance[i]); sum_roc_distance += ((uint32_t)roc_distance[i]);
} }
average_roc_distance = (uint32_t)sum_roc_distance/(float)(DEFAULT_MOTION_DATASET_LEN-1); average_roc_distance = (uint32_t)sum_roc_distance/(DEFAULT_MOTION_DATASET_LEN-1);
for (j = 0; j < (DEFAULT_MOTION_DATASET_LEN-1); j++) for (j = 0; j < (DEFAULT_MOTION_DATASET_LEN-1); j++)
{ {
variance_roc_distance += (uint32_t)(pow((float)roc_distance[j] - (uint32_t)average_roc_distance,2)); variance_roc_distance += (uint32_t)(pow(roc_distance[j] - average_roc_distance,2));
} }
// average // average
variance_roc_distance /= (uint32_t)(DEFAULT_MOTION_DATASET_LEN-1); variance_roc_distance /= (uint32_t)(DEFAULT_MOTION_DATASET_LEN-1);
@ -674,11 +674,11 @@ void STS_YunhornCheckStandardDeviation(void)
sum_roc_acc += ((uint32_t)roc_acc[i]); sum_roc_acc += ((uint32_t)roc_acc[i]);
} }
average_roc_acc = (uint32_t)sum_roc_acc/(float)(DEFAULT_MOTION_DATASET_LEN-2); average_roc_acc = (uint32_t)sum_roc_acc/(DEFAULT_MOTION_DATASET_LEN-2);
for (j = 0; j < (DEFAULT_MOTION_DATASET_LEN-2); j++) for (j = 0; j < (DEFAULT_MOTION_DATASET_LEN-2); j++)
{ {
variance_roc_acc += (uint32_t)pow((uint32_t)((uint32_t)roc_acc[j] - (uint32_t)average_roc_acc),2.0f); variance_roc_acc += (uint32_t)pow((uint32_t)((uint32_t)roc_acc[j] - (uint32_t)average_roc_acc),2);
} }
variance_roc_acc /= (uint32_t)(DEFAULT_MOTION_DATASET_LEN-2); variance_roc_acc /= (uint32_t)(DEFAULT_MOTION_DATASET_LEN-2);
@ -686,7 +686,7 @@ void STS_YunhornCheckStandardDeviation(void)
standard_variance_roc_acc = (uint32_t)sqrt((uint32_t)variance_roc_acc); standard_variance_roc_acc = (uint32_t)sqrt((uint32_t)variance_roc_acc);
//Normallize to m/s --- * DEFAULT_MOTION_DATASET_LEN for One single second //Normallize to m/s --- * DEFAULT_MOTION_DATASET_LEN for One single second
#if 0
average_roc_distance *= (uint32_t)DEFAULT_MOTION_DATASET_LEN; average_roc_distance *= (uint32_t)DEFAULT_MOTION_DATASET_LEN;
variance_roc_distance *= (uint32_t)DEFAULT_MOTION_DATASET_LEN; variance_roc_distance *= (uint32_t)DEFAULT_MOTION_DATASET_LEN;
standard_variance_roc_distance *= (uint32_t)DEFAULT_MOTION_DATASET_LEN; standard_variance_roc_distance *= (uint32_t)DEFAULT_MOTION_DATASET_LEN;
@ -694,32 +694,34 @@ void STS_YunhornCheckStandardDeviation(void)
average_roc_acc *= (uint32_t)DEFAULT_MOTION_DATASET_LEN; average_roc_acc *= (uint32_t)DEFAULT_MOTION_DATASET_LEN;
variance_roc_acc *= (uint32_t)DEFAULT_MOTION_DATASET_LEN; variance_roc_acc *= (uint32_t)DEFAULT_MOTION_DATASET_LEN;
standard_variance_roc_acc *= (uint32_t)DEFAULT_MOTION_DATASET_LEN; standard_variance_roc_acc *= (uint32_t)DEFAULT_MOTION_DATASET_LEN;
#endif
// print result // print result
//#ifdef LOG_RSS //#ifdef LOG_RSS
APP_LOG(TS_OFF, VLEVEL_L, "\r\n---Sensor Install Height=%6u-----Distance Average =%6u; Variance = %6u ; Standard =%6u \r\n", APP_LOG(TS_OFF, VLEVEL_M, "\r\n---Sensor Install Height=%6u-----\r\n-------------Distance Average =%6u; Standard_Variance =%6u \r\n",
(int)sts_sensor_install_height, (int)(average_presence_distance), (int)(variance_presence_distance), (int)(standard_variance_presence_distance)); (int)sts_sensor_install_height, (int)(average_presence_distance), (int)(standard_variance_presence_distance));
//#endif //#endif
//#ifdef LOG_RSS //#ifdef LOG_RSS
APP_LOG(TS_OFF, VLEVEL_M, "\r\n\n-------------Motion Average =%6u; Variance = %6u ; Standard =%6u \r\n", APP_LOG(TS_OFF, VLEVEL_M, "\r\n\n-------------Motion Average =%6u; Standard_Variance =%6u \r\n",
(int)(average_presence_score), (int)(variance_presence_score), (int)(standard_variance_presence_score)); (int)(average_presence_score), (int)(standard_variance_presence_score));
//#endif //#endif
//#ifdef LOG_RSS //#ifdef LOG_RSS
APP_LOG(TS_OFF, VLEVEL_L, "\r\n-------------ROC Dist Average =%6u; Variance = %6u ; Standard =%6u \r\n", APP_LOG(TS_OFF, VLEVEL_M, "\r\n-------------ROC Dist Average =%6u; Standard_Variance =%6u \r\n",
(int)(average_roc_distance), (int)(variance_roc_distance), (int)(standard_variance_roc_distance)); (int)(average_roc_distance), (int)(standard_variance_roc_distance));
APP_LOG(TS_OFF, VLEVEL_L, "\r\n-------------ROC ACC Average =%6u; Variance = %6u ; Standard =%6u \r\n", APP_LOG(TS_OFF, VLEVEL_M, "\r\n-------------ROC ACC Average =%6u; Standard_Variance =%6u \r\n",
(int)(average_roc_acc), (int)(variance_roc_acc), (int)(standard_variance_roc_acc)); (int)(average_roc_acc), (int)(standard_variance_roc_acc));
//sts_fall_rising_pattern_factor1 = (int)(standard_variance_roc_distance);
sts_fall_rising_pattern_factor1 = (int)(average_roc_distance/10);
sts_fall_rising_pattern_factor2 = (int)(fabs(average_presence_distance - last_average_presence_distance));
sts_fall_rising_pattern_factor1 = (int)(standard_variance_roc_distance);
sts_fall_rising_pattern_factor2 = (int)(fabs(average_presence_distance - fmax(0,last_average_presence_distance))*100.0f); // in cm
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\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\nThreshold 1: \r\nAcc = %6u \r\nMeasure 1 = %6u ---- \r\n", 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)); (int)(sts_fall_detection_acc_threshold), (int)(sts_fall_rising_pattern_factor1/10));
APP_LOG(TS_OFF, VLEVEL_L, "\r\nThreshold 2: \r\nDis = %6u cm \r\nMeasure 2 = %6u cm ---- \r\n", APP_LOG(TS_OFF, VLEVEL_M, "\r\nThreshold 2: Dis = %6u cm --- Measure 2 = %6u cm ---- \r\n",
(int)(sts_fall_detection_depth_threshold), (int)(sts_fall_rising_pattern_factor2)); (int)(sts_fall_detection_depth_threshold), (int)(sts_fall_rising_pattern_factor2/10));
//#endif //#endif
// ******************************************* // *******************************************

View File

@ -62,7 +62,7 @@ extern volatile uint8_t sts_lamp_bar_flashing_color;
volatile uint8_t last_sts_lamp_bar_color=STS_DARK; volatile uint8_t last_sts_lamp_bar_color=STS_DARK;
extern volatile uint8_t sts_rss_result; extern volatile uint8_t sts_rss_result;
extern volatile uint8_t sts_rss_result_changed_flag, sts_hall1_changed_flag, sts_hall2_changed_flag, sts_reed_hall_changed_flag; extern volatile uint8_t sts_rss_result_changed_flag, sts_hall1_changed_flag, sts_hall2_changed_flag, sts_reed_hall_changed_flag;
volatile uint8_t sts_fall_detection_acc_threshold = 10, volatile uint8_t sts_fall_detection_acc_threshold = 20,
sts_fall_detection_depth_threshold=20, sts_fall_detection_depth_threshold=20,
sts_fall_confirm_threshold_in_10sec=1, sts_fall_confirm_threshold_in_10sec=1,
sts_occupancy_overtime_threshold_in_10min=2; sts_occupancy_overtime_threshold_in_10min=2;
@ -684,7 +684,7 @@ void LoRaWAN_Init(void)
#endif #endif
#if defined(STS_O7)||defined(STS_O6) #if defined(STS_O7)||defined(STS_O6)
UTIL_TIMER_Create(&YunhornSTSRSSWakeUpTimer, YUNHORN_STS_RSS_WAKEUP_CHECK_TIME, UTIL_TIMER_PERIODIC, OnYunhornSTSOORSSWakeUpTimerEvent, NULL); //UTIL_TIMER_Create(&YunhornSTSRSSWakeUpTimer, YUNHORN_STS_RSS_WAKEUP_CHECK_TIME, UTIL_TIMER_ONESHOT, OnYunhornSTSOORSSWakeUpTimerEvent, NULL);
//UTIL_TIMER_Start(&YunhornSTSRSSWakeUpTimer); //UTIL_TIMER_Start(&YunhornSTSRSSWakeUpTimer);
UTIL_TIMER_Create(&YunhornSTSHeartBeatTimer, YUNHORN_STS_HEART_BEAT_CHECK_TIME, UTIL_TIMER_PERIODIC, OnYunhornSTSHeartBeatTimerEvent, NULL); UTIL_TIMER_Create(&YunhornSTSHeartBeatTimer, YUNHORN_STS_HEART_BEAT_CHECK_TIME, UTIL_TIMER_PERIODIC, OnYunhornSTSHeartBeatTimerEvent, NULL);
@ -1429,6 +1429,8 @@ static void OnJoinRequest(LmHandlerJoinParams_t *joinParams)
//UTIL_TIMER_Start(&STSDurationCheckTimer); //UTIL_TIMER_Start(&STSDurationCheckTimer);
OnYunhornSTSHeartBeatPeriodicityChanged(HeartBeatPeriodicity); OnYunhornSTSHeartBeatPeriodicityChanged(HeartBeatPeriodicity);
UTIL_TIMER_Create(&YunhornSTSRSSWakeUpTimer, YUNHORN_STS_RSS_WAKEUP_CHECK_TIME, UTIL_TIMER_ONESHOT, OnYunhornSTSOORSSWakeUpTimerEvent, NULL);
STS_SENSOR_Distance_Test_Process(); STS_SENSOR_Distance_Test_Process();
APP_LOG(TS_OFF, VLEVEL_H, "\r\nRSS Measured Distance=[%u] mm \r\n", (uint16_t)sts_distance_rss_distance); APP_LOG(TS_OFF, VLEVEL_H, "\r\nRSS Measured Distance=[%u] mm \r\n", (uint16_t)sts_distance_rss_distance);
@ -1772,10 +1774,13 @@ static void OnYunhornSTSSamplingPeriodicityChanged(uint32_t periodicity)
/* Update timer periodicity */ /* Update timer periodicity */
#if defined(STS_O6)||defined(STS_O7) #if defined(STS_O6)||defined(STS_O7)
UTIL_TIMER_Stop(&YunhornSTSRSSWakeUpTimer); if (STS_LoRa_WAN_Joined !=0)
UTIL_TIMER_SetPeriod(&YunhornSTSRSSWakeUpTimer, SamplingPeriodicity); {
UTIL_TIMER_Start(&YunhornSTSRSSWakeUpTimer); UTIL_TIMER_Stop(&YunhornSTSRSSWakeUpTimer);
APP_LOG(TS_OFF, VLEVEL_M,"**************** Sampling Timer Periodicity = %u (sec)\r\n", (SamplingPeriodicity/1000) ); UTIL_TIMER_SetPeriod(&YunhornSTSRSSWakeUpTimer, SamplingPeriodicity);
UTIL_TIMER_Start(&YunhornSTSRSSWakeUpTimer);
APP_LOG(TS_OFF, VLEVEL_M,"**************** Sampling Timer Periodicity = %u (sec)\r\n", (SamplingPeriodicity/1000) );
}
#else #else
UTIL_TIMER_Stop(&YunhornSTSSamplingCheckTimer); UTIL_TIMER_Stop(&YunhornSTSSamplingCheckTimer);
@ -2820,7 +2825,7 @@ void OnRestoreSTSCFGContextProcess(void)
#if defined(STS_O7)||defined(STS_O6) #if defined(STS_O7)||defined(STS_O6)
if ((sts_version == sts_cfg_nvm.version)&& (NVM_CFG_PARAMETER_SIZE == sts_cfg_nvm.length)) // if ((sts_version == sts_cfg_nvm.version)&& (NVM_CFG_PARAMETER_SIZE == sts_cfg_nvm.length))
{ {
STS_PRESENCE_SENSOR_Init(); STS_PRESENCE_SENSOR_Init();
//STS_PRESENCE_SENSOR_RSS_Init(); //STS_PRESENCE_SENSOR_RSS_Init();

Binary file not shown.