1. Introduction
Body location and its motions are important for farm animals’ well-being and efficiency monitoring [
1]. Early alarms about dairy cow diseases, stresses and calving can be generated through analyzing untypical behavior and motions [
2,
3]. A variety of commercial systems based on tags with accelerometers provide the ability to monitor cow behavior derived from cow motions. However, these systems have a relatively high cost.
A dairy barn makes a challenging environment for localization due to the relatively high density of animals and the presence of metal structures. In order to monitor the indoor location of dairy cows, several technologies were used. Different ultra-wideband (UWB) systems were used in several studies. The Ubisense UWB system was used in [
4] with 0.5–2 m accuracy depending on the position in the barn. The ability to detect the presence of cows in 0.5–3 m areas with a sensitivity of over 70% using UWB-based Gea CowView with 3–4 years battery lifetime was reported in [
5]; the system reached the accuracy of 16 cm with static tags with worst case positioning error of several meters when tags were attached to cows. A custom setup based on Decawave UWB DW1000 chip reached a static accuracy of 38 cm [
2]. Commercial wireless local area network (WLAN) systems with 2 m of accuracy and 30 day battery lifetime was used in [
3], and with 3 m of accuracy and 1-day battery lifetime was used in [
6]. Image processing was used for cattle motion and behavior monitoring [
7]. A self-designed Bluetooth-based system was used by [
8] with 4.2 m of accuracy. Outdoor animal location was monitored by a system combining GPS tags for global positioning and BLE tags for the identification and approximate localization of animals equipped with BLE tags [
9], and a BLE-based system [
10].
The advantage of the Bluetooth Low Energy (BLE) technology is in long battery life and low sensor price. Nevertheless, the received signal strength (RSS) of BLE tags used for localization is noisy [
11]. In addition, a number of factors influencing the RSS and the accuracy of the tag localization calculated by trilateration [
12] must be taken into account: irregularity of the RSS propagation model [
11], direction of the tag headed to the receiving station [
13], cow body decreasing the RSS, barn obstacles reflecting and increasing the RSS [
14] etc., which, in general, according to the estimation of [
15], limits the accuracy of this method to 2.7 m. To compensate for these factors, various methods were applied. The RSS propagation model was studied in [
11,
16,
17]. To filter the tag positions inside a barn, median and extended Kalman filters [
4,
18], the Viterbi algorithm [
19,
20] and Bayesian filters [
21] were used. The BLE signal channels were treated separately in [
22,
23]. The developed signal propagation model included the geometry and material properties of the structures of the tag environment as well as the mapping of RSS depending on what the tag orientation was used in [
16,
24]. The RSS decreasing while passing through the dairy cow’s body was modeled [
25], and human-body signal shadowing was mitigated [
26]. Algorithms for learning the environment features were used for the localization [
27]. Information about the environment structure was used to eliminate impossible locations [
8,
19,
28]. Instead of describing the environment features, a preliminary mapping (fingerprints) of RSS from several points in the environment was performed [
10,
18,
29], though this method required time-consuming mapping, and its accuracy can be restricted by the resolution of the sampled points.
The goal of this study was to design a system for cow localization in barn environment and estimate its accuracy. We developed a system for cow location monitoring. The system includes low-cost tags attached to cow collars, which sends signals by the BLE protocol to low-cost signal receiving stations installed in a barn similar to [
30]. In this system, the RSS was received as an accompanying effect of the cow motion accelerations monitoring measured by the tags. The RSS was filtered by a moving average filter. The influence of the tag orientation on the localization was studied. The tag location was filtered by the Viterbi algorithm. The system accuracy was tested in a research barn. The data and algorithms used in this study are attached in
Supplementary Materials.
The paper is organized as follows.
Section 2 describes the structure of the localization system, experimental environment, methods used for the localization and conducted localization experiments.
Section 3 describes the tag RSS features studied in the experiments.
Section 4 presents the results of the experiments.
Section 5 specifies the localization system accuracy, analyzes the experimental results and compares them with other studies.
Section 6 summarizes the findings and proposes topics for the future research.
2. Localization System and Accuracy
2.1. System Design
The system was developed as part of a project aiming to develop a low-cost open-source system for monitoring the behavior of dairy cows using accelerometers and positioning. This paper focuses on using tags for cow localization. An open-source BLE tag (RuuviTag, Ruuvi Innovations, Porvoo, Finland) based on the nRF52832 chip (Nordic Semiconductor, Trondheim, Norway) was chosen as the platform. New firmware for measuring acceleration at 25 Hz and advertising the data was developed.
The tags packed in plastic boxes and adjusted to the cow collars on a side by a Velcro belt (
Figure 1) measured the acceleration and sent the measurements as advertising data (24-bytes packets) using the BLE 4.2 protocol. The frequency of message sending was 5 Hz. The messages from the tags were received by 10 receiving stations, which were single-board computers with Bluetooth antennae (Raspberry Pi 3 B+, Raspberry Pi Foundation, UK). The stations were packed in hermetic cases with heat dissipation ribs and installed on barn constructions on the height of 3–5 m (
Figure 1c). They were evenly distributed in the barn (
Figure 2a) to minimize the maximal distance to tags. The stations recorded the RSS, tag accelerations and receiving time. The data was stored on the station memory and was sent via a local network maintained by a router (EA7500, Linksys) by a message queuing protocol (ZeroMQ, iMatix Corporation). A PC (Intel
® Core™ i7-9750H, CPU 2.6GHz, RAM 16GB) received the messages from the microcontrollers and stored the raw data in CSV files. The data managing programs were written on C++ for the stations and C# (Microsoft, Redmond, WA, USA) for the PC.
2.2. Barn and Cows
A research barn (University of Helsinki, Viikki campus) was used for the development and validation of the system. The barn consisted of a 9.8 × 42 m
2 area (
Figure 2a) with 46 lying pens and included 24 feed intake measuring stations (Hokofarm, Marknesse, the Netherlands) and a milking robot (Astronaut, Lely, Maassluis, the Netherlands). The barn was equipped with five constantly recording cameras covering major part of the area. A group of 35 Ayrshire cows were used in the experiments. The cows were housed in a free stall barn (
Figure 2b) during the lactation period.
2.3. Localization
Considering the large number of factors influencing the RSS in the barn environment (diversity of tag and receiving stations features, tag orientation, tag occlusions depending on cow movements, multiple metal structures in the barn), we assumed that RSS fingerprint mapping or using path loss models based on the barn structure description are impractical for this application. Hence, only the RSS propagation model created in a tag feature experiment (described in
Section 3.1) was used.
The RSS propagation model (path loss log-distance model [
31]) describing the dependence between the RSS and the distance to a tag was formulated by Equation (1),
where
D was the distance between the receiving station and the tag, and
n and
A0 are the path loss exponent and the path loss constant fitted by linear regression.
Simple geometric trilateration for the tag location calculation was impractical because of high RSS noise. Hence, 10 receiving stations achieved redundant information about the tag location. The tag localization was equivalent to the solution of an optimization problem finding the tag position with minimal RSS errors for all receiving stations. The optimization problem was defined as the minimization of the localization error function
Err(
x,y):
where (
x,y) were the tag location in the barn coordinates (
Figure 2a),
RSSmes,i was RSS measured by the receiving station
i,
RSSpm(x,y)i was RSS calculated according to the propagation model (Equation (1)) depending on the distance between the receiving station
i and the tag located in the point (
x,y). This optimization problem had two variables, which were the tag coordinates in the barn. It was assumed that the height (Z coordinate) of the tag was 1.5 m and the dependence between the tag RSS and tag orientation was not taken into account.
However, during the tag characteristics experiments, we found significant variability between the RSS of different tags and receiving stations. Hence, the difference between the measured and the calculated values of RSS was expected to reflect the actual distance between the tag and the receiving station incorrectly. Assuming that the RSS propagation model for all tags has same curve shape (coefficient
n in Equation (1)) but different shift (coefficient
A0 in Equation (1)), we canceled this difference by the shifting factors. Then, the localization error function was revised as follows:
where
Nmes was a shifting factor for the measured RSS, and
Npm was a shifting factor for the RSS calculated according to the propagation model.
To make the localization process more practical, the solution for the optimization problem was replaced by finding the best fitting between the measured RSS and the RSS calculated in predefined mapping points and stored in a lookup table. The reasons were the following:
The expected accuracy of the method was lower than the barn mapping points resolution; hence, a continuous solution for the optimization problem was senseless.
A finite number of locations allows to make further analysis of the found locations and filtering them by the Viterbi algorithm, taking into account the barn structure features.
Comparison of the calculated location with the reference location achieved from videos (required intensive manual work) was more convenient with predefined points.
Optimization problem solution was in general a more time-consuming problem than a search in a lookup table. In addition, the nonlinearity of the cost function could cause multiple minima, requiring additional analysis of the function.
The number of the predefined location points (
xk,yk) was 235 for entire barn and 95 for the waiting yard. They were distributed over the barn area with a resolution of about 1 m (
Figure 2a) for entire barn and 0.5 m for the waiting yard. To create the RSS mapping of the barn, the RSS values for each station were calculated in each location point using the RSS propagation model derived from experiments and stored in a lookup table
RSSmap.
2.4. Tag Location Filtering
The level of noise of RSS and, as a result, of the tag location, makes filtering the tag location by average or medial filters inefficient. The Viterbi algorithm using the barn structure and including a Markov chain describing the probability of passages between the location points was used.
The observed states were the RSS values. The hidden states were the location in the barn mapping points. The emission matrix (P) in the Viterbi algorithm (fitting between the hidden and observed states) was replaced by a rule for calculating the probability to be located in all the mapping points. The probability of being in a point
k,
Pk, depended on the error between the
RSSmes measured by the receiving stations and
RSS(xk,yk) precalculated for all mapping points as defined in Equation (4):
To calculate the transition matrix (TM), taking into account the distance between the location points and obstacles, a map of relevant barn structures was created based on a provided barn drawing and manual measurements. TM was built according to the following rules:
TMi,i = 1 – probability to stay in the same location;
TMi,j = 0 – if there is an obstacle between the locations i and j, or distance between them dist(i,j) is more than 3 m;
TMi,j = 1/(1 + dist(i,j)) – if the previous conditions are false.
The transition matrix was normalized to provide the sum of the probabilities equal to 1.
The original RSS data were obtained with a sampling time of 0.2 s. This caused impossible passages between the location points during a single sampling time. To overcome this effect and reduce the computational effort, the RSS data was decreased by folding intervals of 5 s into a single sampling point, where the RSS value was taken as the average value on the intervals.
The entire process for the tag localization is presented in
Figure 3.
2.5. Application of the Localization System
To estimate possible areas of the system applicability, the location of the cows from the entire barn experiment was monitored during one week with the help of the localization system. A map with the distribution of time spent in each location point during this period was created for all the cows.
2.6. Estimation of System Accuracy
To estimate the accuracy of the cow localization system, two experiments with different receiving station arrangements were conducted in order to find the influence of the average distance between the receiving stations (resulting in the number of receiving station covering the barn area) on the method accuracy. In experiment 1, the entire barn experiment included 10 receiving stations distributed over the entire area with the average distance of 10 m between the neighboring stations, as shown in
Figure 2a. This experiment was conducted with 35 cows wearing 12 tags in groups during four periods of about two days. Experiment 2 included 7 receiving stations distributed in the waiting area in front of the milking robot with the average distance between the neighboring stations of 2 m, as shown in
Figure 2a. This experiment was conducted with 19 cows wearing the tags for two days.
The reference cow location was measured by the following systems in the barn. Location during eating and drinking was recorded by the feeding stations. Location during milking was recorded by the milking robot. Locations during lying in cubicles, staying and walking in the alleys were recorded by the barn cameras (
Figure 2b) and classified manually. The location of a cow in a specific barn’s point was registered if this point was the closest to the cow collar for more than five seconds. A continuous walk between two points distanced by more than 5 m was also registered. The clocks of all the systems were synchronized with the receiving stations with accuracy better than 1 s.
5. Discussion
The location accuracy of the system covering the entire barn was 3.27 m and 1.9 m for the smaller area (4 × 5 m
2), which makes the system much less accurate than systems based on UWB technology reaching 0.4–2 m of accuracy in entire barns [
2,
4,
5], but with similar accuracy as the research system based on BLE, such as 4.2 m at [
8] in the cow barn environment and 2.4 m (for 90% of tested cases) at [
22], 3.8 m at [
26] and 2.3 m at [
16] in the office environment. The developed localization system can be used to recognize preferable cow locations, such as areas for lying (
Figure 13a), feeding and crowded locations, such as queuing to the milking robot (
Figure 13b) and a rough distribution of the cow activity (
Figure 13c). However, it does not grant the ability to track the cows’ walking and time spent in more specific locations, such as individual stalls or feeders.
The Viterbi algorithm was chosen among other filtering methods (fingerprint, particle filter, Kalman filter) because of the following reasons: it has a low computation time; the location computation is based on the entire time interval, not only on the previous sampling; it uses additional information about cow behavior and the barn structure (which can be accessible for commercial barns); it does not require reference collecting for learning.
The RSS of the RuuviTag studied in this research had a relatively high noise level and non-gaussian distribution (
Figure 5a) similar to [
12,
27] and others. Particularly, it was caused by the aggregation of RSS received by different channels (37, 38 and 39, separated by [
26]), which can be seen in the first image in
Figure 5a. However, in the barn environment, the RSS distribution was closer to gaussian (
Figure 5b). One possible reason could be multiple reflections of the signal from randomly distributed obstacles, which can produce resultant signals with higher randomization.
The variability of the RSS for the considered tags and receiving stations had several origins. The deviation from the analytical line for the RSS propagation model (
Figure 6a) can be explained by the high sensitivity of the RSS to the objects reflecting radio signals [
14] (such as ground and distant objects which are hard to eliminate during this RSS propagation model experiment) and tag directional RSS variability combined with inaccuracies in the tag direction during the experiment. Trials to create the barn RSS map were conducted during the research. However, this action was extremely time consuming and inconvenient, even for rougher point resolution. In addition, considering the high RSS variability, uncertain factors such as blocking the signal by other cows, or cows bending necks, it was concluded that creating a barn RSS map was impractical, especially for commercial application.
Possible reason for the RSS variability between different tags and receiving stations (
Figure 6b) can be the variability in features of the antennae of the tags and the receiving stations. When separately drawing the average RSS propagation lines for each tag received by all the stations (
Figure 6c), relatively small variability between the tags can be seen, though the average STD for each tag was high, meaning that the signal emitted by a tag was received by different stations with significantly different RSS. Average RSS propagation lines for each station receiving signals from all the tags (
Figure 6d) show that different stations receive signals from the same tags with high variability. The average STD for each station was lower than the average STD for the tags. This can show that each receiving station measures the RSS from all the tags with lower variability, while, on average, different stations measure different RSS sent by the same tags. In general, this can be used for calibrating the RSS propagation model for each station, which could decrease the RSS uncertainty. Nevertheless, total high RSS variability in the open-space experiment makes it impractical to perform additional experiments when their results are used in the barn environment with significantly higher uncertainties.
To simplify the usage of the system in commercial barns, the average RSS propagation model achieved in the experiment (
Figure 6b) was used. In general, the actual measured RSS does not fit the model, which can be observed in the RSS propagation model experiment (
Figure 6c,d) and the RSS measured in the barn (
Figure 7). Nevertheless, the relative RSS (fixed by a shifting factor) can be close to the model line, which justifies the usage of the shifted localization error function (Equation (3)). The average localization accuracy with the unshifted localization error function (Equation (2)) was 4.1 m.
The variability of the RSS depending on tag orientation is relatively high (
Figure 8a); on average, it is 17 dB, while, for a specific tag, it can reach 22 dB, which is similar to [
13]. In general, assuming that the RSS directionality is known and unchanging, and the tag orientation can be defined by accelerometers and a compass (or when a compass is missing, the yaw angle can be treated as a variable in the optimal location fitting), the RSS uncertainty caused by the tag direction can be eliminated. This strategy was applied in the current study, though the average localization accuracy (4.4 m) was worse than when the RSS directionality was not used. A possible explanation can be the same as the explanation for the effect observed in
Figure 5b: signal reflections from multiple objects distributed isotropically in the barn environment act as a filter decreasing the RSS variability caused by the tag direction. This assumption corresponds with the RSS-tag orientation experiment presented in
Figure 8b, where the average deviation of the RSS for different orientations in the barn experiment is about 6 dB.
According to testing different RSS filters and their parameters, they do not have a significant influence on the accuracy of the localization method (in the considered range of parameters). This can be explained by further location filtering by the Viterbi algorithm, which compensates the uncertainties staying after the RSS filtering. The average filter with a 10 s window, providing better performance and the simplest implementation, was used. In this study, the simplest version of the Kalman filter unfitted to the RSS features was tested.
The accuracy of the localization method depends on the way for the receiving stations positioning. According to the two experiments conducted in the study, the accuracy is about half of the minimal distance between the receiving stations. Hence, the number and location of the stations must be fitted to the area of interest and the type of application.
The main reason for the low accuracy of the developed system based on RSS received by BLE technology was the high level of noise caused by the tag sensitivity on its position and complex barn environment. Further improvement of the localization algorithm can be done in the following parts of the system. The RSS noise can be decreased by the separation of the BLE signal channels, as was done in [
26] and [
22]. The Viterbi algorithm can be improved by more detailed description of the cow behavior by the Markov chain, changing a method for calculation of the location probability in the mapping points and using additional information about the cow behavior measured by other sensors (such as cow body position estimated with the help of tag accelerometers) similar to [
16]. To filter the RSS, a more advanced Kalman filter fitted to the RSS features or another filtering method can be found.