Method for collecting sensor data based on state machine principle
The state machine-based method for sensor data collection addresses accuracy and real-time challenges by optimizing sensor operations, enhancing data quality and reducing resource consumption.
Patent Information
- Application Number
- CN202411270694.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-11
- Publication Date
- 2024-12-13
AI Technical Summary
Existing sensor devices face accuracy issues due to limited sensor numbers and costs, leading to reduced device performance and failure to meet real-time requirements, particularly with low-end processors.
A method for collecting sensor data using a state machine principle, which includes sensor preparation, detection, data acquisition, and processing, ensuring real-time operation and efficient data collection while maintaining normal device functions.
The method achieves accurate, efficient, and stable sensor data collection with reduced resource usage, ensuring high sensitivity and resilience to environmental interference.
Smart Images

Figure CN119127350A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of data acquisition, and in particular is a method for acquiring sensor data based on a state machine principle. Background Art
[0002] Terminal devices with sensors have been widely used in various industries and daily life, such as mobile phones, remote controls, washing machines, etc. These devices usually integrate multiple sensors. However, due to the number and cost limitations of sensors, the accuracy of the acquired data may be affected, thus affecting the normal operation of the device functions.
[0003] To solve this problem, filtering technology is a common and effective method. By filtering the data obtained by the sensor, the accuracy of the data can be improved. However, the filtering process requires additional computing resources and time. If the processor takes too much time to obtain and process a large amount of sensor data, it will reduce the execution time of other business logics, thereby affecting the basic functions of the device and failing to meet real-time requirements. This problem is particularly prominent for low-end processors with weak data processing capabilities. Summary of the invention
[0004] The purpose of the present invention is to provide a method for collecting sensor data based on the state machine principle. The sensor data collection method based on the state machine principle effectively solves the problem raised in the above background technology. This method is based on the collection principle of the sensor and combines the real-time operation of the software. Under the premise of ensuring the normal execution of other business logics, the sensor data is collected, filtered, sorted and screened. In this way, not only more accurate and efficient data results can be obtained, but also costs can be reduced, and it has the following advantages: high stability, simple operation, high sensitivity and no influence from the external environment.
[0005] In order to achieve the above-mentioned object, the present invention provides the following technical solutions: a method for collecting sensor data based on the state machine principle, using a low-end processor chip to apply the state machine principle to obtain sensor data;
[0006] The specific process includes: state machine processing flow, sensor preparation processing flow, sensor detection start flow, sensor acquisition completion status query flow, sensor raw data acquisition flow, and sensor data processing flow;
[0007] The specific processes are as follows:
[0008] (I) The specific state machine processing flow is as follows:
[0009] The characters represent the following meanings:
[0010] Status: the current status of the state machine;
[0011] status1: sensor preparation status;
[0012] Status2: sensor detection status is turned on;
[0013] Status3: Query the sensor acquisition completion status;
[0014] Status4: Get the original data status of the sensor;
[0015] Status5: sensor data processing status;
[0016] The five states correspond to the five states or steps of the state machine, and one state or step is executed each time;
[0017] (II) The sensor preparation process is as follows:
[0018] The characters represent the following meanings:
[0019] Status: the current status of the state machine;
[0020] status1: sensor preparation status;
[0021] Status2: sensor detection status is turned on;
[0022] Count_WakeUp: count of sensor wake-up times;
[0023] Count_Err_WakeUp: count of sensor wake-up failures;
[0024] Specific step-by-step instructions:
[0025] S1, wake up the dormant sensor;
[0026] S2, determine whether the sensor is awakened;
[0027] S3, the sensor is not awakened; Status is still status1; Count_WakeUp+1;
[0028] S4, the sensor is awakened; Status changes to status2; Count_WakeUp is reset to 0;
[0029] S5, determining whether the count of the number of times the sensor is woken up reaches the count of the number of times the sensor is woken up;
[0030] S6, if the count reaches, the sensor is considered damaged;
[0031] (III) Start the sensor detection process, specifically:
[0032] The characters represent the following meanings:
[0033] Status: the current status of the state machine;
[0034] Status3: Query the sensor acquisition completion status;
[0035] Specific step-by-step instructions:
[0036] S1, operate the sensor to start measurement;
[0037] S2, Status changes to status3;
[0038] (IV) Query the sensor acquisition completion status process, specifically:
[0039] The characters represent the following meanings:
[0040] Status: the current status of the state machine;
[0041] status3: query the sensor acquisition completion status;
[0042] Status4: Get the original data status of the sensor;
[0043] Count_DetectFinish; detects the number of times the sensor has completed measurement;
[0044] Count_Err_Detect: The count of sensor detection failures;
[0045] Specific step-by-step instructions:
[0046] S1, determine whether the sensor has completed detection;
[0047] S2, the sensor has not completed detection; Status is still status3; Count_DetectFinish+1;
[0048] S3, the sensor completes detection; Status changes to status4; Count_DetectFinish is reset to 0;
[0049] S4, determining whether the number of times the detection sensor completes the measurement exceeds the count for determining that the sensor detection transmission fails;
[0050] S5, if the count is exceeded, the sensor is considered damaged;
[0051] (V) The process of obtaining raw sensor data is as follows:
[0052] The characters represent the following meanings:
[0053] Status: the current status value of the state machine;
[0054] Status2: sensor detection status is turned on;
[0055] Status4: Get the original data status of the sensor;
[0056] Status5: sensor data processing status;
[0057] Count_GetResult: the number of times the sensor raw data is obtained;
[0058] Count_Err_GetResult: The number of times the acquisition of sensor raw data failed;
[0059] Num_EffectiveData: the number of effective data;
[0060] Threshold_EffectiveData: The number threshold of effective data;
[0061] Specific step-by-step instructions:
[0062] S1, obtain sensor raw data;
[0063] S2, judging whether the original data of the sensor is successfully obtained;
[0064] S3, Status is still status4; Count_GetResult+1;
[0065] S4, judging whether the acquired sensor raw data is legal;
[0066] S5, Status is still status4; Count_GetResult+1;
[0067] S6, determining whether the number of times of obtaining the raw data of the sensor exceeds the number of times of determining that the acquisition of the raw data of the sensor fails;
[0068] S7, if the number exceeds the limit, the sensor is considered damaged;
[0069] S8, determining whether the valid data exceeds the number threshold of valid data;
[0070] S9, Status is still status4;
[0071] S10; Status changes to status5;
[0072] (VI) Sensor data processing flow, specifically:
[0073] The characters represent the following meanings:
[0074] Status: the current status value of the state machine;
[0075] Status1: wake up the dormant sensor;
[0076] Specific step-by-step instructions:
[0077] S1, sorting, filtering and other processing of the acquired sensor data to obtain the final result, and the sensor enters sleep mode;
[0078] S2, sets the state value Status of the state machine to status1.
[0079] Preferably, the low-end processor chip is a single-chip microcomputer, the power supply voltage of the single-chip microcomputer should be maintained at 5V or 3.3V, and the single-chip microcomputer includes a clock circuit.
[0080] Preferably, the sensor data contains high-precision characteristics, the sensor data having a limited range.
[0081] Preferably, sensor data collection includes data quality requirements, and the sensor data includes real-time requirements.
[0082] Preferably, the sensor state machine has clear state definition and clear state transfer logic.
[0083] Preferably, the business logic includes domain entity definition, and the business logic includes state business rule formulation.
[0084] Preferably, the sensor raw data includes a data range restriction, and the sensor raw data has a data accuracy requirement.
[0085] Preferably, the valid data has data stability and environmental adaptability.
[0086] The beneficial effects of the present invention are as follows:
[0087] The real-time operation of the software has been added here. Under the premise of ensuring the normal execution of other business logics, it can collect, filter, sort, and screen the sensor data. While obtaining more accurate and efficient data results, it also has the advantages of high stability, simple operation, high sensitivity, and no influence from the external environment. BRIEF DESCRIPTION OF THE DRAWINGS
[0088] Figure 1 The low-end processor chip of the present invention uses the state machine principle to obtain the sensor data overview;
[0089] Figure 2 It is a general diagram of the state machine processing flow of the present invention;
[0090] Figure 3 A schematic diagram of a flow chart for preparing a sensor of the present invention;
[0091] Figure 4 It is a schematic diagram of the opening sensor detection process of the present invention;
[0092] Figure 5 This is a schematic diagram of the query sensor acquisition completion state process of the present invention;
[0093] Figure 6 This is a schematic diagram of the process of obtaining raw data of the sensor according to the present invention;
[0094] Figure 7 It is a schematic diagram of the sensor data processing flow of the present invention. DETAILED DESCRIPTION
[0095] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0096] like Figures 1 to 7 As shown, an embodiment of the present invention provides a method for collecting sensor data based on a state machine principle, comprising the following steps:
[0097] Get the overall picture of sensor data based on the state machine principle of low-end processor chips;
[0098] The specific state machine processing flow is as follows:
[0099] (I) The meanings of the characters are as follows:
[0100] Status: the current status of the state machine;
[0101] status1: sensor preparation status;
[0102] Status2: sensor detection status is turned on;
[0103] Status3: Query the sensor acquisition completion status;
[0104] Status4: Get the original data status of the sensor;
[0105] Status5: sensor data processing status;
[0106] The five states correspond to the five states or steps of the state machine, and one step is executed at a time;
[0107] (II) The sensor preparation process is as follows:
[0108] The characters represent the following meanings:
[0109] Status: the current status of the state machine;
[0110] status1: sensor preparation status;
[0111] Status2: sensor detection status is turned on;
[0112] Count_WakeUp: count of sensor wake-up times;
[0113] Count_Err_WakeUp: count of sensor wake-up failures;
[0114] Specific step-by-step instructions:
[0115] S1, wake up the dormant sensor;
[0116] S2, determine whether the sensor is awakened;
[0117] S3, the sensor is not awakened; Status is still status1; Count_WakeUp+1;
[0118] S4, the sensor is awakened; Status changes to status2; Count_WakeUp is reset to 0;
[0119] S5, determining whether the count of the number of times the sensor is woken up reaches the count of failed wake-up sensor transmission;
[0120] S6, the sensor is considered damaged;
[0121] (III) Start the sensor detection process, specifically:
[0122] The characters represent the following meanings:
[0123] Status: the current status of the state machine;
[0124] Status3: Query the sensor acquisition completion status;
[0125] Specific step-by-step instructions:
[0126] S1, operate the sensor to start measurement;
[0127] S2, Status changes to status3;
[0128] (IV) Query the sensor acquisition completion status process, specifically:
[0129] The characters represent the following meanings:
[0130] Status: the current status of the state machine;
[0131] status3: query the sensor acquisition completion status;
[0132] Status4: Get the original data status of the sensor;
[0133] Count_DetectFinish; detects the number of times the sensor has completed measurement;
[0134] Count_Err_Detect: The count of sensor detection failures;
[0135] S1, determine whether the sensor has completed detection;
[0136] S2, the sensor has not completed detection; Status is still status3; Count_DetectFinish+1;
[0137] S3, the sensor completes detection; Status changes to status4; Count_DetectFinish is reset to 0;
[0138] S4, determining whether the number of times the detection sensor completes the measurement exceeds the count for determining that the sensor detection transmission fails;
[0139] S5, the sensor is considered damaged;
[0140] (V) The process of obtaining raw sensor data is as follows:
[0141] The characters represent the following meanings:
[0142] Status: the current status value of the state machine;
[0143] Status2: sensor detection status is turned on;
[0144] Status4: Get the original data status of the sensor;
[0145] Status5: sensor data processing status;
[0146] Count_GetResult: the number of times the sensor raw data is obtained;
[0147] Count_Err_GetResult: The number of times the acquisition of sensor raw data failed;
[0148] Num_EffectiveData: the number of effective data;
[0149] Threshold_EffectiveData: The number threshold of effective data;
[0150] S1, obtain sensor raw data;
[0151] S2, judging whether the original data of the sensor is successfully obtained;
[0152] S3, S5, Status is still status4; Count_GetResult+1;
[0153] S4, judging whether the acquired sensor raw data is legal;
[0154] S6, determining whether the number of times of obtaining the raw data of the sensor exceeds the number of times of determining that the acquisition of the raw data of the sensor fails;
[0155] S7, the sensor is considered damaged;
[0156] S8, determining whether the valid data exceeds the number threshold of valid data;
[0157] S9, Status is still status4;
[0158] S10; Status changes to status5;
[0159] (VI) Sensor data processing flow, specifically:
[0160] The characters represent the following meanings:
[0161] Status: the current status value of the state machine;
[0162] Status1: wake up the dormant sensor;
[0163] S1, sorting, filtering and other processing of the acquired sensor data to obtain the final result, and the sensor enters sleep mode;
[0164] S2, sets the state value Status of the state machine to status1.
[0165] Instructions attached Figure 1The basic principle and implementation of this application are summarized. Low-end processors are generally single-chip microcomputers, which cannot perform multi-threaded operations, that is, only one business logic can be processed at a time, and sensor data generally uses more data for centralized processing. If a general single-chip microcomputer performs polling, the efficiency is very low, and the real-time performance of some important businesses cannot be guaranteed. If the program runs are counted here, the real-time performance of sensor data acquisition and other business logics can be taken into account, which greatly improves efficiency. If T counts once every 10ms and T1 is 10, the sensor state machine rotates every 100ms. At other times, other business logics can be executed to ensure real-time performance, and the sensor damage status is queried every 100ms. Once a problem occurs, an alarm can be immediately issued. Such a design can avoid wasting resources and time, and reduce the execution time of other business logics. In addition, the real-time operation of the software is added, which can ensure the normal execution of other business logics. By collecting, filtering, sorting, screening and other operations on sensor data, not only more accurate and efficient data results are obtained, but also the cost is reduced. At the same time, it has the advantages of high stability, simple operation, high sensitivity, and no influence from the external environment.
[0166] Among them, the power supply voltage of the microcontroller should be maintained at 5V or 3.3V, and the microcontroller contains a clock circuit.
[0167] The microcontroller must be powered at a certain power. Higher or lower voltage will cause the microcontroller to malfunction. The clock circuit provides the microcontroller with a clock signal so that the microcontroller can execute instructions in sequence.
[0168] Among them, sensor data contains high-precision characteristics and sensor data has range limitations.
[0169] The high-precision feature ensures that the data error is within an acceptable range to ensure its accuracy; the range limitation is because the sensor has a specific measurement range, and data outside this range may not be accurately obtained or may be invalid.
[0170] Among them, sensor data collection includes data quality requirements, and sensor data includes real-time requirements.
[0171] The collected data must meet certain quality requirements such as accuracy and completeness to ensure the reliability and validity of the data; and the real-time requirement requires the sensor to have the ability to respond and transmit data quickly.
[0172] Among them, the sensor state machine has clear state definition and clear state transfer logic.
[0173] Each state in the state machine needs to have clear definitions and boundaries to ensure the accuracy of state transfers; and the clarity of state transfer logic ensures that the conditions and logic of state transfers are clear and unambiguous, avoiding ambiguous or erroneous state transfers.
[0174] Among them, business logic includes domain entity definition, and business logic includes state business rule formulation.
[0175] Domain entities clearly define the objects in the business and their attributes and behaviors, ensuring that the business logic revolves around these entities; the business rule formulation side specifies the conditions that must be met to complete specific actions, ensuring the correctness and consistency of the business logic.
[0176] Among them, the sensor raw data includes data range restrictions, and the sensor raw data has data accuracy requirements.
[0177] The data range limitation ensures that the data should be within the range of the sensor. Data outside the range may be inaccurate; while the data accuracy requirement ensures the accuracy and authenticity of the sensor's raw data.
[0178] Among them, valid data has data stability, and valid data has environmental adaptability.
[0179] Data stability enables effective data to remain stable for a long time, avoiding fluctuations in large amounts of data; while environmental adaptability enables it to adapt to different working environments and reduce interference from environmental factors.
[0180] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device.
[0181] Although embodiments of the present invention have been shown and described, it will be appreciated by those skilled in the art that various changes, modifications, substitutions and variations may be made to the embodiments without departing from the principles and spirit of the present invention, and that the scope of the present invention is defined by the appended claims and their equivalents.
Claims
1. A method for collecting sensor data based on the state machine principle, characterized in that: Use low-end processor chips to apply state machine principles to obtain sensor data; The specific process includes: state machine processing flow, sensor preparation processing flow, sensor detection start flow, sensor acquisition completion status query flow, sensor raw data acquisition flow, and sensor data processing flow; The specific processes are as follows: (I) The specific state machine processing flow is as follows: The characters represent the following meanings: Status: the current status of the state machine; status1: sensor preparation status; Status2: sensor detection status is turned on; Status3: Query the sensor acquisition completion status; Status4: Get the original data status of the sensor; Status5: sensor data processing status; The five states correspond to the five states or steps of the state machine, and one state or step is executed each time; (II) The sensor preparation process is as follows: The characters represent the following meanings: Status: the current status of the state machine; status1: sensor preparation status; Status2: sensor detection status is turned on; Count_WakeUp: count of sensor wake-up times; Count_Err_WakeUp: count of sensor wake-up failures; Specific step-by-step instructions: S1, wake up the dormant sensor; S2, determine whether the sensor is awakened; S3, the sensor is not awakened; Status is still status1; Count_WakeUp+1; S4, the sensor is awakened; Status changes to status2; Count_WakeUp is reset to 0; S5, determining whether the count of the number of times the sensor is woken up reaches the count of the number of times the sensor is woken up; S6, if the count reaches, the sensor is considered damaged; (III) Start the sensor detection process, specifically: The characters represent the following meanings: Status: the current status of the state machine; Status3: Query the sensor acquisition completion status; Specific step-by-step instructions: S1, operate the sensor to start measurement; S2, Status changes to status3; (IV) Query the sensor acquisition completion status process, specifically: The characters represent the following meanings: Status: the current status of the state machine; status3: query the sensor acquisition completion status; Status4: Get the original data status of the sensor; Count_DetectFinish; detects the number of times the sensor has completed measurement; Count_Err_Detect: The count of sensor detection failures; Specific step-by-step instructions: S1, determine whether the sensor has completed detection; S2, the sensor has not completed detection; Status is still status3; Count_DetectFinish+1; S3, the sensor completes detection; Status changes to status4; Count_DetectFinish is reset to 0; S4, determining whether the number of times the detection sensor completes the measurement exceeds the count for determining that the sensor detection transmission fails; S5, if the count is exceeded, the sensor is considered damaged; (V) The process of obtaining raw sensor data is as follows: The characters represent the following meanings: Status: the current status value of the state machine; Status2: sensor detection status is turned on; Status4: Get the original data status of the sensor; Status5: sensor data processing status; Count_GetResult: the number of times the sensor raw data is obtained; Count_Err_GetResult: The number of times the acquisition of sensor raw data failed; Num_EffectiveData: the number of effective data; Threshold_EffectiveData: The number threshold of effective data; Specific step-by-step instructions: S1, obtain sensor raw data; S2, judging whether the original data of the sensor is successfully obtained; S3, Status is still status4; Count_GetResult+1; S4, judging whether the acquired sensor raw data is legal; S5, Status is still status4; Count_GetResult+1; S6, determining whether the number of times of obtaining the raw data of the sensor exceeds the number of times of determining that the acquisition of the raw data of the sensor fails; S7, if the number exceeds the limit, the sensor is considered damaged; S8, determining whether the valid data exceeds the number threshold of valid data; S9, Status is still status4; S10; Status changes to status5; (VI) Sensor data processing flow, specifically: The characters represent the following meanings: Status: the current status value of the state machine; Status1: wake up the dormant sensor; Specific step-by-step instructions: S1, sorting, filtering and other processing of the acquired sensor data to obtain the final result, and the sensor enters sleep mode; S2, sets the state value Status of the state machine to status1.
2. The method for collecting sensor data based on the state machine principle according to claim 1, characterized in that: The low-end processor chip is a single-chip microcomputer, the power supply voltage of the single-chip microcomputer should be maintained at 5V or 3.3V, and the single-chip microcomputer includes a clock circuit.
3. The method for collecting sensor data based on the state machine principle according to claim 1, characterized in that: Sensor data contains high-precision characteristics, which have range limitations.
4. The method for collecting sensor data based on the state machine principle according to claim 1, characterized in that: Sensor data collection includes data quality requirements, and the sensor data includes real-time requirements.
5. The method for collecting sensor data based on the state machine principle according to claim 1, characterized in that: The sensor state machine has clear state definition and clear state transition logic.
6. The method for collecting sensor data based on the state machine principle according to claim 1, characterized in that: The business logic includes domain entity definition, and the business logic includes state business rule formulation.
7. The method for collecting sensor data based on the state machine principle according to claim 1, characterized in that: The sensor raw data includes a data range restriction, and the sensor raw data has a data accuracy requirement.
8. The method for collecting sensor data based on the state machine principle according to claim 1, characterized in that: The effective data has data stability and environmental adaptability.
