Orientation Capture of a Walker's Leg Using Inexpensive Inertial Sensors with Optimized Complementary Filter Design

—Accelerometers and gyroscope are often referred to as inertial sensors. They detect movement and are used for motion tracking systems in many fields. In recent years they have become much smaller, lighter and cheaper which makes them attractive for use in consumer electronics. The goal of this research is to use all these advantages to create a cheap, low cost and accurate motion tracking system. The system that will be developed is using two pairs of accelerometer + gyroscope sensors which communicates with an iOS device using BLE. The sensors are attached to a persons leg to capture the orientation of the leg while walking or running. Studying the movements of a persons leg can be useful regarding both performance and health aspects. To create the system, usage of inertial sensors and how to combine their data using the complementary filter have been studied. Further, several experiments were made to optimize the filter design for this kind of movement. The results shows how the orientation estimation differs in accuracy depending on different values of how the filter is designed. However, by using the right values, a fairly accurate orientation of the leg can be estimated which is proved by the simple visualization of the iOS application.


I. INTRODUCTION
Motion tracking systems with inertial sensors have been used for many years in fields that includes military, health care, navigation and flight technologies [1].But it is just in the last decade that the market of inertial sensors in consumer electronics has rapidly increased [2].The main reason for this is advances in Micro-Electro-Mechanical-System (MEMS) technology which makes the sensors small, light, low cost and with low power consumption [2,3].Together with Bluetooth Low Energy (BLE, Bluetooth Smart), which also have reduced power consumption compared to the classic Bluetooth, it makes the sensors very convenient to wear on the body for applications in sports, fitness and health.One product that use the advantages of both these technologies is the CC2541 SensorTag by TI.With the CC2541 SensorTag the development process for smart phone applications that uses inertial sensors gets a lot simpler since no hardware implementation is required.Inertial sensors includes accelerometers and gyroscopes.For a successful motion tracking system, data from both these sensors is combined and thereby creating an inertial measurement unit (IMU) [4][5][6].
The improvements of inertial sensor technologies opens up a lot of possibilities for developers to create cheap consumer electronics in ways that was not possible before.It could be anything from tracking the movement of a specific body part to a completely different device or vehicle.One interesting example is to capture the orientation of the legs while walking or running.This can be done for many different reasons.One might want to study the movement of the legs to improve the running technique which can increase the performance and avoid injuries [7].This paper is considering orientation capturing of the leg while walking or running by using sensors in the CC2541 SensorTag.To make the orientation estimation as accurate as possible, data is combined from both accelerometer and gyroscope sensors by using a complementary filter.Experiments are then made to optimize the accuracy of the filter by having a test subject walking while wearing the sensors.
The rest of the paper is organized in the following way: Section II gives an overview of the application and details about the setup of the experiments, Section III introduces usage of inertial sensors while Section IV introduces the complementary filter, the procedure of how to optimize the filter for this application is described in Section V and finally, the result and conclusion is presented in Sections VI and VII respectively.

II. EXPERIMENTAL ENVIRONMENT
Two CC2541 SensorTags and an iOS device is used for implementation of the orientation tracking system.Each SensorTag represents one IMU and they are attached to the lower leg and the upper leg respectively to get an orientation estimation of the whole leg.Only one angle is being tracked as it is the most interesting while walking or running, this is the angle of the leg straight forward or backward of the walker.In all tests the test subject that is wearing the sensors starts from a standing position with the legs 90 • relative to the ground.The subject then starts walking in a speed of 4km/h for around 1 minute and then ends the test by stop walking and goes back to the starting position.The CC2541 SensorTag is a device which includes several commonly used sensors, including accelerometer and gyroscope, on one single board and uses Bluetooth Low Energy for communication.It is specially targeted for smart phone application development since a lot of configurations can be done over the GATT 1 server which is already included in the SensorTag's firmware.

B. iOS application
The responsibilities of the iOS device is to connect, configure, read the sensor values from the SensorTags and, most important, make all calculations of the orientation estimation.Connecting, configuring and reading the SensorTag is done using the following steps: 1) Scan and discover the SensorTag 2) Establish a connection 3) Discover the available services and characteristics 4) Write to characteristic value 5) Read from characteristic value In iOS this is done by using the CBCentralManagerDelegate and CBPeripheralDelegate protocols.These protocols makes step 1-3 very straight forward.Step 4 activates and configures the wanted sensors to suit with the application needs.When that is done the SensorTag will advertise at the specified intervals with data from the active sensors.Calculations of the angle estimation is done after each time a new value is updated from a characteristic.

A. Gyroscope
Gyroscope sensors measures the velocity of angular movement around one axis.The angle of a rotating gyroscope can be obtained by integrating this data.Of course, since there will be a time interval between each reading from the sensor the integration will not be 100% accurate and as time goes the angle estimation will be less and less accurate.This problem is referred to as drift which is a big problem with inertial sensors [8].To measure the angular movement in a 3D space it is required to use three different gyroscopes placed orthogonal to each other.In this experiment only one gyroscope is used since it is only the angle in one direction that is of interest. 1Framework for transporting data between two Bluetooth Low Energy devices

B. Accelerometer
An accelerometer measures the acceleration in G forces.Similar to the gyroscope, three accelerometers placed orthogonal to each other is needed to measure acceleration in a 3D space.In a constant speed or in a resting state the only output will be gravity, which is 1G straight down towards the earth.The gravity can be used to calculate the angle of the accelerometer using trigonometry.In Objective-C the function atan2f can be used which is the arctangent function with two arguments.zAngle = atan2f (x, y) * 180.0/MP I; The above code calculates the angle around the accelerometer z axis.X and y is the acceleration measured on the respective axis.The resulted angle from the atan2f function is in radians so it needs to be converted to degrees.Unlike the gyroscopes drift problem when it comes to angle estimation, the accelerometer angle calculation is very accurate as long as it is not exposed to any kind of acceleration other than gravity.In this experiment a 2D accelerometer is used to measure the one angle that is interesting.
Table I shows the update frequency as well as the range of which each sensor is operable.There are some limitations in the range of the gyroscope.For the usage within this paper (walking, slow running) the range is enough but faster movements will need a gyroscope with higher range.Another limitation is, of course, the updates.It is obvious that faster updates will give better results.The SensorTag doesn't allow a lower update frequency to be set over the GATT server and the reason for this is to keep the power consumption at an acceptable level.

IV. COMPLEMENTARY FILTER
Basically, there are two different kinds of filters that have become very popular to use when combining accelerometer and gyroscope data for angle calculation.The more complex one is the Kalman filter.It was first introduced in 1960 by R.E.Kalman [9].It uses a set of complex mathematical equations to estimate the past, present and future state of a process in a way that minimizes the errors [10].The other one is the complementary filter.It is much simpler to understand and contains a lot less computations and is therefore much easier to modify and optimize for a specific problem.In its most basic form it takes integrated data from the gyroscope and combines it with data from the accelerometer [11,12] in the following way: Where gyroData is the angular movement in • /s, dt is the time passed since the last reading and accData is the angle calculated by the accelerometer.The variable ii is a value 178 | P a g e www.ijacsa.thesai.org between 0 and 1 and will directly decide the influence of the different sensors.Bigger ii will result in an angle where the accelerometer has more influence.How to choose the best possible ii depends a lot of the kind of movement that the IMU will be used for.As mentioned before, the gyroscope is good for reading fast movements during a short time but will drift over time and the accelerometer is very reliable when the speed is constant.How can these principles be applied to optimize the filter for a walking movement?

V. OPTIMIZING THE FILTER
The basic idea for the optimization is simple: use data from the two different sensors when it is the most reliable.This means using gyroscope data when the movement is big and many disturbing forces is acting on the accelerometer and using accelerometer data as much as possible when the sensor is in a resting state to correct the drift caused by the gyroscope.
To do this we must know when and how much (varying values of ii) to use the data according to when it is the most reliable.Figure 2 shows the angle estimation of both sensors alone, without combining any data and with no filters.The angle from the gyroscope is very smooth and behaves in a logical way for a walking motion.But one can see that already after 10 seconds the angle has drifted away and after 48 seconds the angle has drifted around 60 • .The angle from the accelerometer on the other hand is very noisy during a lot of movement but when standing still again after 48 seconds the angle is back to where it started, no drift at all.Fig. 2: Angle estimation from gyroscope (green) and accelerometer (red) (y axis: angle, x axis: seconds) First, the accelerometer data alone can be filtered to get rid of some noise during movement.We know now that angle estimation by the accelerometer is almost 100% accurate when gravity is the only force that is acting on it.This means that in a position where one axis is directed straight to earth that axis will measure an acceleration of 1G and the other two axes 0G which makes the total acceleration 1G.If the device is tilted 45 • , two of the axes will measure an acceleration of 0.75G and the third 0G which makes the total 1.5G.So, when gravity is the only force the total acceleration must measure between 1G and 1.5G and that is when the accelerometer angle should have the most influence.This can be programmed as shown below.
totalAcc = f absf (x) + f absf (y) + f absf (z); if totalAcc ≥ 1.0 && totalAcc ≤ 1.5 then {Calculations of the desired angles} {according to the algorithm} {presented in section IV} end if Fig. 3: Improved angle estimation of accelerometer (y axis: angle, x axis: seconds) Figure 3 shows the result of this method.The improvements from figure 2 where no filtering of the accelerometer data was done is very clear.The spikes are almost gone, the data is less noisy and the angle estimation behaves more logical (more like the gyroscope in figure 2).After knowing how to use the accelerometer data the next step is to find out how much of the data to use.If the accelerometer angle estimation have too much influence there will be too much disturbance in the filtered angle.If it has too little influence the angle will start to drift away with the gyroscope angle estimation.Experiments were made with different values of ii (0.5, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35) and the result is presented in the next section.

VI. RESULT
The figures 4 to 10 presents the resulted angles of the complementary filter discussed in previous sections using different values of ii and with the accelerometer filter.The data is extracted from the same test session, starting from the 22:nd second.other hand, we can also see the effects of ii being too big as in figure 10 where it is 0.35.The angle doesn't drift at all but the angle estimation when movement is occurring is way too noisy because of the accelerometers big influence.When ii = 0.1 there is still some drift on the angle but at ii >= 0.15 there is not much difference when considering the drift problem.From ii = 0.2 and up we mostly just gain noise and making the angle estimation less and less smooth.
The iOS application includes a simple visualization of a leg which is wearing the sensors.In figure 11, three samples  The forward swing is complete and the foot is just about to make contact with the ground again.

VII. CONCLUSION
A system with a pair of IMU's that's connected with an iOS device have been developed for angle estimation of a persons leg while walking.Optimizations of the sensor data was applied considering the specific application.The complementary filter has been studied and with help of several experiments we can see how the performance of the filter changes by adjusting how much of each sensor's data is used.The result shows how different values of ii in the filter affects the outcome of the angle estimation.For the best performance we end up with ii around 0.15-0.2,depending a little on what factor is most important: no drifting or making the angle smoother while moving.After 36 seconds of walking, the system is still capturing the angles of the leg which is shown by the simple leg visualization in figure 11.
The filter can be improved even further by analyzing more accurately when each sensor is reliable and from there we can make ii change with the reliability.For example, if at one point the accelerometer data is 80% reliable then 80% of that data should be used but at another point it is calculated to be 5% reliable then only that much is used.

Fig. 11 :
Fig. 11: (a) The leg is behind the body and the foot is just about to get released from the ground.(b) The leg is in the middle of the forward swing.No contact with the ground.(c)The forward swing is complete and the foot is just about to make contact with the ground again.

TABLE I :
Sensor details