ground up zone define and start dual mode, uni mode fast switch issue

This commit is contained in:
Yunhorn 2024-06-18 13:28:52 +08:00
parent 7927dd9bb1
commit 8efcbc6ac7
5 changed files with 89 additions and 27 deletions

View File

@ -47,7 +47,7 @@ extern "C" {
/**
* @brief Verbose level for all trace logs
*/
#define VERBOSE_LEVEL VLEVEL_M
#define VERBOSE_LEVEL VLEVEL_L
/**
* @brief Enable trace logs

View File

@ -44,7 +44,13 @@
#define STS_DISTANCE_HWAAS (63)
#define DEFAULT_FAR_RANGE_CFAR_THRESHOLD_GUARD 0.12f
#define DEFAULT_FAR_RANGE_CFAR_THRESHOLD_WINDOW 0.03f
#ifndef MIN
#define MIN( a, b ) ( ( ( a ) < ( b ) ) ? ( a ) : ( b ) )
#endif
#ifndef MAX
#define MAX( a, b ) ( ( ( a ) > ( b ) ) ? ( a ) : ( b ) )
#endif
//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, 2, 63, 2, 10, 0.5, 1.3, 0.2};
@ -126,7 +132,7 @@ int sts_distance_rss_detector_distance(void)
APP_LOG(TS_OFF, VLEVEL_M, "\r\nAverage Distance= %u mm\r\n", (uint16_t)sts_distance_rss_distance);
// ensure it's a valid installation height
if (sts_distance_rss_distance > 2000) sts_sensor_install_height = sts_distance_rss_distance;
sts_sensor_install_height = MAX(sts_distance_rss_distance,2000);
bool deactivated = acc_detector_distance_deactivate(distance_handle);

View File

@ -84,6 +84,28 @@
#ifndef MIN
# define MIN(a,b) ((a) < (b) ? (a) : (b))
#endif
//sensor installation height segment from ground
// sensor at ceiling sts_sensor_install_height_in_10cm
//
//
// HS5= distance = sts_sensor_install_height_in_10cm - 5*DEFAULT_ZONE_LENGTH -> (26-4*5)*10cm
//
// HS4= distance = sts_sensor_install_height_in_10cm - 4*DEFAULT_ZONE_LENGTH -> (26-4*4)*10cm
//
// HS3= distance = sts_sensor_install_height_in_10cm - 3*DEFAULT_ZONE_LENGTH -> (26-4*3)*10cm
//
// HS2= distance = sts_sensor_install_height_in_10cm - 2*DEFAULT_ZONE_LENGTH -> (26-4*2)*10cm
//
// HS1= distance = sts_sensor_install_height_in_10cm - 1*DEFAULT_ZONE_LENGTH -> (26-4)*10cm
//
// HS0= ------ Ground -distance = sts_sensor_install_height_in_10cm, say 26*10cm
#define HS0 (1<<0) // ground up 0*zone(0.4)
#define HS1 (1<<1) // ground up 0*zone(0.4)
#define HS2 (1<<2) // ground up 1*zone(0.4)
#define HS3 (1<<3)
#define HS5 (1<<4)
extern volatile uint8_t sts_fall_detection_acc_threshold, sts_fall_detection_depth_threshold, sts_occupancy_overtime_threshold;
volatile uint8_t sts_unconscious_state=0;
@ -95,7 +117,9 @@ volatile float sts_presence_rss_distance, sts_presence_rss_score;
volatile STS_OO_RSS_SensorTuneDataTypeDef sts_presence_rss_config;
//static void update_configuration(acc_detector_presence_configuration_t presence_configuration);
static void print_result(acc_detector_presence_result_t result);
volatile uint8_t motion_detected_count=0;
volatile uint8_t motion_in_hs_zone[12][10]={0}; //0.4*12=4.8meter high, past 10 measures
volatile uint8_t detected_hs_zone=0;;
volatile uint16_t motion_count=0, motion_feature_count=0;
static acc_detector_presence_result_t sts_motion_dataset[DEFAULT_MOTION_DATASET_LEN];
static STS_PRESENCE_Motion_Featuer_t sts_motion_feature[DEFAULT_MOTION_FEATURE_LEN];
@ -292,7 +316,6 @@ static void print_result(acc_detector_presence_result_t result)
if (result.presence_detected)
{
uint32_t detected_zone = (uint32_t)((float)(result.presence_distance - DEFAULT_START_M) / (float)DEFAULT_ZONE_LENGTH);
APP_LOG(TS_OFF, VLEVEL_H,"Motion in zone: %u, distance: %d, score: %d\n", (unsigned int)detected_zone,
(int)(result.presence_distance * 1000.0f),
(int)(result.presence_score * 1000.0f));
@ -373,6 +396,11 @@ int sts_presence_rss_fall_rise_detection(void)
//uint8_t k=0;
uint16_t motion_in_zone[10]={0x0};
uint16_t detected_zone=0;
memset(motion_in_hs_zone, 0x0, 12*10);
//past 10 times of detection with 5 zones from ground to ceiling
//for (k=0; k<5; k++) {motion_in_zone[k]=0;}
#if 1
for (int i = 0; i < (iterations/2); i++)
@ -394,6 +422,12 @@ int sts_presence_rss_fall_rise_detection(void)
average_score += result.presence_score;
detected_zone = (uint16_t)((float)(result.presence_distance - DEFAULT_START_M) / (float)DEFAULT_ZONE_LENGTH);
motion_in_zone[detected_zone]++;
// new add 2024-06-18
detected_hs_zone = (uint16_t)((float)(sts_sensor_install_height/1000.0f - (result.presence_distance))/(float)DEFAULT_ZONE_LENGTH);
//APP_LOG(TS_OFF, VLEVEL_L, "\r\nHS_ZONE=%u", (int)detected_hs_zone);
motion_in_hs_zone[detected_hs_zone][(motion_detected_count)]++;
}
if (sts_presence_fall_detection == 1)
@ -460,6 +494,11 @@ int sts_presence_rss_fall_rise_detection(void)
average_score += result.presence_score;
detected_zone = (uint16_t)((float)(result.presence_distance - DEFAULT_START_M) / (float)DEFAULT_ZONE_LENGTH);
motion_in_zone[detected_zone]++;
// new add 2024-06-18
//detected_hs_zone = (uint16_t)((float)(sts_sensor_install_height/1000.0f - (result.presence_distance))/(float)DEFAULT_ZONE_LENGTH);
//APP_LOG(TS_OFF, VLEVEL_L, "\r\nHS_ZONE=%u", detected_hs_zone);
//motion_in_hs_zone[detected_hs_zone][(motion_detected_count)]++;
}
if (sts_presence_fall_detection == 1)
@ -482,8 +521,13 @@ 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);
uint8_t thiscnt= motion_detected_count;
sts_rss_result = (average_result > 1)? 1: 0;
if (motion_detected_count++ == 10) {
motion_detected_count=0;
}
sts_rss_result = (average_result > 3)? 1: 0;
if (sts_rss_result) {
LED1_ON;
OnSensor3StateChanged();
@ -501,14 +545,18 @@ int sts_presence_rss_fall_rise_detection(void)
*/
#ifdef LOG_RSS
for (uint8_t k=0; k<10; k++) {
if (motion_in_zone[k]>0) {
APP_LOG(TS_OFF, VLEVEL_M,"\r\nMotion Distance Zone: %2u %4u %4d cm", k, motion_in_zone[k], (80+k*40));
}
else {
APP_LOG(TS_OFF, VLEVEL_M,"\r\nMotion Distance Zone: %2u %4s", k, " ");
}
}
APP_LOG(TS_OFF, VLEVEL_L,"\r\nSensor at Ceiling Height: %4u mm\r\n",(int)sts_sensor_install_height);
for (uint8_t k=0; k<12; k++) {
if (motion_in_hs_zone[k][thiscnt]>0) {
APP_LOG(TS_OFF, VLEVEL_L,"\r\nMotion Distance Zone: %2u %4u Height< %4u cm", k, (uint8_t)motion_in_hs_zone[k][thiscnt], (int)(k+1)*40);
}
else
{
APP_LOG(TS_OFF, VLEVEL_L,"\r\nMotion Distance Zone: %2u %4s", k, " ");
}
}
#endif
average_distance = (1000.0f*average_distance)/average_result; // in meters
average_score = (1000.0f*average_score)/average_result;
@ -516,8 +564,16 @@ int sts_presence_rss_fall_rise_detection(void)
sts_presence_rss_score = average_score;
if (average_score) //if (average_score !=0) //if (sts_rss_result)
{
APP_LOG(TS_OFF, VLEVEL_H,"\r\n######## Motion: %u Distance=%u mm, Score=%u Average_result=%u out of %u \r\n",
#ifdef LOG_RSS
APP_LOG(TS_OFF, VLEVEL_L,"\r\n######## Motion: %u Distance=%u mm, Score=%u Average_result=%u out of %u \r\n",
(uint8_t)sts_rss_result,(int) average_distance, (int)(average_score), (int)average_result, (int)iterations);
#endif
#ifdef LOG_RSS
for (uint8_t j=0; j<5; j++) {
APP_LOG(TS_OFF, VLEVEL_M,"\r\n######## Motion: %u Distance=%u mm, Score=%u Average_result=%u out of %u \r\n",
(uint8_t)sts_rss_result,(int) average_distance, (int)(average_score), (int)average_result, (int)iterations);
}
#endif
}
@ -623,10 +679,10 @@ void STS_YunhornCheckStandardDeviation(void)
standard_variance_roc_acc *= (float)DEFAULT_MOTION_DATASET_LEN;
// 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",
(int)sts_sensor_install_height, (int)(average_presence_distance*1000.0f), (int)(variance_presence_distance*1000.0f), (int)(standard_variance_presence_distance*1000.0f));
//#endif
#endif
#ifdef LOG_RSS
APP_LOG(TS_OFF, VLEVEL_M, "-------------Motion Average =%6u; Variance = %6u ; Standard =%6u \r\n",
(int)(average_presence_score*1000.0f), (int)(variance_presence_score*1000.0f), (int)(standard_variance_presence_score*1000.0f));

View File

@ -38,7 +38,7 @@
/* USER CODE BEGIN Includes */
extern volatile sts_cfg_nvm_t sts_cfg_nvm;
extern volatile uint8_t sts_ac_code[20];
volatile uint8_t sts_service_mask;
volatile uint8_t sts_service_mask=0;
volatile uint32_t rfac_timer;
volatile uint8_t sensor_data_ready=0;
@ -58,7 +58,7 @@ extern volatile uint8_t mems_int1_detected, link_wakeup, link_sleep;
volatile uint32_t event_start_time=0, event_stop_time=0;
volatile uint32_t event_door_lock_start_time=0,event_door_lock_stop_time=0;
extern volatile uint8_t sts_occupancy_overtime_state;
extern volatile STS_OO_RSS_SensorTuneDataTypeDef sts_presence_rss_config;
//extern volatile STS_OO_RSS_SensorTuneDataTypeDef sts_presence_rss_config;
extern volatile sts_cfg_nvm_t sts_cfg_nvm;
extern volatile uint8_t sts_fall_detection_acc_threshold, sts_fall_detection_depth_threshold, sts_occupancy_overtime_threshold_in_10min;
extern volatile uint8_t sts_fall_rising_detected_result_changed_flag;

View File

@ -71,7 +71,7 @@ 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;
volatile uint8_t sts_presence_fall_detection=1;
volatile uint32_t SamplingPeriodicity = 1000; //unit ms
volatile uint32_t SamplingPeriodicity = 3000; //unit ms
volatile uint32_t HeartBeatPeriodicity = 120000; //unit ms
volatile uint8_t STS_LoRa_WAN_Joined = 0;
volatile uint8_t mems_int1_detected = 0;
@ -88,7 +88,7 @@ volatile sts_cfg_nvm_t sts_cfg_nvm = {
sts_hardware_ver,
0x05,
'M', //Uplink data interval for heart-beat uplink
0x01,
0x03,
'S', //Sampling sensor interval for real-time sensing of MEMS
0x04, // dual mode=4, uni_mode =5
0x00, // service mask
@ -943,11 +943,11 @@ static void SendTxData(void)
char colorshow[30]="";
strcpy(colorshow, (ich==0)?"":sts_lamp_color_code[ich]);
APP_LOG(TS_OFF, VLEVEL_L,
APP_LOG(TS_OFF, VLEVEL_M,
"\r\n######| Color = %s%s | Mode = %5s |\r\n",(char *)colorshow, sts_lamp_color_code[icl], (char*)sts_work_mode_code[sensorData.workmode]);
if (sts_work_mode == STS_UNI_MODE)
{
APP_LOG(TS_OFF, VLEVEL_L,
APP_LOG(TS_OFF, VLEVEL_M,
"\r\n######| S1-DoorOpen | S2-Motion | S3-SOS | S4 |Distance(mm) | MotionScore| Unconscious | Over_Stay_(min) | Fall Detected|"
"\r\n######| %1d | %1d | %1d | %1d | %04d | %04d | %1d | %4d | %1d |\r\n",
sensorData.state_sensor1_on_off, sensorData.state_sensor2_on_off,sensorData.state_sensor3_on_off, sensorData.state_sensor4_on_off,
@ -955,7 +955,7 @@ static void SendTxData(void)
sensorData.unconscious_state, sensorData.over_stay_duration/60, sensorData.fall_state );
} else if (sts_work_mode == STS_DUAL_MODE) {
APP_LOG(TS_OFF, VLEVEL_L,
APP_LOG(TS_OFF, VLEVEL_M,
"\r\n######| S1-DoorOpen | S2-Motion | S3-SOS |\r\n"
"\r\n######| %1d | %1d | %1d |\r\n",
sensorData.state_sensor1_on_off, sensorData.state_sensor2_on_off,sensorData.state_sensor3_on_off);
@ -1520,14 +1520,14 @@ static void OnYunhornSTSOORSSWakeUpTimerEvent(void *context)
{
UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_YunhornSTSEventP2), CFG_SEQ_Prio_0);
APP_LOG(TS_OFF,VLEVEL_L,"\r\n RSS result changed flag=%d \r\n", sts_rss_result_changed_flag);
if ((STS_LoRa_WAN_Joined != 0)&&(sts_rss_result_changed_flag==1))
{
sts_rss_result_changed_flag = 0;
UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_LoRaSendOnTxTimerOrButtonEvent), CFG_SEQ_Prio_0);
//if ((last_sts_rss_result ==STS_RESULT_NO_MOTION)&& (sts_rss_result==STS_RESULT_MOTION))
{
OnSensor3StateChanged();
//OnSensor3StateChanged();
}
}
}
@ -1610,13 +1610,13 @@ static void OnYunhornSTSSamplingPeriodicityChanged(uint32_t periodicity)
UTIL_TIMER_Stop(&YunhornSTSRSSWakeUpTimer);
UTIL_TIMER_SetPeriod(&YunhornSTSRSSWakeUpTimer, SamplingPeriodicity);
UTIL_TIMER_Start(&YunhornSTSRSSWakeUpTimer);
APP_LOG(TS_OFF, VLEVEL_L,"**************** Sampling Timer Periodicity = %u (sec)\r\n", (SamplingPeriodicity/1000) );
APP_LOG(TS_OFF, VLEVEL_M,"**************** Sampling Timer Periodicity = %u (sec)\r\n", (SamplingPeriodicity/1000) );
#else
UTIL_TIMER_Stop(&YunhornSTSSamplingCheckTimer);
UTIL_TIMER_SetPeriod(&YunhornSTSSamplingCheckTimer, SamplingPeriodicity);
UTIL_TIMER_Start(&YunhornSTSSamplingCheckTimer);
APP_LOG(TS_OFF, VLEVEL_L,"**************** SamplingPeriodicity = %u (sec)\r\n", (SamplingPeriodicity/1000) );
APP_LOG(TS_OFF, VLEVEL_M,"**************** SamplingPeriodicity = %u (sec)\r\n", (SamplingPeriodicity/1000) );
#endif
/* USER CODE BEGIN OnTxPeriodicityChanged_2 */