A method and system for setting a virtual electronic fence of a device based on UWB positioning
By optimizing the time slot allocation of the UWB positioning system through density clustering and deep Q-network, the problems of positioning blind spots and virtual fence monitoring failures in the UWB positioning system under high load were solved, and continuous and reliable positioning of critical equipment was achieved.
Patent Information
- Application Number
- CN202611434776.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-09-16
- Publication Date
- 2026-11-27
AI Technical Summary
Existing UWB positioning systems cannot adapt to dynamically changing tag loads in high-load scenarios, leading to positioning blind spots and virtual fence monitoring failures. Furthermore, they lack a priority mechanism to differentiate services based on their importance, making it impossible to guarantee continuous and reliable positioning of critical equipment.
Density clustering algorithm is used to group labels, combined with carrier sense multiple access conflict avoidance and time division multiple access hybrid access, long short time memory network is used to predict future trajectories and fence threat index, deep Q network agent dynamically adjusts the time slot quota between groups, and reserves or releases time slots according to the threat index to achieve secondary optimization allocation of time slots.
It alleviates the rigidity of static resource allocation, reduces the occurrence rate of blind spots in positioning, ensures the continuity and reliability of virtual fence monitoring, and overcomes the failure defects of traditional fixed allocation and random access under high load.
Smart Images

Figure CN123185656A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of wireless positioning and electronic fence technology, and more specifically, to a method and system for setting up a virtual electronic fence for a device based on UWB positioning. Background Technology
[0002] With the rapid development of IoT technology, Ultra-Wideband (UWB) positioning technology has been widely applied in scenarios such as large sports stadiums, general hospitals, and smart manufacturing plants to implement precise virtual electronic fence monitoring of a large number of mobile devices. For example, in a stadium with a capacity of 10,000, each staff member wears a UWB badge, and the system needs to simultaneously locate thousands of tags in real time and delineate restricted areas. In modern hospitals, medical equipment, medicine carts, and medical staff all carry UWB tags, requiring the system to continuously track and prevent equipment from accidentally entering clean or hazardous areas in densely populated spaces such as corridors and wards. In large factories, AGVs, tool trays, and inspection personnel work together, and virtual fences need to dynamically divide safe passages and work areas. The common feature of these scenarios is the large number of tags, reaching hundreds or even thousands, and all tags share the same UWB frequency band for ranging communication.
[0003] Currently, such systems generally use Time Division Multiple Access (TDMA) to allocate fixed ranging time slots to each tag to ensure conflict-free data interaction. However, when the total number of tags exceeds the preset number of time slots, some tags will be unable to complete ranging within the specified frame period, resulting in periodic positioning blind spots. This causes the corresponding devices to completely lose their location information for a period of time, and the virtual fence monitoring will fail. The root cause of this problem is that static time slot allocation cannot adapt to dynamically changing tag loads. Even if some tags are idle, they occupy time slot resources for a long time, while weak signal tags moving in the air further squeeze out limited time slots due to retransmission requirements. At the same time, the system lacks a priority mechanism to differentiate services according to importance, so dangerous devices near the fence boundary and ordinary devices far from the boundary receive the same service level, and critical devices cannot be prioritized. Existing expansion solutions mostly rely on adding base stations or dividing subnets, which are not only costly but also complex to deploy. Furthermore, the probability of collisions increases sharply under high loads using contention-based random access methods, all of which are difficult to meet the stringent requirements of continuous and reliable positioning for virtual fences in large-scale concurrent scenarios. Summary of the Invention
[0004] This invention addresses the technical problems existing in the prior art by providing a method and system for setting up a virtual electronic fence for devices based on UWB positioning, thereby resolving the issues raised in the background section.
[0005] The technical solution of this invention to solve the above-mentioned technical problems is as follows: a method for setting up a virtual electronic fence for a device based on UWB positioning, specifically including the following steps:
[0006] S1. The central controller collects the real-time location coordinates of all UWB tags to be located through the UWB base station according to the preset scheduling frame, and obtains the signal-to-noise ratio of each UWB tag communicating with the UWB base station. It uses a density clustering algorithm to group these UWB tags. Within each group, a carrier sense multiple access conflict avoidance mechanism is used for contention access. Different groups are allocated non-overlapping time slots using time division multiple access. Each group maintains a corresponding time slot pool, stores all time slots allocated to the group in the current scheduling frame, and records the number of time slots allocated to the group in the previous scheduling frame.
[0007] S2. Extract the historical trajectory sequence for each UWB tag and input it into the pre-trained long short-term memory network model. Output the predicted location sequence for future time moments, calculate the probability of the UWB tag crossing the fence boundary and the minimum distance to the fence boundary, and define the fence threat index for each UWB tag accordingly.
[0008] S3. The central controller uses each group as a scheduling unit to construct a deep Q network agent. The state space is based on the number of UWB tags in the group, the average fence threat index and the maximum fence threat index calculated according to the fence threat index of each UWB tag obtained in step S2, the average signal-to-noise ratio of each UWB tag communicating with the UWB base station in the group, and the number of time slots allocated to the group in the previous scheduling frame. The action space is based on the time slot increment. The reward function is based on a function that comprehensively considers the time slot rewards for successful positioning, lost positioning, and high-threat groups. The output is the number of time slots that each group should obtain in the current scheduling frame.
[0009] S4. Based on the fence threat index of each UWB tag, reserve dedicated time slots from the time slot pool of its group and shorten the ranging cycle for UWB tags that are higher than the preset first threshold, and extend the ranging cycle and release the time slots for UWB tags that are lower than the preset second threshold. The released time slots are returned to the time slot pool of the group for reallocation, thus completing the secondary optimization allocation of time slots.
[0010] In a preferred embodiment, the specific operation of the density clustering algorithm in step S1 is as follows:
[0011] First, the central controller calculates the joint distance between every two UWB tags. The joint distance is obtained by weighted summation of two parts. The first part is the Euclidean distance between the real-time position coordinates of the two UWB tags multiplied by a first weighting coefficient. The second part is the absolute value of the difference between the reciprocals of the signal-to-noise ratios of the two UWB tags multiplied by a second weighting coefficient. The sum of the first weighting coefficient and the second weighting coefficient is equal to one.
[0012] Then, the central controller calculates the exclusive neighborhood radius for each UWB tag. The exclusive neighborhood radius is equal to the preset base radius multiplied by an adjustment factor. The adjustment factor is one plus a preset adjustment coefficient multiplied by the difference between the signal-to-noise ratio of the UWB tag and the maximum signal-to-noise ratio among all UWB tags in the current scheduling frame, divided by the difference between the maximum value and the minimum signal-to-noise ratio among all UWB tags in the current scheduling frame.
[0013] Finally, the central controller uses the joint distance as the distance metric and the exclusive neighborhood radius of each UWB tag as its neighborhood radius. It then runs the DBSCAN clustering algorithm to group all density-reachable UWB tags into the same group and separate UWB tags not covered by any principal point into a separate group.
[0014] In a preferred embodiment, the specific operation of maintaining a corresponding time slot pool for each group and recording the number of time slots allocated to each group in the previous scheduling frame in step S1 is as follows:
[0015] The central controller allocates the total number of available time slots in the current scheduling frame based on the number of UWB tags in each group within the current scheduling frame, according to the proportion of the number of UWB tags in each group to the total number of UWB tags in all groups. This results in the initial time slot pool capacity for each group. Simultaneously, the central controller records the number of time slots allocated to each group in the previous scheduling frame. For the first scheduling frame, the initial time slot pool capacity of the group is used as the number of time slots allocated in the previous scheduling frame.
[0016] Subsequently, the UWB tags within each packet compete for the use of time slots in the packet's time slot pool through the carrier sense multiple access conflict avoidance mechanism, and different packets occupy their respective time slot blocks in turn according to the time division multiple access method, without overlapping.
[0017] In a preferred embodiment, the specific operation of extracting the historical trajectory sequence and inputting it into the pre-trained Long Short-Term Memory network model in step S2 is as follows:
[0018] For each UWB tag, the central controller extracts the location records within a preset number of scheduling frames in the past to form a historical trajectory sequence;
[0019] Simultaneously, the velocity scalar and heading angle of each historical scheduling frame are calculated, and the sine and cosine values of the position coordinates, velocity scalar, and heading angle are concatenated into a multi-dimensional feature vector;
[0020] The multidimensional feature vectors are input into the pre-trained Long Short-Term Memory (LSTM) network model in chronological order. The LSM network model contains two LSM hidden layers and one fully connected layer, and outputs the predicted position offsets for a preset number of future time steps. The central controller accumulates the predicted position offsets of each time step to the position coordinates of the current scheduling frame to obtain the predicted position coordinates of each future time step, forming a sequence of predicted positions for future moments.
[0021] In a preferred embodiment, the specific steps in step S2—calculating the probability of a UWB tag crossing the fence boundary, the minimum distance to the fence boundary, and defining the fence threat index—are as follows:
[0022] For each predicted location in the predicted location sequence of each UWB tag, the central controller uses the ray casting method to determine whether the predicted location is outside the virtual fence boundary. If it is outside, it is recorded as a crossing event.
[0023] An exponentially weighted average is calculated for all crossing events, with the weight of the predicted position that is closer to the current scheduling frame in time being higher than the weight of the predicted position that is farther away from the current scheduling frame in time, to obtain the crossing probability of the UWB tag.
[0024] Simultaneously, the shortest Euclidean distance from each predicted location to the virtual fence boundary is calculated, and the minimum value within the entire prediction window is taken as the minimum distance between the UWB tag and the fence boundary.
[0025] Finally, the probability of crossing is multiplied by an exponential decay function with the minimum distance as the variable to obtain the fence threat index of the UWB tag. The smaller the minimum distance, the larger the value of the exponential decay function.
[0026] In a preferred embodiment, the state space in step S3 is specifically configured as follows:
[0027] The central controller uses each group as a scheduling unit to construct a deep Q network agent; it uses five components to form a state vector: the number of UWB tags in each group, the average fence threat index and the maximum fence threat index calculated based on the fence threat index of each UWB tag obtained in step S2, the average signal-to-noise ratio of each UWB tag communicating with the UWB base station within the group, and the number of time slots allocated to the group in the previous scheduling frame.
[0028] The average fence threat index is the sum of the fence threat indices of all UWB tags in the group divided by the number of UWB tags in the group, and the maximum fence threat index is the maximum value among all UWB tags in the group.
[0029] The central controller performs min-max normalization on each component in the state vector, so that the value of each component falls between zero and one. The normalization is calculated using the maximum and minimum values of the components in all packets within the current scheduling frame.
[0030] In a preferred embodiment, the specific operation of updating the action space and time slot constraints in step S3 is as follows:
[0031] The central controller defines a discrete set of actions for each group. The set of actions contains five possible time slot increment values, namely -2, -1, zero, +1, and +2, with the unit being the number of time slots.
[0032] After the central controller selects the time slot increment for each group based on the current state, it adds the time slot increment to the number of time slots allocated to the group in the previous scheduling frame to obtain the initial number of time slots that the group should obtain in the current scheduling frame. Then, it compares the initial number of time slots with the minimum number of time slots and takes the larger value as the final number of time slots for the group.
[0033] The central controller further verifies whether the sum of the final timeslots of all groups exceeds the total number of available timeslots in the current scheduling frame. If it does, the number of timeslots is reduced proportionally to the final timeslots of each group until the sum equals the total number of available timeslots.
[0034] The number of time slots after verification and reduction is taken as the number of time slots that each group should obtain in the current scheduling frame.
[0035] In a preferred embodiment, the reward function in step S3 is specifically configured as follows:
[0036] The central controller calculates the reward value after each scheduling frame ends. The reward value is obtained by weighted summation of three parts. The first part is the positioning success reward, which is equal to the number of UWB tags that successfully completed ranging and positioning in the current scheduling frame divided by the total number of all UWB tags.
[0037] The second part is the lost location penalty, which is equal to the negative of the number of UWB tags that failed to complete ranging due to insufficient time slots in the current scheduling frame, divided by the total number of all UWB tags.
[0038] The third part is the slot reward for high-threat groups. For each group, if the average fence threat index of the group is greater than the average fence threat index of all groups, then the positive reward is calculated based on the difference between the actual slot increment obtained by the group and the average fence threat index of the group minus the average fence threat index of all groups. The average of the positive rewards of all groups is taken as the third part; the sum of the weight coefficients of the three parts is equal to one.
[0039] In a preferred embodiment, the specific operation of performing secondary optimization allocation of time slots based on the fence threat index of each UWB tag in step S4 is as follows:
[0040] The central controller presets a first threshold and a second threshold, with the first threshold being greater than the second threshold. The central controller classifies UWB tags with a fence threat index greater than the first threshold into a high-threat tag set and UWB tags with a fence threat index less than the second threshold into a low-threat tag set.
[0041] For each UWB tag in the high-threat tag set, the central controller calculates the number of reserved dedicated time slots. The number of reserved dedicated time slots is equal to the preset reserved strength coefficient multiplied by the difference between the fence threat index of the UWB tag and the first threshold, divided by the difference between the first threshold and the preset maximum number of reserved time slots, and then rounded up. At the same time, the ranging period of the UWB tag is shortened from the reference period to the reference period divided by the preset period shortening factor.
[0042] For each UWB tag in the low-threat tag set, the central controller calculates the number of release slots. The number of release slots is equal to the ratio of the preset release strength coefficient multiplied by the second threshold minus the difference of the UWB tag's fence threat index divided by the second threshold, multiplied by the preset maximum number of release slots, and then rounded down. At the same time, the ranging period of the UWB tag is extended to the base period multiplied by the preset period extension factor. The base period is equal to the duration of one scheduling frame.
[0043] The central controller updates the actual time slot pool capacity of each group based on the total number of reserved dedicated time slots for high-threat tag sets and the total number of released time slots for low-threat tag sets within each group. The actual time slot pool capacity is equal to the number of time slots obtained by the group in step S3 minus the total number of reserved dedicated time slots plus the total number of released time slots. The reserved dedicated time slots are pre-allocated from the time slot pool for exclusive use by high-threat tags, and the released time slots are returned to the time slot pool for reallocation.
[0044] This application also provides a device virtual electronic fence setting system based on UWB positioning, specifically including:
[0045] Time slot initialization module: The central controller collects the real-time location coordinates and signal-to-noise ratio of all UWB tags to be located through the UWB base station according to the preset scheduling frame, and uses a density clustering algorithm to group the tags. Within each group, the carrier sense multiple access conflict avoidance mechanism competes for access, and the time division multiple access allocates non-overlapping time slots between groups. It also maintains a time slot pool for each group and records the number of time slots allocated in the previous frame.
[0046] Threat assessment module: The central controller extracts historical trajectory sequences for each UWB tag and inputs them into a pre-trained long short-term memory network model, outputting a future predicted location sequence. Based on this, it calculates the probability of crossing the fence boundary and the minimum distance, and defines the fence threat index for each tag.
[0047] The time slot dynamic allocation module: The central controller constructs a deep Q network agent with each group as the scheduling unit. The state is based on the number of tags in the group, the average and maximum fence threat index, the average signal-to-noise ratio, and the number of time slots in the previous frame. The action is the time slot increment. The reward function is the time slot reward for successful positioning, lost positioning, and high-threat group. The output is the number of time slots that each group should get in the current frame.
[0048] Secondary time slot optimization module: Based on the fence threat index of each tag, the central controller reserves a dedicated time slot from the time slot pool of its group and shortens the ranging cycle for tags with a value higher than the first threshold, and extends the ranging cycle and releases the time slot for tags with a value lower than the second threshold. The released time slot is returned to the time slot pool, thus completing the secondary time slot optimization allocation.
[0049] The beneficial effects of this invention are as follows: Labels are grouped using density clustering algorithms, and combined with carrier sense multiple access conflict avoidance and time division multiple access (TDMA) hybrid access, alleviating resource rigidity caused by static allocation; Long short-term memory (LSTM) networks are used to predict future trajectories and calculate the fence threat index, enabling the system to predict risks; Deep Q-network agents dynamically adjust time slot quotas between groups, and based on the threat index, dedicated time slots are reserved for high-threat labels and the ranging cycle is shortened, while the cycle is extended for low-threat labels to release time slots, achieving secondary optimization of time slots; Thus, scarce time slots are accurately allocated to dangerous devices near the fence, significantly reducing the occurrence of blind spots in positioning, ensuring the continuity and reliability of virtual fence monitoring, and overcoming the failure defects of traditional fixed allocation and random access under high load. Attached Figure Description
[0050] Figure 1 This is a flowchart of the method of the present invention;
[0051] Figure 2 This is a block diagram of the system structure of the present invention;
[0052] Figure 3 This is a schematic diagram comparing the secondary optimization allocation of time slots within the group of this invention. Detailed Implementation
[0053] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0054] In the description of this application, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of indicated technical features. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more of the stated features. In the description of this application, "multiple" means two or more, unless otherwise explicitly specified.
[0055] In the description of this application, the term "for example" is used to mean "used as an example, illustration, or description." Any embodiment described as "for example" in this application is not necessarily to be construed as being more preferred or advantageous than other embodiments. The following description is provided to enable any person skilled in the art to make and use the invention. Details are set forth in the following description for purposes of explanation. It should be understood that those skilled in the art will recognize that the invention can be made without using these specific details. In other instances, well-known structures and processes will not be described in detail to avoid obscuring the description of the invention with unnecessary detail. Therefore, the invention is not intended to be limited to the embodiments shown, but is consistent with the broadest scope of the principles and features disclosed in this application.
[0056] Example 1: This example provides the following... Figure 1 The method for setting up a virtual electronic fence for a device based on UWB positioning is shown, and specifically includes the following steps:
[0057] S1. The central controller collects the real-time location coordinates of all UWB tags to be located through the UWB base station according to the preset scheduling frame, and obtains the signal-to-noise ratio of each UWB tag communicating with the UWB base station. It uses a density clustering algorithm to group these UWB tags. Within each group, a carrier sense multiple access conflict avoidance mechanism is used for contention access. Different groups are allocated non-overlapping time slots using time division multiple access. Each group maintains a corresponding time slot pool, stores all time slots allocated to the group in the current scheduling frame, and records the number of time slots allocated to the group in the previous scheduling frame.
[0058] S2. Extract the historical trajectory sequence for each UWB tag and input it into the pre-trained long short-term memory network model. Output the predicted location sequence for future time moments, calculate the probability of the UWB tag crossing the fence boundary and the minimum distance to the fence boundary, and define the fence threat index for each UWB tag accordingly.
[0059] S3. The central controller uses each group as a scheduling unit to construct a deep Q network agent. The state space is based on the number of UWB tags in the group, the average fence threat index and the maximum fence threat index calculated according to the fence threat index of each UWB tag obtained in step S2, the average signal-to-noise ratio of each UWB tag communicating with the UWB base station in the group, and the number of time slots allocated to the group in the previous scheduling frame. The action space is based on the time slot increment. The reward function is based on a function that comprehensively considers the time slot rewards for successful positioning, lost positioning, and high-threat groups. The output is the number of time slots that each group should obtain in the current scheduling frame.
[0060] S4. Based on the fence threat index of each UWB tag, reserve dedicated time slots from the time slot pool of its group and shorten the ranging cycle for UWB tags that are higher than the preset first threshold, and extend the ranging cycle and release the time slots for UWB tags that are lower than the preset second threshold. The released time slots are returned to the time slot pool of the group for reallocation, thus completing the secondary optimization allocation of time slots.
[0061] In this embodiment, the specific operation of the density clustering algorithm in step S1 is as follows:
[0062] First, the central controller calculates the joint distance between every two UWB tags. This joint distance is obtained by a weighted sum of two parts: the first part is the Euclidean distance between the real-time location coordinates of the two UWB tags multiplied by a first weighting coefficient; the second part is the absolute value of the difference between the reciprocals of the signal-to-noise ratios of the two UWB tags multiplied by a second weighting coefficient. The sum of the first and second weighting coefficients is equal to one. The first weighting coefficient is set to 0.7, and the second weighting coefficient is set to 0.3. Experiments have verified in typical indoor environments that this setting ensures that the spatial clustering of tags within a group is consistent with signal quality. To achieve an optimal balance, the joint distance is calculated as follows: The central controller reads the two-dimensional position coordinates of each UWB tag, calculates the square root of the sum of the squares of the differences between the two coordinates to obtain the Euclidean distance; simultaneously, it reads the signal-to-noise ratio (SNR) value of each UWB tag, calculates its reciprocal, and then calculates the absolute value of the difference between the two reciprocals; the Euclidean distance is multiplied by 0.7, the absolute value of the difference between the reciprocals of the SNR is multiplied by 0.3, and the products of the two items are added together to obtain the joint distance between the two UWB tags; the smaller the joint distance, the more similar the two tags are in terms of space and signal quality, and the more suitable they are to be grouped into the same group;
[0063] Then, the central controller calculates the exclusive neighborhood radius for each UWB tag. The exclusive neighborhood radius is equal to a pre-set base radius multiplied by an adjustment factor. The adjustment factor is one plus a preset adjustment coefficient multiplied by the ratio of the difference between the UWB tag's signal-to-noise ratio and the maximum signal-to-noise ratio among all UWB tags in the current scheduling frame, divided by the difference between the maximum value and the minimum signal-to-noise ratio among all UWB tags in the current scheduling frame. The base radius is set to three meters, and the adjustment coefficient is set to 0.5. The calculation process for the exclusive neighborhood radius is as follows: the central controller traverses all UWB tags in the current scheduling frame and finds the maximum and minimum signal-to-noise ratios; for each UWB tag... For a UWB tag, the difference between its signal-to-noise ratio (SNR) and the maximum value is calculated, then divided by the difference between the maximum and minimum values to obtain a normalized difference value between zero and one. This normalized difference value is multiplied by an adjustment factor of 0.5, and then one is added to obtain an adjustment factor. The base radius of three meters is multiplied by this adjustment factor to obtain the exclusive neighborhood radius of the UWB tag. This formula allows UWB tags with lower SNR to obtain a larger neighborhood radius, making it easier to attract surrounding tags to form larger groups to meet the retransmission requirements of weak signal tags. UWB tags with higher SNR obtain a smaller neighborhood radius, making the groups more compact and reducing unnecessary time slot waste.
[0064] Finally, the central controller uses the joint distance as the distance metric and the exclusive neighborhood radius of each UWB tag as its own neighborhood radius to run the DBSCAN clustering algorithm. This groupings all density-reachable UWB tags into the same group and separates UWB tags not covered by any principal point into a separate group. The specific execution steps of the DBSCAN clustering algorithm are as follows: First, the central controller marks all UWB tags as unvisited. Second, it randomly selects an unvisited UWB tag as the current point, searches for all other UWB tags within its exclusive neighborhood radius, and counts the number of these tags. If the number is greater than or equal to the minimum sample point size, the current point is marked as the principal point, and a new group is created starting from this current point. Otherwise, the current point is temporarily marked as a noise point; the third step is to add all unvisited tags within its neighborhood radius to the candidate queue of the current group for each UWB tag marked as a main point, and recursively expand the queue until it is empty; the fourth step is to repeat the second and third steps until all UWB tags have been visited; the fifth step is to group all UWB tags marked as noise points into separate groups; the minimum number of sample points is two to ensure that even if there are only two tags, a group can be formed, while avoiding a single tag being incorrectly assigned to a large group; each group output by this clustering process contains a set of UWB tags that are highly similar in space and signal quality, laying the foundation for subsequent intra-group competitive access and inter-group time-division multiplexing;
[0065] In step S1, the specific operations of maintaining a corresponding time slot pool for each group and recording the number of time slots allocated to each group in the previous scheduling frame are as follows:
[0066] The central controller allocates the total available time slots of the current scheduling frame based on the number of UWB tags in each packet, according to the ratio of the number of UWB tags in each packet to the total number of UWB tags in all packets. This results in the initial time slot pool capacity for each packet. The total available time slots of the current scheduling frame are preset by the system frame structure, for example, one hundred time slots. The central controller first counts the total number of UWB tags in all packets, then for each packet, it calculates the ratio of the number of UWB tags in that packet to the total number, multiplies it by one hundred, and finally... Rounding down gives the initial time slot pool capacity for the group. For example, if there are three groups with 20, 30, and 50 tags respectively, the total number is 100. The proportions of each group are 0.2, 0.3, and 0.5, and the initial time slot pool capacities are 20, 30, and 50 time slots respectively. The rounding down operation ensures that the sum of the initial time slot pool capacities of all groups does not exceed the total number of available time slots. If the sum is less than 100 due to rounding down, the remaining time slots are replenished by the central controller in descending order of the number of tags in the group until all time slots are used up.
[0067] Meanwhile, the central controller records the number of time slots allocated to each packet in the previous scheduling frame. For the first scheduling frame, the initial time slot pool capacity of the packet is used as the number of time slots allocated in the previous scheduling frame. The central controller maintains a variable in memory for each packet to store the number of time slots allocated to the packet in the previous scheduling frame. At the beginning of the first scheduling frame, this variable has no historical value, so it is directly assigned the initial time slot pool capacity calculated for the current scheduling frame. Starting from the second scheduling frame, this variable is updated at the end of each frame to the number of time slots actually allocated and used in the current frame, so that the deep Q network scheduling of the next frame can use it.
[0068] Subsequently, UWB tags within each group compete for time slots in the group's time slot pool through a carrier sense multiple access (CMA) collision avoidance mechanism. Different groups occupy their respective time slot blocks sequentially according to time division multiple access (TDMA), without overlap. Before sending a ranging request, each UWB tag in a group listens to whether the channel is idle. If idle, it sends immediately; if busy, it backs off randomly for a period of time and then retryes. The backoff time uses a binary exponential backoff algorithm, with an initial backoff window of sixteen time slot units and a maximum backoff window of one thousand and twenty-four time slot units. Between different groups, the central controller allocates a continuous time slot block to each group in ascending order of group number. The length of the time slot block is equal to the time slot pool capacity of the current scheduling frame for that group. The time slot blocks between groups strictly do not overlap on the time axis, thus completely eliminating cross-group signal collisions. This hybrid access mechanism retains the flexibility of intra-group contention for access while ensuring global controllability and fairness through inter-group time division multiplexing.
[0069] In this embodiment, it is specifically necessary to explain the specific operation of extracting the historical trajectory sequence and inputting it into the pre-trained long short-term memory network model in step S2:
[0070] For each UWB tag, the central controller extracts the location records within a preset number of scheduling frames to form a historical trajectory sequence. The preset number of scheduling frames is 10, meaning the central controller stores the location coordinates of each UWB tag in the most recent 10 scheduling frames. If a tag has just been added to the system and the historical record is less than 10 frames, the current frame position is used to fill the remaining 10 frames. The method for extracting location records is as follows: the central controller reads the positioning result of each UWB tag at the end of each scheduling frame from the local cache. The positioning result is calculated by the UWB base station using a bilateral ranging algorithm, and includes the horizontal and vertical coordinates in meters with centimeter-level accuracy.
[0071] Simultaneously, the velocity scalar and heading angle of each historical scheduling frame are calculated, and the position coordinates, velocity scalar, and sine and cosine values of the heading angle are concatenated into a multi-dimensional feature vector. The velocity scalar is calculated as follows: for each historical scheduling frame, the Euclidean distance between the position coordinates of this frame and the position coordinates of the previous frame is calculated, and then divided by the scheduling frame interval time, which is 0.1 seconds. The heading angle is calculated using the arctangent function, with the input being the difference between the ordinate and the abscissa, and the output range being from -π to π radians. Then, the sine and cosine values of the heading angle are taken respectively to eliminate the problem of angle jumps near 0 degrees and 360 degrees. The final multi-dimensional feature vector consists of five components: abscissa, ordinate, velocity scalar, sine of the heading angle, and cosine of the heading angle, forming a five-dimensional vector. This five-dimensional vector completely describes the motion state of the UWB tag within a single historical scheduling frame.
[0072] The multidimensional feature vectors are input sequentially into a pre-trained Long Short-Term Memory (LSTM) network model. The LSM network model consists of two LSM hidden layers and one fully connected layer, outputting the predicted position offset for a predetermined number of future time steps. The specific structure and training process of the LSM network model are as follows: The input layer accepts a 10x5 tensor, representing 10 time steps, with 5 features per time step; the first LSM hidden layer contains 128 neurons, using a hyperbolic tangent activation function to return the complete sequence; the second LSM hidden layer also contains 128 neurons, returning only the output of the last time step; subsequently, a fully connected layer containing 8 neurons is connected. The model outputs the predicted position offset for the next four time steps, with each time step containing the horizontal and vertical offsets, for a total of eight values. Model training utilizes 100,000 historically collected real UWB tag trajectory data points. Each trajectory contains position records for 14 consecutive scheduling frames. The first 10 frames are used as input, and the mean squared error between the actual and predicted positions in the last four frames is used as the loss function. The Adam optimizer is employed, with a learning rate of 0.001, a batch size of 64, and 100 training epochs. The training data covers various typical motion modes, including straight-line motion, constant-speed turning, acceleration straight-line movement, and deceleration stopping, and a small amount of random noise is added to simulate measurement errors and enhance model robustness.
[0073] The central controller accumulates the predicted position offset of each time step to the position coordinates of the current scheduling frame to obtain the predicted position coordinates of each future time step, forming a sequence of predicted positions for future moments. The specific accumulation process is as follows: the predicted position coordinate of the first future time step is equal to the position coordinate of the current scheduling frame plus the predicted position offset of the first time step; the predicted position coordinate of the second future time step is equal to the position coordinate of the current scheduling frame plus the sum of the predicted position offsets of the first and second time steps; and so on, the predicted position coordinate of the fourth future time step is equal to the position coordinate of the current scheduling frame plus the sum of the predicted position offsets of all four time steps; the resulting predicted position sequence contains the position coordinates of four future time steps, each coordinate containing an x-coordinate and a y-coordinate, in meters, with a time interval of 0.1 seconds, covering the motion trajectory for the next 0.4 seconds;
[0074] The specific steps in step S2 to calculate the probability of a UWB tag crossing the fence boundary and the minimum distance to the fence boundary, and to define the fence threat index, are as follows:
[0075] For each predicted location in the predicted location sequence of each UWB tag, the central controller uses a ray-mapping method to determine whether the predicted location is outside the virtual fence boundary. If it is outside, it is recorded as a crossing event. The specific steps of the ray-mapping method are as follows: a horizontal ray is emitted to the right from the predicted location point to be judged, and the number of intersections between the ray and all line segments of the virtual fence boundary is counted. The virtual fence boundary consists of a set of line segments connected end to end, and each line segment is defined by the coordinates of its two endpoints. If the ray intersects a line segment and the intersection point is not at the endpoint of the line segment, the count is incremented by one. If the intersection point is exactly at the endpoint of the line segment, special handling is required to avoid double counting. Specifically, the intersection point is counted only when the endpoint is the endpoint with the higher ordinate in the line segment. Finally, if the total number of intersection points is odd, the predicted location is determined to be outside the fence, and the crossing flag is recorded as 1; if it is even, the location is determined to be inside the fence, and the crossing flag is recorded as 0.
[0076] An exponentially weighted average is calculated for all crossing events, with a higher weight for predicted positions that are temporally closer to the current scheduling frame than for predicted positions that are temporally farther away. This yields the crossing probability of the UWB tag. The specific calculation process for the exponentially weighted average is as follows: First, a weight is assigned to the crossing tag at each future time step. The weight is calculated using an exponential function with the natural constant e as the base. The time step number with a negative exponent is divided by a decay constant, which is 2. The weight for the first future time step is e raised to the power of -0.5, approximately equal to 0.6. 0.65; the weight of the second future time step is e raised to the power of -1, approximately 0.3679; the weight of the third future time step is e raised to the power of -1.5, approximately 0.2231; the weight of the fourth future time step is e raised to the power of -2, approximately 0.1353; then the four crossing flags are multiplied by their corresponding weights and summed, then divided by the sum of the four weights to obtain the final crossing probability; the crossing probability ranges from 0 to 1, and the larger the value, the higher the probability that the UWB tag will cross the virtual fence boundary within the next 0.4 seconds;
[0077] Simultaneously, the shortest Euclidean distance from each predicted location to the virtual fence boundary is calculated, and the minimum value within the entire prediction window is taken as the minimum distance of the UWB tag from the fence boundary. The method for calculating the shortest Euclidean distance is as follows: for each predicted location, calculate the shortest distance from that point to each line segment of the virtual fence boundary, and take the minimum value among them; the method for calculating the shortest distance from a point to a line segment is as follows: first, calculate the foot of the perpendicular from the point to the line containing the line segment. If the foot of the perpendicular falls on the line segment, the distance is the length of the perpendicular line; if the foot of the perpendicular falls on the extension of the line segment, the distance is the distance from the point to the closer of the two endpoints of the line segment; after calculating the shortest distance for all four predicted locations, take the minimum value among these four distances as the minimum distance of the UWB tag from the fence boundary within the entire prediction window, in meters;
[0078] Finally, the crossing probability is multiplied by an exponential decay function with the minimum distance as the variable to obtain the fence threat index of the UWB tag. The smaller the minimum distance, the larger the value of the exponential decay function. The specific form of the exponential decay function is: an exponential function with the natural constant e as the base, where the minimum distance with a negative exponent is divided by a scale parameter, which is 0.5 meters. When the minimum distance is 0 meters, the exponential decay function has a value of 1; when the minimum distance is 0.5 meters, the exponential decay function has a value of e to the power of -1, approximately equal to 0.3679; when the minimum distance is 1 meter, the exponential decay function has a value of e to the power of -2. The fence threat index is approximately equal to 0.1353. It is equal to the cross-cross probability multiplied by the value of the exponential decay function, and its value ranges from 0 to 1. The physical meaning of this index is that the fence threat index will only increase significantly when the UWB tag has both a high cross-cross probability and is very close to the fence boundary. If the tag has a high cross-cross probability but is far from the fence, or is very close but has a low cross-cross probability, the fence threat index will be suppressed. The purpose of this design is to avoid allocating resources to tags far from the fence too early and to avoid overreacting to tags that are stationary near the fence, thereby achieving precise resource allocation.
[0079] In this embodiment, it is specifically necessary to explain the specific structure of the state space in step S3 as follows:
[0080] The central controller uses each group as a scheduling unit to construct a deep Q-network agent. The specific construction process of the deep Q-network agent is as follows: The central controller maintains a deep neural network consisting of an input layer, three fully connected hidden layers, and an output layer. The number of neurons in the input layer is equal to the total dimension of the state vectors of all groups, i.e., the total number of groups multiplied by 5. The first hidden layer contains 256 neurons with a rectified linear unit activation function; the second hidden layer contains 128 neurons with a rectified linear unit activation function; the third hidden layer contains 64 neurons with a rectified linear unit activation function. The number of neurons in the output layer is equal to the total number of combinations of joint actions of all groups. However, since the joint action space grows exponentially with the number of groups, a strategy of independent decision-making for each group is actually adopted: that is, an independent sub-network is used for each group. The input of each sub-network is its own 5-dimensional state vector, and the output is 5 Q-values, corresponding to 5 possible time-slot increment actions. The structure of each sub-network is: input layer 5... The network consists of 64 neurons in the first hidden layer, 32 neurons in the second hidden layer, and 5 neurons in the output layer. All sub-networks share the same experience replay buffer and target network. The experience replay buffer capacity is set to 1000 transition samples for scheduling frames. Each transition sample contains the state vectors of all groups in the current frame, the actions selected by all groups, the reward value of the current frame, and the state vectors of all groups in the next frame. During training, 64 samples are randomly sampled each time, using mean squared error as the loss function, Adam as the optimizer, and a learning rate of 0.001. Every 100 scheduling frames, the parameters of the current network are copied to the target network to stabilize the training process. At the beginning of each scheduling frame, the deep Q-network agent selects an action for each group based on the current state. The selection method adopts an ε-greedy strategy: randomly selecting an action with probability ε, and selecting the action with the largest output Q value of the current network with probability 1-ε. The initial value of ε is set to 1.0, and it decays linearly to 0.01 as the training progresses, with a decay step of 5000 scheduling frames.
[0081] The state vector consists of five components: the number of UWB tags in each group, the average fence threat index and the maximum fence threat index calculated based on the fence threat index of each UWB tag obtained in step S2, the average signal-to-noise ratio of communication between each UWB tag and the UWB base station within the group, and the number of time slots allocated to the group in the previous scheduling frame.
[0082] The average fence threat index is the sum of the fence threat indices of all UWB tags in the group divided by the number of UWB tags in the group, and the maximum fence threat index is the maximum value among all UWB tags in the group.
[0083] The central controller performs min-max normalization on each component in the state vector, ensuring that the value of each component falls between zero and one. Normalization is calculated using the maximum and minimum values of the components across all packets in the current scheduling frame. The specific calculation process for min-max normalization is as follows: For each packet, the first component in its state vector, i.e., the number of UWB tags, is extracted. All packets in the current scheduling frame are scanned to find the maximum and minimum values of this component. Then, the following operation is performed on this component of the packet: the original value of this component is subtracted from the minimum value of this component across all packets, and then divided by the difference between the maximum and minimum values of this component across all packets. If the maximum value equals the minimum value, then normalization is performed. The normalized value is directly set to zero; the same operation is performed on the remaining four components of the state vector in turn; the five normalized components together constitute the standard state vector of the group, which is used as input to the deep Q network; for example, assuming that there are three groups in the current scheduling frame with 20, 30 and 50 UWB labels respectively, the maximum value is 50 and the minimum value is 20; for the group with 30 labels, its normalized value is (30 minus 20) divided by (50 minus 20) equals 10 divided by 30, which is approximately 0.333; the normalization of other components is similar; this normalization operation eliminates the adverse effects of different dimensions and numerical ranges on neural network training, making all state components have the same scale;
[0084] The specific operations for updating the action space and time slot constraints in step S3 are as follows:
[0085] The central controller defines a discrete set of actions for each group. The set of actions contains five possible time slot increment values, namely -2, -1, zero, +1, and +2, with the unit being the number of time slots.
[0086] After the central controller selects the time slot increment for each group based on the current state, it adds the time slot increment to the number of time slots allocated to the group in the previous scheduling frame to obtain the initial number of time slots that the group should obtain in the current scheduling frame. Then, it compares the initial number of time slots with the minimum number of time slots and takes the larger value as the final number of time slots for the group.
[0087] The central controller further verifies whether the sum of the final timeslots of all groups exceeds the total number of available timeslots in the current scheduling frame. If it does, the number of timeslots is reduced proportionally to the final timeslots of each group until the sum equals the total number of available timeslots.
[0088] The number of time slots after verification and reduction is used as the number of time slots each group should receive in the current scheduling frame. The detailed verification and reduction process is as follows: Assume the total number of available time slots in the current scheduling frame is 100. The central controller first calculates the sum of the final time slot numbers for all groups. If this sum is less than or equal to 100, the final time slot number is used directly as the allocation result. If the sum is greater than 100, the reduction ratio is calculated, which is equal to 100 divided by the sum of the final time slot numbers for all groups. Then, the final time slot number for each group is multiplied by the reduction ratio and rounded down to obtain the initially reduced number of time slots. At this point, the sum of the initially reduced time slot numbers for all groups may be less than 100. The central controller then adds a time slot to each group sequentially, according to the group number in ascending order, until the total number of time slots is exactly 100. For example, assuming the final number of time slots for three groups are 40, 50, and 30 respectively, the total is 120, which exceeds 100. The reduction ratio is 100 divided by 120, which is approximately 0.8333. The initial values after reduction are 33, 41, and 25 respectively, with a total of 99. Then, according to the group number order, the first group is added by 1 to become 34, and the total becomes 100, at which point the allocation stops. The final allocation result is 34, 41, and 25. This mechanism ensures that the total number of time slots does not exceed the system capacity under any circumstances, while maintaining the proportional relationship of the deep Q network output as much as possible.
[0089] The reward function in step S3 is specifically structured as follows:
[0090] The central controller calculates the reward value after each scheduling frame ends. The reward value is obtained by weighted summation of three parts. The first part is the positioning success reward, which is equal to the number of UWB tags that successfully completed ranging and positioning in the current scheduling frame divided by the total number of all UWB tags.
[0091] The second part is the lost location penalty, which is equal to the negative of the number of UWB tags that failed to complete ranging due to insufficient time slots in the current scheduling frame, divided by the total number of all UWB tags.
[0092] The third part is the high-threat group time slot reward. For each group, if the group's average fence threat index is greater than the average of all groups' average fence threat indices, a positive reward is calculated based on the difference between the group's actual time slot increment and the group's average fence threat index minus the average of all groups' average fence threat indices. The average of all groups' positive rewards is taken as the third part. The sum of the weight coefficients of the three parts equals one. The specific values of the weight coefficients and the detailed calculation process of the third part are as follows: the three weight coefficients are set to 0.4, 0.3, and 0.3 respectively, that is, the location success reward accounts for 40%, the location loss penalty accounts for 30%, and the high-threat group time slot reward accounts for 30%. The calculation of the high-threat group time slot reward is divided into the following steps: First, the central controller calculates the average of all groups' average fence threat indices, that is, the average fence threat index of all groups... The first step is to divide the sum of the values of all groups by the total number of groups. The second step is to iterate through each group. If the average fence threat index of the group is greater than the global average, the threat deviation of the group is calculated. The threat deviation is equal to the average fence threat index of the group minus the global average, and then divided by the largest average fence threat index among all groups minus the global average, to obtain a normalized value between zero and one. The third step is to normalize the actual slot increment of the group by 2 (because the slot increment ranges from -2 to +2, dividing by 2 maps it to -1 to +1). The fourth step is to multiply the normalized slot increment by the threat deviation to obtain the positive reward component of the group. If the average fence threat index of the group is not greater than the global average, the positive reward component of the group is set to zero. The fifth step is to sum the positive reward components of all groups and then divide by the total number of groups to obtain the final value of the slot reward for the high-threat group.
[0093] For example, suppose there are two groups with average fence threat indices of 0.8 and 0.3 respectively, a global average of 0.55, and a maximum of 0.8. The threat deviation of the first group is (0.8 minus 0.55) divided by (0.8 minus 0.55) equals 1.0. If its time slot increment is +2, then after normalization it becomes 1.0, and the positive reward component is 1.0 multiplied by 1.0 equals 1.0. The second group does not meet the condition, and the positive reward component is 0. Then the time slot reward for the high-threat group is equal to (1.0 plus 0) divided by 2, which equals 0.5. This reward mechanism encourages the deep Q network agent to allocate additional time slots to groups with threat levels higher than the average level. The greater the threat deviation and the more time slots added, the higher the reward, thereby guiding the agent to prioritize the positioning needs of high-risk areas.
[0094] In this embodiment, the specific operation of secondary optimization allocation of time slots based on the fence threat index of each UWB tag in step S4 is as follows:
[0095] The central controller presets a first threshold and a second threshold, with the first threshold being greater than the second. The first threshold is set to 0.75, and the second threshold to 0.25. This threshold selection is based on extensive field test data: when the first threshold is set to 0.75, it effectively filters out tags with a truly high risk of crossing the boundary, while avoiding misjudgments of normally moving tags; when the second threshold is set to 0.25, it can promptly reduce the frequency of tags that have been inside the fence for a long time and move slowly, freeing up idle time slots; the 0.5-point gap between the two thresholds provides sufficient buffer space for tags with moderate threats, preventing tags from frequently switching states at the threshold boundaries; the central controller will then control the fence's perimeter. UWB tags with a threat index greater than the first threshold are classified into a high-threat tag set, while UWB tags with a fence threat index less than the second threshold are classified into a low-threat tag set. The specific operation of the classification process is as follows: The central controller traverses all UWB tags in the current scheduling frame, reads the fence threat index value of each tag, and if the value is greater than 0.75, the tag's identifier is added to the high-threat tag list; if the value is less than 0.25, the tag's identifier is added to the low-threat tag list; the remaining tags are assigned to the medium-threat tag list, maintaining the default scheduling policy; all three lists are stored in the central controller's memory for subsequent steps to call.
[0096] For each UWB tag in the high-threat tag set, the central controller calculates the number of reserved dedicated time slots. The number of reserved dedicated time slots is equal to the preset reserved strength coefficient multiplied by the difference between the UWB tag's fence threat index and the first threshold, divided by 1 minus the difference between the first threshold and the preset maximum number of reserved time slots, and then rounded up. Simultaneously, the ranging period of the UWB tag is shortened from the base period to the base period divided by a preset period shortening factor. The reserved strength coefficient is set to 0.8, the maximum number of reserved time slots is set to 2, and the period shortening factor is 2. The base period is equal to the duration of one scheduling frame, i.e., 0.1 seconds. The specific calculation process for the number of reserved dedicated time slots is as follows: First, calculate the difference between the tag's fence threat index and the first threshold of 0.75. Then, calculate 1 minus the first threshold of 0.75 equals 0.25. Divide the former by the latter to obtain a normalized ratio between 0 and 1. Multiply this ratio by the reserved strength coefficient of 0.8, and then multiply by the maximum number of reserved time slots of 2 to obtain a decimal. Round up this decimal. The process involves rounding up the data to obtain the final number of reserved dedicated time slots. For example, if the fence threat index of a high-threat tag is 0.9, the difference between it and the first threshold is 0.15. Dividing this by 0.25 gives 0.6, multiplying by 0.8 gives 0.48, multiplying by 2 gives 0.96, and rounding up gives 1, meaning one dedicated time slot is reserved for this tag. If the fence threat index is 1.0, the difference is 0.25. Dividing this by 0.25 gives 1, multiplying by 0.8 gives 0.8, multiplying by 2 gives 1.6, and rounding up gives 2, meaning one dedicated time slot is reserved. Two dedicated time slots are allocated; rounding up ensures that at least one time slot is reserved even if the normalization ratio is very small, preventing high-threat tags from relying entirely on contention; at the same time, the ranging period of this tag is shortened from 0.1 seconds to 0.1 seconds divided by two equals 0.05 seconds, that is, two rangings are performed within each scheduling frame, with each ranging occupying one time slot, and the two reserved time slots just meet the requirements of two rangings; if only one time slot is reserved, the second ranging still needs to be obtained through contention, but the reserved time slots guarantee at least one successful ranging.
[0097] For each UWB tag in the low-threat tag set, the central controller calculates its release slot count. The release slot count is equal to the ratio of the preset release strength coefficient multiplied by the second threshold minus the UWB tag's fence threat index, divided by the second threshold, multiplied by the preset maximum release slot count, and rounded down. Simultaneously, the UWB tag's ranging period is extended to a base period multiplied by a preset period extension factor, where the base period equals the duration of one scheduling frame. The release strength coefficient is set to 0.6, the maximum release slot count is set to 1, and the period extension factor is set to 3. The specific calculation process for the release slot count is as follows: First, calculate the difference between the second threshold of 0.25 and the tag's fence threat index, then divide by the second threshold of 0.25 to obtain a normalized ratio between zero and one; multiply this ratio by... The release intensity coefficient is 0.6, multiplied by the maximum number of release slots (1), resulting in a decimal. This decimal is then rounded down to obtain the final number of release slots. For example, if the fence threat index of a low-threat tag is 0.1, the second threshold minus this value is 0.15, divided by 0.25 to get 0.6, multiplied by 0.6 to get 0.36, multiplied by 1 to get 0.36, and rounded down to 0, meaning the tag does not release slots. If the fence threat index is 0.0, the difference is 0.25, divided by 0.25 to get 1, multiplied by 0.6 to get 0.6, multiplied by 1 to get 0.6, and rounded down to 0, still no release. This is because of the rounding down property; slots can only be released when the normalization ratio is sufficiently large. In reality, for a low-threat tag to release slots, the fence threat index needs to be sufficiently low.
[0098] For example, if the fence threat index is 0.05, the difference is 0.20. Dividing by 0.25 gives 0.8, multiplying by 0.6 gives 0.48, multiplying by 1 gives 0.48, and rounding down still gives 0. Only when the fence threat index is below approximately 0.0417 can a normalized product above 0.6 be obtained, thus rounding down to 1. This design ensures that only tags with extremely low threats will release time slots, avoiding frequent releases that could lead to location interruptions. At the same time, the ranging period of this tag is extended from 0.1 seconds to 0.1 seconds multiplied by 3 equals 0.3 seconds, meaning ranging is performed once every three scheduling frames. Within the current scheduling frame, it does not occupy any time slots, thus releasing one time slot to return to the group time slot pool. If the number of released time slots is zero, the ranging period is still extended, but the tag does not participate in contention within the current frame, which is equivalent to passively releasing a time slot that might have been occupied.
[0099] The central controller updates the actual time slot pool capacity of each group based on the total number of reserved dedicated time slots for high-threat labels and the total number of released time slots for low-threat labels within each group. The actual time slot pool capacity equals the number of time slots obtained by the group in step S3 minus the total number of reserved dedicated time slots plus the total number of released time slots. Reserved dedicated time slots are pre-allocated from the time slot pool for exclusive use by high-threat labels, while released time slots are returned to the time slot pool for reallocation. The specific operation process for updating the actual time slot pool capacity is as follows: The central controller first iterates through each group, counting the sum of the number of reserved dedicated time slots for all high-threat labels and the sum of the number of released time slots for all low-threat labels within the group. Then, it subtracts the total number of reserved dedicated time slots from the number of time slots output in step S3 and adds the total number of released time slots to obtain the actual time slot pool capacity for the group. For example, assuming a group obtains twenty time slots in step S3, the... Within a group, there are three high-threat labels, with reserved dedicated time slots 1, 2, and 1, for a total of four. There are two low-threat labels, with released time slots 1 and 0, for a total of one. Therefore, the actual time slot pool capacity equals 20 minus 4 plus 1, which equals 17 time slots. The central controller places these 17 time slots into the group's time slot pool, allowing medium-threat labels and high-threat labels that haven't received reserved time slots to compete for them via the carrier sense multiple access conflict avoidance mechanism. Simultaneously, the four reserved dedicated time slots are allocated from the time slot pool, assigned fixed time slot positions on the time axis, and exclusively used by the corresponding three high-threat labels, preventing other labels from occupying them. The released time slot has been added to the time slot pool and is available for other labels to compete for. This secondary optimization allocation mechanism ensures deterministic access for high-threat labels, releases redundant resources for low-threat labels, improves the competitive environment for medium-threat labels, and significantly enhances overall time slot utilization.
[0100] Example 2: This example provides the following... Figure 2 The system shown is a virtual electronic fence setting system for devices based on UWB positioning, specifically including:
[0101] Time slot initialization module: The central controller collects the real-time location coordinates and signal-to-noise ratio of all UWB tags to be located through the UWB base station according to the preset scheduling frame, and uses a density clustering algorithm to group the tags. Within each group, the carrier sense multiple access conflict avoidance mechanism competes for access, and the time division multiple access allocates non-overlapping time slots between groups. It also maintains a time slot pool for each group and records the number of time slots allocated in the previous frame.
[0102] Threat assessment module: The central controller extracts historical trajectory sequences for each UWB tag and inputs them into a pre-trained long short-term memory network model, outputting a future predicted location sequence. Based on this, it calculates the probability of crossing the fence boundary and the minimum distance, and defines the fence threat index for each tag.
[0103] The time slot dynamic allocation module: The central controller constructs a deep Q network agent with each group as the scheduling unit. The state is based on the number of tags in the group, the average and maximum fence threat index, the average signal-to-noise ratio, and the number of time slots in the previous frame. The action is the time slot increment. The reward function is the time slot reward for successful positioning, lost positioning, and high-threat group. The output is the number of time slots that each group should get in the current frame.
[0104] Secondary time slot optimization module: Based on the fence threat index of each tag, the central controller reserves a dedicated time slot from the time slot pool of its group and shortens the ranging cycle for tags with a value higher than the first threshold, and extends the ranging cycle and releases the time slot for tags with a value lower than the second threshold. The released time slot is returned to the time slot pool, thus completing the secondary time slot optimization allocation.
[0105] It should be noted that the descriptions of each embodiment in the above embodiments have different focuses. For parts that are not described in detail in a certain embodiment, please refer to the relevant descriptions in other embodiments.
[0106] Those skilled in the art will understand that embodiments of the present invention can be provided as methods, systems, or computer program products. Therefore, the present invention can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present invention can take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0107] This invention is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded computer, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart illustrations. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0108] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0109] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0110] Although preferred embodiments of the invention have been described, those skilled in the art, upon learning the basic inventive concept, can make other changes and modifications to these embodiments. Therefore, the appended claims are intended to be interpreted as including both the preferred embodiments and all changes and modifications falling within the scope of the invention.
[0111] Obviously, those skilled in the art can make various modifications and variations to this invention without departing from its spirit and scope. Therefore, if these modifications and variations fall within the scope of the claims of this invention and their equivalents, this invention also intends to include these modifications and variations.
Claims
1. A method for setting up a virtual electronic fence for a device based on UWB positioning, characterized in that, Specifically, the following steps are included: S1. The central controller collects the real-time location coordinates of all UWB tags to be located through the UWB base station according to the preset scheduling frame, and obtains the signal-to-noise ratio of each UWB tag communicating with the UWB base station. It uses a density clustering algorithm to group these UWB tags. Within each group, a carrier sense multiple access conflict avoidance mechanism is used for contention access. Different groups are allocated non-overlapping time slots using time division multiple access. Each group maintains a corresponding time slot pool, stores all time slots allocated to the group in the current scheduling frame, and records the number of time slots allocated to the group in the previous scheduling frame. S2. Extract the historical trajectory sequence for each UWB tag and input it into the pre-trained long short-term memory network model. Output the predicted location sequence for future time moments, calculate the probability of the UWB tag crossing the fence boundary and the minimum distance to the fence boundary, and define the fence threat index for each UWB tag accordingly. S3. The central controller uses each group as a scheduling unit to construct a deep Q network agent. The state space is based on the number of UWB tags in the group, the average fence threat index and the maximum fence threat index calculated according to the fence threat index of each UWB tag obtained in step S2, the average signal-to-noise ratio of each UWB tag communicating with the UWB base station in the group, and the number of time slots allocated to the group in the previous scheduling frame. The action space is based on the time slot increment. The reward function is based on a function that comprehensively considers the time slot rewards for successful positioning, lost positioning, and high-threat groups. The output is the number of time slots that each group should obtain in the current scheduling frame. S4. Based on the fence threat index of each UWB tag, reserve dedicated time slots from the time slot pool of its group and shorten the ranging cycle for UWB tags that are higher than the preset first threshold, and extend the ranging cycle and release the time slots for UWB tags that are lower than the preset second threshold. The released time slots are returned to the time slot pool of the group for reallocation, thus completing the secondary optimization allocation of time slots.
2. The method for setting up a virtual electronic fence for a device based on UWB positioning according to claim 1, characterized in that: The specific operation of the density clustering algorithm in step S1 is as follows: First, the central controller calculates the joint distance between every two UWB tags. The joint distance is obtained by weighted summation of two parts. The first part is the Euclidean distance between the real-time position coordinates of the two UWB tags multiplied by a first weighting coefficient. The second part is the absolute value of the difference between the reciprocals of the signal-to-noise ratios of the two UWB tags multiplied by a second weighting coefficient. The sum of the first weighting coefficient and the second weighting coefficient is equal to one. Then, the central controller calculates the exclusive neighborhood radius for each UWB tag. The exclusive neighborhood radius is equal to the preset base radius multiplied by an adjustment factor. The adjustment factor is one plus a preset adjustment coefficient multiplied by the difference between the signal-to-noise ratio of the UWB tag and the maximum signal-to-noise ratio among all UWB tags in the current scheduling frame, divided by the difference between the maximum value and the minimum signal-to-noise ratio among all UWB tags in the current scheduling frame. Finally, the central controller uses the joint distance as the distance metric and the exclusive neighborhood radius of each UWB tag as its neighborhood radius. It then runs the DBSCAN clustering algorithm to group all density-reachable UWB tags into the same group and separate UWB tags not covered by any principal point into a separate group.
3. The method for setting up a virtual electronic fence for a device based on UWB positioning according to claim 2, characterized in that: In step S1, the specific operations of maintaining a corresponding time slot pool for each group and recording the number of time slots allocated to each group in the previous scheduling frame are as follows: The central controller allocates the total number of available time slots in the current scheduling frame based on the number of UWB tags in each group within the current scheduling frame, according to the proportion of the number of UWB tags in each group to the total number of UWB tags in all groups. This results in the initial time slot pool capacity for each group. Simultaneously, the central controller records the number of time slots allocated to each group in the previous scheduling frame. For the first scheduling frame, the initial time slot pool capacity of the group is used as the number of time slots allocated in the previous scheduling frame. Subsequently, the UWB tags within each packet compete for the use of time slots in the packet's time slot pool through the carrier sense multiple access conflict avoidance mechanism, and different packets occupy their respective time slot blocks in turn according to the time division multiple access method, without overlapping.
4. The method for setting up a virtual electronic fence for a device based on UWB positioning according to claim 3, characterized in that: The specific steps for extracting historical trajectory sequences and inputting them into the pre-trained Long Short-Term Memory (LSTM) network model in step S2 are as follows: For each UWB tag, the central controller extracts the location records within a preset number of scheduling frames in the past to form a historical trajectory sequence; Simultaneously, the velocity scalar and heading angle of each historical scheduling frame are calculated, and the sine and cosine values of the position coordinates, velocity scalar, and heading angle are concatenated into a multi-dimensional feature vector; The multidimensional feature vectors are input into the pre-trained Long Short-Term Memory (LSTM) network model in chronological order. The LSM network model contains two LSM hidden layers and one fully connected layer, and outputs the predicted position offsets for a preset number of future time steps. The central controller accumulates the predicted position offsets of each time step to the position coordinates of the current scheduling frame to obtain the predicted position coordinates of each future time step, forming a sequence of predicted positions for future moments.
5. The method for setting up a virtual electronic fence for a device based on UWB positioning according to claim 4, characterized in that: The specific steps in step S2 to calculate the probability of a UWB tag crossing the fence boundary and the minimum distance to the fence boundary, and to define the fence threat index, are as follows: For each predicted location in the predicted location sequence of each UWB tag, the central controller uses the ray casting method to determine whether the predicted location is outside the virtual fence boundary. If it is outside, it is recorded as a crossing event. An exponentially weighted average is calculated for all crossing events, with the weight of the predicted position that is closer to the current scheduling frame in time being higher than the weight of the predicted position that is farther away from the current scheduling frame in time, to obtain the crossing probability of the UWB tag. Simultaneously, the shortest Euclidean distance from each predicted location to the virtual fence boundary is calculated, and the minimum value within the entire prediction window is taken as the minimum distance between the UWB tag and the fence boundary. Finally, the probability of crossing is multiplied by an exponential decay function with the minimum distance as the variable to obtain the fence threat index of the UWB tag. The smaller the minimum distance, the larger the value of the exponential decay function.
6. The method for setting up a virtual electronic fence for a device based on UWB positioning according to claim 5, characterized in that: The specific structure of the state space in step S3 is as follows: The central controller uses each group as a scheduling unit to construct a deep Q network agent; it uses five components to form a state vector: the number of UWB tags in each group, the average fence threat index and the maximum fence threat index calculated based on the fence threat index of each UWB tag obtained in step S2, the average signal-to-noise ratio of each UWB tag communicating with the UWB base station within the group, and the number of time slots allocated to the group in the previous scheduling frame. The average fence threat index is the sum of the fence threat indices of all UWB tags in the group divided by the number of UWB tags in the group, and the maximum fence threat index is the maximum value among all UWB tags in the group. The central controller performs min-max normalization on each component in the state vector, so that the value of each component falls between zero and one. The normalization is calculated using the maximum and minimum values of the components in all packets within the current scheduling frame.
7. A method for setting up a virtual electronic fence for a device based on UWB positioning according to claim 6, characterized in that: The specific operations for updating the action space and time slot constraints in step S3 are as follows: The central controller defines a discrete set of actions for each group. The set of actions contains five possible time slot increment values, namely -2, -1, zero, +1, and +2, with the unit being the number of time slots. After the central controller selects the time slot increment for each group based on the current state, it adds the time slot increment to the number of time slots allocated to the group in the previous scheduling frame to obtain the initial number of time slots that the group should obtain in the current scheduling frame. Then, it compares the initial number of time slots with the minimum number of time slots and takes the larger value as the final number of time slots for the group. The central controller further verifies whether the sum of the final timeslots of all groups exceeds the total number of available timeslots in the current scheduling frame. If it does, the number of timeslots is reduced proportionally to the final timeslots of each group until the sum equals the total number of available timeslots. The number of time slots after verification and reduction is taken as the number of time slots that each group should obtain in the current scheduling frame.
8. A method for setting up a virtual electronic fence for a device based on UWB positioning according to claim 7, characterized in that: The reward function in step S3 is specifically structured as follows: The central controller calculates the reward value after each scheduling frame ends. The reward value is obtained by weighted summation of three parts. The first part is the positioning success reward, which is equal to the number of UWB tags that successfully completed ranging and positioning in the current scheduling frame divided by the total number of all UWB tags. The second part is the lost location penalty, which is equal to the negative of the number of UWB tags that failed to complete ranging due to insufficient time slots in the current scheduling frame, divided by the total number of all UWB tags. The third part is the slot reward for high-threat groups. For each group, if the average fence threat index of the group is greater than the average fence threat index of all groups, then the positive reward is calculated based on the difference between the actual slot increment obtained by the group and the average fence threat index of the group minus the average fence threat index of all groups. The average of the positive rewards of all groups is taken as the third part; the sum of the weight coefficients of the three parts is equal to one.
9. A method for setting up a virtual electronic fence for a device based on UWB positioning according to claim 8, characterized in that: The specific operation of secondary optimization allocation of time slots based on the fence threat index of each UWB tag in step S4 is as follows: The central controller presets a first threshold and a second threshold, with the first threshold being greater than the second threshold. The central controller classifies UWB tags with a fence threat index greater than the first threshold into a high-threat tag set and UWB tags with a fence threat index less than the second threshold into a low-threat tag set. For each UWB tag in the high-threat tag set, the central controller calculates the number of reserved dedicated time slots. The number of reserved dedicated time slots is equal to the preset reserved strength coefficient multiplied by the difference between the fence threat index of the UWB tag and the first threshold, divided by the difference between the first threshold and the preset maximum number of reserved time slots, and then rounded up. At the same time, the ranging period of the UWB tag is shortened from the reference period to the reference period divided by the preset period shortening factor. For each UWB tag in the low-threat tag set, the central controller calculates the number of release slots. The number of release slots is equal to the ratio of the preset release strength coefficient multiplied by the second threshold minus the difference of the UWB tag's fence threat index divided by the second threshold, multiplied by the preset maximum number of release slots, and then rounded down. At the same time, the ranging period of the UWB tag is extended to the base period multiplied by the preset period extension factor. The base period is equal to the duration of one scheduling frame. The central controller updates the actual time slot pool capacity of each group based on the total number of reserved dedicated time slots for high-threat tag sets and the total number of released time slots for low-threat tag sets within each group. The actual time slot pool capacity is equal to the number of time slots obtained by the group in step S3 minus the total number of reserved dedicated time slots plus the total number of released time slots. The reserved dedicated time slots are pre-allocated from the time slot pool for exclusive use by high-threat tags, and the released time slots are returned to the time slot pool for reallocation.
10. A device virtual electronic fence setting system based on UWB positioning, applied to the device virtual electronic fence setting method based on UWB positioning as described in any one of claims 1-9, characterized in that: Specifically, it includes: Time slot initialization module: The central controller collects the real-time location coordinates and signal-to-noise ratio of all UWB tags to be located through the UWB base station according to the preset scheduling frame, and uses a density clustering algorithm to group the tags. Within each group, the carrier sense multiple access conflict avoidance mechanism competes for access, and the time division multiple access allocates non-overlapping time slots between groups. It also maintains a time slot pool for each group and records the number of time slots allocated in the previous frame. Threat assessment module: The central controller extracts historical trajectory sequences for each UWB tag and inputs them into a pre-trained long short-term memory network model, outputting a future predicted location sequence. Based on this, it calculates the probability of crossing the fence boundary and the minimum distance, and defines the fence threat index for each tag. The time slot dynamic allocation module: The central controller constructs a deep Q network agent with each group as the scheduling unit. The state is based on the number of tags in the group, the average and maximum fence threat index, the average signal-to-noise ratio, and the number of time slots in the previous frame. The action is the time slot increment. The reward function is the time slot reward for successful positioning, lost positioning, and high-threat group. The output is the number of time slots that each group should get in the current frame. Secondary time slot optimization module: Based on the fence threat index of each tag, the central controller reserves a dedicated time slot from the time slot pool of its group and shortens the ranging cycle for tags with a value higher than the first threshold, and extends the ranging cycle and releases the time slot for tags with a value lower than the second threshold. The released time slot is returned to the time slot pool, thus completing the secondary time slot optimization allocation.
