2008:146 CIV
M A S T E R ' S T H E S I S
Real-Time Ultrasonic Measurements of Log Diameters
Magnus Eriksson
Luleå University of Technology MSc Programmes in Engineering
Electrical Engineering
Department of Computer Science and Electrical Engineering Division of EISLAB
2008:146 CIV - ISSN: 1402-1617 - ISRN: LTU-EX--08/146--SE
Real-time Ultrasonic Measurements of Log Diameters
Magnus Eriksson
Lule˚ a University of Technology
Dept. of Computer Science and Electrical Engineering EISLAB
10th June 2008
A BSTRACT
In today’s harvesters they measure log diameters with the limbing knifes. This system does not meet the requirements of today’s forestry. So Skogforsk (the Forestry Research Institute of Sweden) and a group of companies contacted LTU (Lule˚ a University of Tech- nology) to develop a system with ultrasonic sensors to measure the diameter. This project is a continuation of the Master’s thesis on Log Diameter Measurements Using Ultrasound by Reza Tavakolizadeh (2007). The overall goal with this project was to do the whole chain from the sensor modules to calculations of diameters and filtering. This was done by choosing between commercial sensor modules and programming in MATLAB and C/C++.
Skogforsk and the group of companies chose a commercial approach of this project in the means of the sensor modules. The sensor modules that were found were not built for this purpose so they do not meet the requirements. But they were used to show that the whole chain from the sensor modules to calculated diameters and filtering, works without any synchronization of the sensors modules when all sensor modules operate simultaneously.
iii
P REFACE
I would like to thank, first and foremost, my supervisor Johan Carlson for the opportu- nity to work with this project and his guidance and encouragement. Second the project group for the challenging project that kept me up many nights to think of how to solve the problem in the best way. Finally I will thank my girlfriend and family that are always there for me.
In the end I say good luck to the project group with the future work of the system and I hope you are satisfied with the results.
GOOD LUCK.
Magnus Eriksson Lule˚ a, April 2008
v
T ABLE OF C ONTENTS
Chapter 1: Introduction 1
1.1 Background . . . . 1
1.2 The aim . . . . 1
1.3 Requirements from the companies . . . . 2
1.4 Problems . . . . 2
1.5 Programs used . . . . 3
Chapter 2: Filter Design and Analysis 5 2.1 Summary . . . . 5
2.2 Filtering . . . . 5
2.3 Filter analysis . . . . 8
2.4 Filter analysis conclusion . . . . 8
Chapter 3: Data Collection and Sensor Steering 21 3.1 Summary . . . . 21
3.2 Sensor modules . . . . 21
3.3 Configuration of the rig . . . . 23
Chapter 4: Computation Module 25 4.1 Summary . . . . 25
4.2 The configuration file, Confell . . . . 25
4.3 Software design . . . . 27
4.4 Ellipse to Circle and Error codes . . . . 29
4.5 Fitting a circle to measurements . . . . 29
4.6 Time analysis . . . . 30
Chapter 5: Conclusions and Future Work 31
Appendix A:Sensor modules 33
Appendix B:Confell file 37
Appendix C:Project Plan 39
C HAPTER 1 Introduction
1.1 Background
In today’s harvesters log diamters are measured using sensors in the limbing knifes. This system does not meet the requirements of today’s forestry. So Skogforsk (the Forestry Research Institute of Sweden) and a group of companies contacted LTU (Lule˚ a Univer- sity of Technology) to develop a system with ultrasonic sensors to measure the diameter.
The harvester measures the diameter to know how much wood they can take out of every log.
This project is a continuation of the Master’s thesis of Log Diameter Measurements Using Ultrasound by Reza Tavakolizadeh (2007) [1]. Tavakolizadeh (2007) developed a method to measure the log diameter using ultrasound in Matlab. Tavakolizadeh (2007) tested the method on a test bench at LTU in the ultrasonics lab and verified the mea- surements at the Division of Wood Science and Technology,Skellefte˚ a.
The method that Tavakolizadeh (2007) developed was an ellipse fitting algorithm with six ultrasonic sensors and a seventh sensor to measure the speed of sound. This algo- rithm calculate the major and minor diameter, the position in space of the log and the angle of the ellipse. Tavakolizadeh (2007) used commercial ultrasonic sensors that were connected to the data collection card Nidaq PCI - 6143 version 2.8.1 Texas Instruments.
1.2 The aim
The aims of this thesis are to develop methods to steer the ultrasonic sensors, filter out disturbances lengthwise on the log, investigate how the sound reflection angle to the
1
2 Introduction log will disturb the signal and if there is time left, program the computation module in C/C++. The focus is to do the whole chain form sensor module to calculation of diameters and filtering. Figure 1.1 shows a schematic view of the thesis project. Skogforsk and the group of companies chose a commercial approach of this project in the means of the sensor modules i.e. choose between already existing sensor modules.
Data collection and sensor steering
Simulation and input data
Computation of diameter and length-wise filtering
Visualization and and analysis of system performance
Programs in Matlab
Electronics construction and programing of microcontroller Prototype in Matlab, if there is time implementation in C
Figure 1.1: Block diagram of the project. Taken from the project plan in Appendix C
1.3 Requirements from the companies
The standard deviation of the diameter measurement error should decrease from 5 - 8 mm to 3.5 mm. The measurement frequency is one measurement by 10 mm with a speed of 5 m/s. This means that the frequency of the measurements is 500 times/sec or 500 Hertz(Hz). The sensors should be insensitive to light, humidity, snow, vibrations, noise and temperature. The temperature range should be -55 to 80 degrees Celsius. [2]
1.4 Problems
The problem that Tavakolizadeh (2007) encountered was that the transducers disturbed
each other too much which resulted in erroneous distance estimation between the log and
the transducers. The solution to this problem was to measure the distance to the log by
two transducers at a time, one on each side of the log [1].
1.5. Programs used 3
1.5 Programs used
In this project I used Matlab R2006b to collect data and to calculate the diameters and
to do the filtering analysis. The computation module was programmed in C/C++ on
the Eclipse platform, version: 3.3.1.1 with C/C++ plugin. The code was then compiled
and run under MATLAB.
C HAPTER 2 Filter Design and Analysis
This chapter describes how the filtering and choice of filter was done.
2.1 Summary
The filtering is done length-wise of the log to reduce any measurement error to a min- imum, be less sensitive to limbs and other abnormal things along the log i.e. snow, ice and the rough surface of the log. Filtering length wise is done with a so-called sliding window. This sliding window filters the incoming data with specified window length. In the beginning when the window is empty the window fills up with incoming data. After the window is full the whole window width is filtered with the chosen filter. Three kinds of filters were implemented. First a median filter that calculates a median value of the data in the window and returns it. The second filter is a mean filter that does the same as the first one but calculates the mean value instead. The third filter is also a mean filter but this filter takes away maximum and minimum values from the window before calculating the mean value. These were implemented in two ways to evaluate the filtering window algorithm. First one A, just returns the filtered values and the second one B, also returns the filtered value but puts the filtered value back to the window at the first position again. The mean filter that takes away the maximum and minimum values from the window with window algorithm B was chosen with a window length of 5 samples.
2.2 Filtering
Filtering length-wise was done by a sliding window that remembers the major and minor diameters, position in space X0 and Y0 and the angle in space Figure 2.1.
5
6 Filter Design and Analysis
Y
X (X0,Y0)
X0 Y0
Phi
Phi = Angle in space R1
R2
Figure 2.1: Graphical view of R1 (minor radius), R2 (major radius), X0, Y0 and angle φ.
Filtering with a chosen filter with the recent calculated parameters down to window length (see Figure 2.2). When the computation module starts, it fills the sliding window.
After the sliding window becomes full the filter starts to filter the window with the chosen filter.
Data
Window length
Figure 2.2: The method of sliding windows, where the window length is the length of the vector that should be filtered. Data are the major or minor diameters, position in space (X0,Y0) and angle of the log.
Three different filter implementations were done. The first one was a median filter. It filters the major and minor diameters, X0 and Y0 and the angle with a median filter.
The filter returns the median of the values in the window. The second filter is the mean filter. It works in the same way as the median filter but it returns the average of the samples instead. The third and final filter is also a mean filter but it takes away the mini- mum and maximum values from the window to reduce the effect of large and small values.
Two different methods were implemented for returning the filtered values. The first
method, A, filters the data in the window and then returns the diameters, positons of
the log’s origin, and the angle (as in Figure 2.3). The second method, B, returns the
2.2. Filtering 7 filtered parameters, but also replaces the last values of the window with these new filtered values (as in Figure 2.4).
Window length
Filtering window Return filtered Value
Window length
New data
New data Window Algorithm A
Data(N)
Data(N+1)
Figure 2.3: Description of the sliding window principle A
Window length
Filtering window Return filtered Value
Window length
New data
New data Window Algorithm B
Filtered value from last time Data(N)
Data(N+1)
Figure 2.4: Description of the sliding window principle B
8 Filter Design and Analysis
2.3 Filter analysis
The filter analysis was done in MATLAB and with data that Tavakolizadeh (2007) col- lected. White Gaussian noise was added to the data to study what the effect of filtering in real world environment would be like. The levels of the noise were 0 dB, -20dB and -50dB. The window length of the filter vector was chosen to be 1 - 50 samples long. To do this analysis data with the name 070106 - Gran 100 were used. Figures 2.8 - 2.10 show the results from of simulations.
2.4 Filter analysis conclusion
In the Figures 2.5 - 2.7 for window algorithm A the standard deviation goes down to a minimum with increasing window length until a filter length of around 40 and then it begins to increase again. The filter with the lowest standard deviation is the median filter with a filter length of 30. With the window algorithm B in Figures 2.8 - 2.10 we see that with all three filters the window length of around 3 values results in a minimum standard deviation. Thus, we can say that the window length should be around 3 samples, and that the filter to choose is the median filter because it has the lowest standard deviation at a filter length of 2 samples. Because the median filter in the window algorithm B has the smallest standard deviation this window algorithm and the Median filter is the best choice.
But is the median filter with a filter length of 2 samples fast enough to follow the changes of the diameter of the log, is the filter length to small, should the filter length be longer to be less sensitive or should we chose another filter instead? To answer these questions we need to do a step response test of the two algorithms. The step responses for window algorithm A and B for all filters are in Figures 2.11 - 2.16. The filter lengths were chosen around where the standard deviation have a minimum.
The filters with algorithm A have a step response that has a nice slope but the re- sponses are shifted by the filter length so the effect of the step is delayed corresponding to the filter length. This is not preferable so filters with window algorithm A is a bad choice. The median filter with window algorithm B in Figure 2.14 shows that the step has no effect on the output and therefore this filter is a bad choice. The median filter disturbed the diameter too much so the output does not follow the diameter of the log.
There are only two filters left. These filters are the mean filter and the mean filter with
maximum and minimum values removed from the filter window with window algorithm
B. These two filters are almost the same if we look at the standard deviation but the
2.4. Filter analysis conclusion 9 mean filter with the maximum and minimum values removed from filter window is less sensitive. The step sensitivity of the filter can be chosen with filter length and this filter has a better step response when the filter length goes up compared to the regular mean filter. The filter length can be set to five samples so that the filter would not become too sensitive.
0 5 10 15 20 25 30 35 40 45 50
0 5 10 15 20 25 30 35 40
Median filter with window algorithm A.Noise level −50 dB
Filter length [n]
Standard deviation [mm]
0 10 20 30 40 50
0 0.5 1 1.5 2 2.5 3 3.5
Median filter with window algorithm A.
Noise level −20 dB
Filter length [n]
Standard deviation [mm]
0 10 20 30 40 50
0 0.5 1 1.5 2 2.5 3
Median filter with window algorithm A.
Noise level 0 dB
Filter length [n]
Standard deviation [mm]
Major diameter not filtered Minor diameter not filtered Major diameter filtered Minor diameter filtered
Figure 2.5: The median filter with window algorithm A. Standard deviations for a filter length
of 1 - 50 and three different noise levels
10 Filter Design and Analysis
0 5 10 15 20 25 30 35 40 45 50
0 5 10 15 20 25 30 35 40 45
Mean filter with window algorithm A.Noise level −50 dB
Filter length [n]
Standard deviation [mm]
0 10 20 30 40 50
0 0.5 1 1.5 2 2.5 3 3.5
Mean filter with window algorithm A.
Noise level −20 dB
Filter length [n]
Standard deviation [mm]
0 10 20 30 40 50
0 0.5 1 1.5 2 2.5 3
Mean filter with window algorithm A.
Noise level 0 dB
Filter length [n]
Standard deviation [mm]
Major diameter not filtered Minor diameter not filtered Major diameter filtered Minor diameter filtered
Figure 2.6: The mean filter with window algorithm A. Standard deviations for a filter length of
1 - 50 and three different noise levels
2.4. Filter analysis conclusion 11
0 5 10 15 20 25 30 35 40 45 50
0 5 10 15 20 25 30 35 40
Mean filter that takes away maximum and minimum values from window with window algorithm A.Noise level −50 dB
Filter length [n]
Standard deviation [mm]
0 10 20 30 40 50
0 0.5 1 1.5 2 2.5 3 3.5
Mean filter that takes away maximum and minimum values from window with window algorithm A.
Noise level −20 dB
Filter length [n]
Standard deviation [mm]
0 10 20 30 40 50
0 0.5 1 1.5 2 2.5 3
Mean filter that takes away maximum and minimum values from window with window algorithm A.
Noise level 0 dB
Filter length [n]
Standard deviation [mm]
Major diameter not filtered Minor diameter not filtered Major diameter filtered Minor diameter filtered
Figure 2.7: The mean filter that takes away maximum and minimum values from window with
window algorithm A. Standard deviations for a filter length of 1 - 50 and three different noise
levels
12 Filter Design and Analysis
0 5 10 15 20 25 30 35 40 45 50
0 5 10 15 20 25 30 35 40
Median filter with window algorithm B. Noise level −50 dB
Filter length [n]
Standard deviation [mm]
0 10 20 30 40 50
0 0.5 1 1.5 2 2.5 3 3.5
Median filter with window algorithm B.
Noise level −20 dB
Filter length [n]
Standard deviation [mm]
0 10 20 30 40 50
0 0.5 1 1.5 2 2.5 3
Median filter with window algorithm B.
Noise level 0 dB
Filter length [n]
Standard deviation [mm]
Major diameter not filtered Minor diameter not filtered Major diameter filtered Minor diameter filtered
Figure 2.8: The median filter with window algorithm B. Standard deviations for a filter length
of 1 - 50 and three different noise levels
2.4. Filter analysis conclusion 13
0 5 10 15 20 25 30 35 40 45 50
0 5 10 15 20 25 30 35 40 45
Mean filter with window algorithm B. Noise level −50 dB
Filter length [n]
Standard deviation [mm]
0 10 20 30 40 50
0 0.5 1 1.5 2 2.5 3 3.5
Mean filter with window algorithm B.
Noise level −20 dB
Filter length [n]
Standard deviation [mm]
0 10 20 30 40 50
0 0.5 1 1.5 2 2.5 3
Mean filter with window algorithm B.
Noise level 0 dB
Filter length [n]
Standard deviation [mm]
Major diameter not filtered Minor diameter not filtered Major diameter filtered Minor diameter filtered
Figure 2.9: The mean filter with window algorithm B. Standard deviations for a filter length of
1 - 50 and three different noise levels
14 Filter Design and Analysis
0 5 10 15 20 25 30 35 40 45 50
0 5 10 15 20 25 30 35 40
Mean filter that takes away maximum and minimum values from window with window algorithm B. Noise level −50 dB
Filter length [n]
Standard deviation [mm]
0 10 20 30 40 50
0 0.5 1 1.5 2 2.5 3 3.5
Mean filter that takes away maximum and minimum values from window with window algorithm B.
Noise level −20 dB
Filter length [n]
Standard deviation [mm]
0 10 20 30 40 50
0 0.5 1 1.5 2 2.5 3
Mean filter that takes away maximum and minimum values from window with window algorithm B.
Noise level 0 dB
Filter length [n]
Standard deviation [mm]
Major diameter not filtered Minor diameter not filtered Major diameter filtered Minor diameter filtered
Figure 2.10: The mean filter that takes away maximum and minimum from window with window
algorithm B. Standard deviations for a filter length of 1 - 50 and three different noise levels
2.4. Filter analysis conclusion 15
20 30 40 50 60 70 80 90 100
33 33.5 34 34.5 35 35.5
Samples [n]
Major diameter [cm]
Step responce major diameter with Median filter and window algorithm A
20 30 40 50 60 70 80 90 100
31 31.5 32 32.5 33 33.5
Samples [n]
Minor diameter [cm]
Step responce minor diameter with Median filter and window algorithm A Step response
Filter length = 28 Filter length = 29 Filter length = 30 Filter length = 31 Filter length = 32
Step response Filter length = 28 Filter length = 29 Filter length = 30 Filter length = 31 Filter length = 32
Figure 2.11: Step respone for the median filter with window algorithm A
16 Filter Design and Analysis
20 30 40 50 60 70 80 90 100
33 33.5 34 34.5 35 35.5
Samples [n]
Major diameter [cm]
Step responce major diameter with mean filter and window algorithm A
Step response Filter length = 28 Filter length = 29 Filter length = 30 Filter length = 31 Filter length = 32
20 30 40 50 60 70 80 90 100
31 31.5 32 32.5 33 33.5
Samples [n]
Minor diameter [cm]
Step responce minor diameter with mean filter and window algorithm A
Step response Filter length = 28 Filter length = 29 Filter length = 30 Filter length = 31 Filter length = 32
Figure 2.12: Step respone for the mean filter with out maximum and minimum values taken
away from filter window with window algorithm A
2.4. Filter analysis conclusion 17
20 30 40 50 60 70 80 90 100
33 33.5 34 34.5 35 35.5
Samples [n]
Major diameter [cm]
Step responce major diameter with mean filter that takes away maximum and minimum values from window and window algorithm A
Step response Filter length = 28 Filter length = 29 Filter length = 30 Filter length = 31 Filter length = 32
20 30 40 50 60 70 80 90 100
31 31.5 32 32.5 33 33.5
Samples [n]
Minor diameter [cm]
Step responce minor diameter with mean filter that takes away maximum and minimum values from window and window algorithm A
Step response Filter length = 28 Filter length = 29 Filter length = 30 Filter length = 31 Filter length = 32
Figure 2.13: Step respone for the mean filter with maximum and minimum values taken away
from filter window with window algorithm A
18 Filter Design and Analysis
20 30 40 50 60 70 80 90 100
33 33.5 34 34.5 35 35.5
Samples [n]
Major diameter [cm]
Step responce major diameter with median filter and window algorithm B
Step response Filter length = 2 Filter length = 3 Filter length = 4 Filter length = 5 Filter length = 6
20 30 40 50 60 70 80 90 100
31 31.5 32 32.5 33 33.5
Samples [n]
Minor diameter [cm]
Step responce minor diameter with median filter and window algorithm B
Step response Filter length = 2 Filter length = 3 Filter length = 4 Filter length = 5 Filter length = 6
Figure 2.14: Step respone for the median filter with window algorithm B
2.4. Filter analysis conclusion 19
20 30 40 50 60 70 80 90 100
33 33.5 34 34.5 35 35.5
Samples [n]
Major diameter [cm]
Step responce major diameter with mean filter and window algorithm B
Step response Filter length = 2 Filter length = 3 Filter length = 4 Filter length = 5 Filter length = 6
20 30 40 50 60 70 80 90 100
31 31.5 32 32.5 33 33.5
Samples [n]
Minor diameter [cm]
Step responce minor diameter with mean filter and window algorithm B
Step response Filter length = 2 Filter length = 3 Filter length = 4 Filter length = 5 Filter length = 6
Figure 2.15: Step respone for the mean filter with out maximum and minimum values taken
away from filter window with window algorithm B
20 Filter Design and Analysis
20 30 40 50 60 70 80 90 100
33 33.5 34 34.5 35 35.5
Samples [n]
Major diameter [cm]
Step responce major diameter with mean filter that takes away maximum and minimum values from window and window algorithm B
Step response Filter length = 2 Filter length = 3 Filter length = 4 Filter length = 5 Filter length = 6
20 30 40 50 60 70 80 90 100
31 31.5 32 32.5 33 33.5
Samples [n]
Minor diameter [cm]
Step responce minor diameter with mean filter that takes away maximum and minimum from values window and window algorithm B
Step response Filter length = 2 Filter length = 3 Filter length = 4 Filter length = 5 Filter length = 6
Figure 2.16: Step respone for the mean filter with maximum and minimum values taken away
from filter window with window algorithm B
C HAPTER 3 Data Collection and Sensor
Steering
This chapter is about the sensor modules that were chosen and how to configure the measurement rig.
3.1 Summary
There were two approaches to chose from of how to get a sensor package. The first is to do the complete electronics design of the sensor modules as part of this thesis project.
The second is to buy commercially available sensor modules. The project group chose the second approach. Three different sensor modules with three different frequencies were chosen from Baumer systems. These sensors do not meet the requirements of the project and have very large measurement errors. However, the sensors could be used to verify the general principle of the system. The large measurement errors depend mostly on the fact that the sensor modules loses data because of the narrow sound beam. This means that reflection from the rough surface of the log are lost. This needs to be dealt with to get sensor modules to rely upon. Every sensor module has three parameters that need to be measured. These parameters are explained in Chapter 3.3.
3.2 Sensor modules
The sensor modules that were chosen were UNDK 10I6912, UNDK 20U6914 and UNDK 30U6112. The data sheets for the sensor modules are in Appendix A. These three sensor models have three different frequencies that they are sending at and the response times are the same for all three cases in order to make the programming easier. This response time is not fast enough to meet the requirement of 500 measurements per second. Testing
21
22 Data Collection and Sensor Steering has shown that these three sensor modules can send at the same time without disturbing each other so there is no need of any synchronization algorithm to measure with the modules simultaneously. The output of the sensor modules is a voltage from 0 - 10 volt.
This voltage has a relationship to the distance that is in (3.1)
M = K ∗ V + . (3.1)
M is the distance in meters and V is the measured voltage. Because the output is linear with the distance, K is the ratio between the scanning range in meters divided by the voltage range in volts. The is the smallest scanning range in meters that the modules have. The distances that are measured are used to determine where the log is in space, so the ellipse algorithm can fit the best ellipse through these measured values.
0 10 20 30 40 50 60 70 80 90 100
10 15 20 25 30 35
Samples [n]
Diameter [cm]
Measurement with a moving rig and no filter
Major diameter Minor diameter
Figure 3.1: Measurement from the sensors, when the rig is moving with a speed of around 0.1 meters per second over a distance of 1 meter. For the samples lower than fifteen the rig is not moving.
The sensor modules do not meet the requirements because the standard deviation of the
measured diameters is too large (see Figure 3.1). The explanation to these measurement
errors is that the sound beam transmitted by the sensor module is too narrow, causing
the reflection to miss the sensor when reflected off a rough surface. When the sensor
modules miss a measurement they return to a voltage of five volts. These sensor modules
miss the measurements fairly often as one can se in Figure 3.1. It should be a straight
3.3. Configuration of the rig 23 line in both diameters if the sensor modules do not miss there measurement. During the first fifteen samples the measurement rig was not moving. But when the rig starts to move after around fifteen samples the measurement error becomes too big. A filter that is described in Chapter 2 could be used to force the measurement error to meet the requirements but this is not a good idea. Instead the computation module recognises this error and chooses to calculate the diameters, position in space and angle with a circle algorithm instead and takes away the sensor that has the error when calculating. This is described in Chapter 4. In the long term the sensor modules need to bee fixed so one can rely on the measurements. To reduce the measurement errors we need to make sensor modules that meet the requirements and have a wider sound beam. If this can be achieved the requirements of the filter can be relaxed. As a reminder Tavakolizadeh (2007) did not have a filter and still met the requirements with respect to the standard deviation.
However, with the sensors used in the previous project, simultaneous measurements were not possible.
3.3 Configuration of the rig
To configure the rig we need to measure the three variables R, φ and θ where R is the distance to the sensor from some point O in the complex plane (Figure 3.2). This point O can be anywhere. φ is the angle in degrees from the real axis to the vector R. θ is the angle in degrees between the log and the real axis. These values should be in the confell file that is described more in detail in Chapter 4.
Re θ
R Im
O
Sensor
1 2
3 4
5 6
Φ
Figure 3.2: Graphical visualization of the configuration parameters of the measurement rig
24 Data Collection and Sensor Steering Experiments show that the accuracy of the ellipse fitting algorithm is very sensitive to the angle θ. By setting the sensor modules in the arrangement in Figure 5.1 of the Tavakolizadeh (2007) report the computation of the diameters become more accurate.
Due to maximum scanning range of the sensor modules the UNDK 10I6912 that has
the smallest maximum scanning range of the three sensor modules was put as sensors 3
and 4. UNDK 10I6912 and UNDK 30U6112 are quite close in sending frequency so the
UNDK 20U6914 was put as sensors 2 and 5 and UNDK 30U6112 was put as sensors 1
and 6 (See Figure 3.2).
C HAPTER 4 Computation Module
This chapter is about the software design and how to configure the computation module.
4.1 Summary
The computation module fits either an ellipse or a circle to the data points, depending on how many sensors that return reliable data. If more than one sensor module misses its measurement the computation module returns the last computed value and an error code. If more than one sensor module misses its measurement more than 10 times it sends out an error code that say that one can not rely on the computations. The computation module uses a configuration file where all parameters are stored for both the measurement rig and the filters.
4.2 The configuration file, Confell
Confell is a file where all data to configure the rig and computation module are stored.
These variables are shown in Table 1. The whole confell file is shown in Appendix B.
The values k10 to k30 and e10 to e30 are required for calculating the distance to the log from the sensor modules as explained in Chapter 3. The values e10 to e30 and k10 to k30 are the :s and the K:s for the sensor modules respectively. The variables sensor1 to sensor6 are the parameters for the sensors that were explained in Chapter 3 and each variable has an on/off flag to show which sensors are installed. These flags are not implemented in this version but they are there to show the possibility for them in the future. With the variable filterchoose one can choose between the three filters that were implemented by setting the variable to 1 to choose the median filter, 2 to choose the mean filter and 3 to choose the mean filter that removes the minimum and maximum values from filter window. The filterlength is the variable for the window length of
25
26 Computation Module the filter. With the winalg variable it is possible to choose between the two window algorithms A and B for the filter. The samplerate is how many measurements to do and making a finite matrix to put the output parameters in. Filter is a variable that activates the filters.
Table 1: The configuration variables in the confell file.
Variable Description filter Filter or no filter
samplerate How meny measurements to do winalg Window algorithm A or B filterlength Length of filter window filterchoose Which filter to use sensor1 on/off,R,Phi,Theta sensor2 on/off,R,Phi,Theta sensor3 on/off,R,Phi,Theta sensor4 on/off,R,Phi,Theta sensor5 on/off,R,Phi,Theta sensor6 on/off,R,Phi,Theta
e10 minimum scanning range of UNDK10 e20 minimum scanning range of UNDK20 e30 minimum scanning range of UNDK30 k10 sensor sensitivity for UNDK10
k20 sensor sensitivity for UNDK20
k30 sensor sensitivity for UNDK30
4.3. Software design 27
4.3 Software design
The structure of the software is described in Figure 4.1. The program is divided into groups. The first group is the computation and filtering module. These are done in the ANSI C language. The second group contains the main file, reading of the confell file, fetching data from sensors and visualization of the calculated values. These files are written in MATLAB. The reason it was done like this is because the program has to be as general as possible and the hardware for fetching data from the sensor modules should be possible to change without the need of rewriting the computational modules. The file Ell file is the main file of the program. Here the confell file is read, the C program is compiled and then called through the link between the MATLAB and C program.
In the link between MATLAB and C program the variables from the confell file are
initialized and the size of the filter window is set. After this is done the program jumps
back to MATLAB and fetches data from the sensor modules and then jumps back to
the C program and starts to calculate the diameters, positions in space and the angle
of the ellipse. The values are then filtered. This is done as long as specified in the
confell file. After this it jumps back to MATLAB with the filtered and calculated
diameters, positions and angles in order to visualize the values. Figure 4.2 describes the
flow of the program. The C program returns a matrix where every row is equal to [major
diameter,minor diameter,X0,Y0,angle,calculation method,error code]. The calculation
method shows what method was used to calculate the diameters, positions and angle. In
the calculation method the computation module sets a 0 for the ellipse fitting algorithm
and a 1 for the circle algorithm. The error codes are described in section 4.4.
28 Computation Module
Confell Read confell
Ell Main file Visualization
MATLAB
Mex
(MATLAB/C link) EllMain
Filters
Median filter
Mean filter
Mean filter that removes maximum and minimum values from the window
C/C++
Read from sensors
Figure 4.1: The structure of the software.
Ell main file
Reading confell
Compiling C program
MEX file
Setting variables from confell
Reading sensor data
Parameter estimation and filtering
Visualization
Figure 4.2: The flow of the program.
4.4. Ellipse to Circle and Error codes 29
4.4 Ellipse to Circle and Error codes
If one of the sensor modules misses the measurement for some reason the sensor modules return an output voltage of 5.0 Volt. The sensor modules are very sensitive to this so the program recognises it and instead of calculating an ellipse the computation module calculates a circle with only one diameter and the position X0 and Y0. The program saves this diameter in both major and minor diameters place. But if there is more than one sensor module that misses its measurement the program does not calculate a new value because with less then 5 sensors the measurements are not statistically secure.This means that it is not possible to know that the measurements are correct. If a sensor module fails for more than 10 times in a row the program returns an error that tells us that we should not rely on the calculations anymore. The error codes are shown in Table 2.
Table 2: Error codes from the program Error code Description
1 One sensor has missed its measurement 2 Two sensors have missed their measurement 3 Three sensors have missed their measurement 4 Four sensors have missed their measurement 5 Five sensors have missed their measurement 6 Six sensors have missed their measurement 7 Do not rely on my calculations!
4.5 Fitting a circle to measurements
The first thing the program does is to take away the sensor module that has missed its measurement so one have only five measurements, to estimate the center of the circle X0 and Y0 and the unknown radius R by solving Equation 4.1. x and y of Equation 4.1 are the X and Y coordinates of the measurements.
(x − X0)
2+ (y − Y 0)
2= R
2(4.1)
By expanding and rearranging Equation 4.1 we obtain the linearized model in Equation 4.3.
b = Aθ (4.2)
which is
30 Computation Module
x
21+ y
12x
22+ y
22.. . x
25+ y
52
=
1 x
1y
11 x
2y
2.. . .. . .. . 1 x
5y
5
R
2− X0
2− Y 0
22X0 2Y 0
(4.3)
The least-squares estimate of b θ is then found as
θ = A b
TA
−1A
Tb. (4.4)
By solving Equation 4.4 one can calculate R, X0 and Y0 from Equation 4.5.
R = q
X0
2+ Y 0
2+ b θ (1) X0 = b θ (2) /2 Y 0 = b θ (3) /2
(4.5)
4.6 Time analysis
The ANSI C standard does not support any reading of the CPU clock in microseconds so the analysis of the execution time of the computation module could not be done. This needs to be done to check if the program meets the requirements, i.e. if the program is fast enough to calculate the ellipse parameters in real-time. If the computation module does not meet the requirements the first thing to look at is the code where the calculations of the ellipse and circle is done. There are some matrix operations like the matrix inverse.
In my implementation of the matrix inverse the time to calculate the inverse is around
O(n
6). This means that it takes n
6operations to calculate the inverse of a matrix with
n elements. The second thing to modify is the filtering. Currently, all parameters are
filtered. It should be enough to apply the filtering algorithm only to the estimated
diameters. The third thing to look at is if the median filter is used. There is a sorting
algorithm of the data in the filter window to get the median value of the data. If necessary,
the sorting algorithm can be changed to a more efficient implementation. The code for
estimating the circle is less computationally demanding and should not have problems
meeting the real-time requirements. If none of the above is enough to achieve real-time
performance, go out an buy some faster hardware.
C HAPTER 5 Conclusions and Future Work
In this report it has been shown that the whole chain from sensor modules to calculated diameters and filtering can be done in a synchronous way. The sensor modules can send at the same time without disturbing each other if the sensor modules have different frequencies on each side of the log. The computation module can calculate a new diameter if no more than one sensor module misses its measurement. The filter keeps the standard deviation down so that we can measure a diameter that is as close as possible to the real diameter. The results from a test run is in Figure 5.1.
0
20
40
60
80
−10 0 10
−10 0 10
Samples [n]
The measured log with the chosen filter and filter length of 10 samples
Diameter [cm]
Diameter [cm]
Figure 5.1: Simulated test run of the project. The measurement rig was moving under the test log.
31
32 Conclusions and Future Work Unfortunately the sensor modules do not meet the requirements at all. The measure- ment rate of the modules is too slow and the sound beam is too narrow, meaning that the sensor misses the reflection when the sound bounces off a rough surface like a log.
These sensor modules returns an output of 5 volt if this happens, right in the middle of the output range. The transmitted sound beam must be wider than for the sensors used in this project but as Tavakolizadeh (2007) suggested, no more than 30 degrees.
Any of the three filters and the two window algorithms can be used. I think that the mean filter that removes the maximum and minimum values from the filter window is the best one with the window algorithm B as explaind in Chapter 2. I recommend that one should not use the median filter with algorithm A because if we want the smallest standard deviation that is around 30, the sorting of the window could do that.
The time analysis needs to be done on the hardware that is going to be used with all
threads running to see if the program meets the requirements. Otherwise try to change
the program in the way that was explained in section 4.6.
A PPENDIX A Sensor modules
33
34 Appendix A
www.baumerelectric.com
Ultrasonic analog sensors
Ultrasonic sensors
general data
sensing range sd 20 ... 200 mm
scanning range close limit Sdc 20 ... 200 mm scanning range far limit Sde 20 ... 200 mm
repeatability < 0,5 mm
resolution < 0,3 mm
adjustment Teach-in
sonic frequency 380 kHz
response time ton < 60 ms
release time toff < 60 ms
alignment aid target display flashing
light indicator yellow LED / red LED
temperature drift < 2% of distance to target So
electrical data
voltage supply range +Vs 15 ... 30 VDC
current consumption max. 35 mA
output circuit voltage output
output signal 0 ... 10 V / 10 ... 0 V
output current < 20 mA
residual ripple < 10% Vs
short circuit protection yes
reverse polarity protection yes
mechanical data
type rectangular
housing material plastic (ASA)
width / diameter 10,4 mm
height / length 27 mm
depth 14 mm
ambient conditions
operating temperature -10 ... +60 °C
protection class IP 67
sample picture sample drawing
2,9 7
2,915
Teach-in LED
3 3,2 12
10,4 M8 x 1
6,727 17,9
14
1
UNDK 10 (Sd = 200 mm)
10/11/2007
Figure A.1:
35
www.baumerelectric.com
Ultrasonic analog sensors
Ultrasonic sensors
general data
sensing range sd 60 ... 400 mm
scanning range close limit Sdc 60 ... 400 mm scanning range far limit Sde 60 ... 400 mm
repeatability < 0,5 mm
resolution < 0,3 mm
adjustment Teach-in
sonic frequency 290 kHz
response time ton < 60 ms
release time toff < 60 ms
alignment aid target display flashing
light indicator yellow LED / red LED
temperature drift < 2% of distance to target So
electrical data
voltage supply range +Vs 15 ... 30 VDC
current consumption max. 55 mA
output circuit current output
output signal 4 ... 20 mA / 20 ... 4 mA
output current < 20 mA
load resistance +Vs max. < 1100 Ohm
load resistance +Vs min. < 400 Ohm
residual ripple < 10% Vs
short circuit protection yes
reverse polarity protection yes
mechanical data
type rectangular
housing material polyester
width / diameter 20 mm
height / length 42 mm
depth 15 mm
connection types connector M8
ambient conditions
operating temperature -10 ... +60 °C
protection class IP 67
photo
connection diagram
Ext.Teach-In
Analog BU (3) output
BN (1)
WH (2)
+VS
Z 0V BK (4)
internal and external Teach-in compact housing
dimension drawing
426,59,5
3,2
14
M8 x 1 5,7
11,8 LED 15
Teach- in 20
29,5
UNDK 20I6912/S35A
17/8/2007
Figure A.2:
36 Appendix A
www.baumerelectric.com
Ultrasonic analog sensors
Ultrasonic sensors
general data
sensing range sd 60 ... 400 mm
scanning range far limit Sde 60 ... 400 mm
repeatability < 0,5 mm
resolution < 0,3 mm
sonic frequency 400 kHz
response time ton < 60 ms
release time toff < 60 ms
alignment aid target display flashing
temperature drift < 2% of distance to target So potentiometer
light indicator LED green
Teach-in
scanning range close limit Sdc 60 ... 400 mm
light indicator yellow LED / red LED
electrical data
voltage supply range +Vs 15 ... 30 VDC
output current < 20 mA
residual ripple < 10% Vs
short circuit protection yes
reverse polarity protection yes
voltage output
current consumption max. 35 mA
current output
current consumption max. 55 mA
load resistance +Vs max. < 1100 Ohm
load resistance +Vs min. < 400 Ohm
mechanical data
type rectangular
housing material polyester / die-cast zinc
width / diameter 30 mm
height / length 65 mm
depth 31 mm
sample picture sample drawing
6523
4,5
M12 x 1
30 31,1
11,4 LED
11
20 14
37,4
Teach-in 18,4
Teach-in = Teach-in or Potentiometer
1
UNDK 30 (Sd = 400 mm)
9/11/2007
Figure A.3:
A PPENDIX B Confell file
37
38 Appendix B
####################################################
#
# Author: Magnus Eriksson
# Date: 20071206
# Project: Master thesis in Real-time Ultrasonic
# Measurements of Log Diameters
# Filename: conf_ell
# Description: This file is configure file where
# the operator can choose to set variables
# DO NOT FOR GET THE BLANK SPACE AFTER
# EACH VARIABLES
####################################################
#
# Samplerate is how many measurements that should be done
#
samplerate=100
#
# Filter on/off
# filter= 1 - on
# 0 - off
filter=1
# winalg - window algorithm A or B winalg=B
#
# Filterlength is a variable that is the length of the filter window
# Should be >10 filterlength=5
#
# Filterchoose is a variable that make you choose of the
# three filters that was implemented
# filterchoose 1 - median filter
# 2 - mean filter
# 3 - cut of min max mean filter. To reduce the max
# and min values from the filter window
filterchoose=3
#
# Which sensors are installed
#
# Sensor 1 * ---- * sensor 6
# / \
# Sensor 2 * \ / * sensor 5
# ----
# Sensor 3 * * sensor 4
# ¤
# Sound of speed measurement
# Sensor 7 => |
#
# sensorN = on/off,R,phi,theta
#
# 1 - sensor installed.
# 0 - sensor not installed.
# R - length to sensor from ¤.
# phi - angel in degrees from ¤ to the sensor in the
# Cartesian Coordinate System.
# theta - angel in degrees that the sensor is sending at in
# the Cartesian Coordinate System.
#
#
sensor1=1,0.438,146,350 sensor2=1,0.322,157,0 sensor3=1,0.174,169,38 sensor4=1,0.142,15,132 sensor5=1,0.322,26,180 sensor6=1,0.405,31,190 sensor7=0
#
#
# Linear approximation of sensor
# Out from sensors -> 0 - 10 volt
# Min scanning range e(metre) ->UNDK10 0.200->0.20
# UNDK20 0.400->0.60
# UNDK30 0.400->0.60
# K -> Scanning range / voltage range
#
# m -> measured distance
# m = K*V + e
#
e10=0.020 k10=0.0180 e20=0.060 k20=0.0340 e30=0.060 k30=0.0340