the application of the kalman filter on robot...

26
The Application of the Kalman Filter on Robot Soccer Dylan Oelmann, Zachary Rothsching December 10 2018 1

Upload: others

Post on 20-Aug-2020

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: The Application of the Kalman Filter on Robot Soccergauss.vaniercollege.qc.ca/~iti/proj/Dylan_Zachary.pdf · Robot soccer has the same underlying rules as human soccer, but with a

The Application of the Kalman Filter

on Robot Soccer

Dylan Oelmann, Zachary Rothsching

December 10 2018

1

Page 2: The Application of the Kalman Filter on Robot Soccergauss.vaniercollege.qc.ca/~iti/proj/Dylan_Zachary.pdf · Robot soccer has the same underlying rules as human soccer, but with a

Contents

1 Introduction 3

2 Basic Concepts of the Bayesian Filter 72.1 State, Environment, and Control Data . . . . . . . . . . . . . . . 7

2.1.1 State . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72.1.2 Measurement Data . . . . . . . . . . . . . . . . . . . . . . 82.1.3 Control Data . . . . . . . . . . . . . . . . . . . . . . . . . 82.1.4 Belief Distribution . . . . . . . . . . . . . . . . . . . . . . 8

3 The Bayesian Filter 93.1 An Overview of the Bayes Filter . . . . . . . . . . . . . . . . . . 93.2 Derivation of the Bayes Filter . . . . . . . . . . . . . . . . . . . . 93.3 The Markov Assumption . . . . . . . . . . . . . . . . . . . . . . . 123.4 Necessity to Restrict to Gaussian Distributions . . . . . . . . . . 12

4 The Kalman Filter 144.1 Explanation of the Kalman Filter Algorithm . . . . . . . . . . . 144.2 Application of the Kalman Filter on Robot Soccer . . . . . . . . 18

4.2.1 The Variables of the Kalman Filter . . . . . . . . . . . . . 194.2.2 The Modelling of Robot Soccer Using Python Code . . . 21

5 Conclusion 24

2

Page 3: The Application of the Kalman Filter on Robot Soccergauss.vaniercollege.qc.ca/~iti/proj/Dylan_Zachary.pdf · Robot soccer has the same underlying rules as human soccer, but with a

Abstract

Bayesian Filters are algorithms which allow for the recursive calculationof the current belief of a state. It allows robots to move and make decisionsbased on its model of the current state. Additionally, it does not limit robotsto performing a simple task autonomously, rather it allows to robots to reactbased on what the current state is in order to accomplish a specific task. Oneof the most common variations of the Bayesian filter is the Kalman filter, whichallows the Bayes filter to be modelled linearly. The non-linear case is seen inthe extended Kalman filter, which will not be discussed in this paper. Thispaper discusses the Bayes filter and some of its basic properties as well as oneof its derivatives, the Kalman filter. The Kalman filter is then applied to areal world scenario in the context of robot soccer. The robots playing socceruse the Kalman filter to model the position and velocity of the ball in the xand y directions. The computations used by the robots have been found tohave excellent accuracy in modelling the velocity and position of the ball, andcarry very small discrepancies from the true trajectory. Kalman and Bayesfilter modelling are very important fields of study because they not only pushforward the development of artificial intelligence, but also push forward thehuman understanding of the brain.

1 Introduction

Robotics has become one of the most predominant fields of study in thelast few decades. The goal is to build a robot which can exist in the physicalworld and perform actions based on its perception of the environment throughits sensors, much like a human. Over the years, many successful robotic systemshave come to fruition, such as actuated arms used during surgery or in assem-bly lines, self-driving cars, or robotic vehicles used in planetary exploration.The opportunities robotics provides are endless, and humans are continuouslypushing their understanding in order to create robots which function more flu-idly and more autonomously. As such, artificial intelligence has also undergonemany advancements, and robotic systems are being placed in new situationswhere they must operate in unpredictable and unstructured environments, thatare not limited to the repetition of identical tasks. The Robot Soccer WorldCup, also known as RoboCup, was created under this idea; to provide an un-predictable environment for robots to operate in, in order to push the humanunderstanding of artificial intelligence.

The concept of robots playing soccer was first initialized in 1992 by a groupof Japanese scientists who gathered together to discuss the major challengesof artificial intelligence. This gathering eventually led to the creation of theFederation of International Robot-soccer Association (FIRA) in 1997. Thatyear, the first official RoboCup was held in Nagoya Japan, where 40 teams

3

Page 4: The Application of the Kalman Filter on Robot Soccergauss.vaniercollege.qc.ca/~iti/proj/Dylan_Zachary.pdf · Robot soccer has the same underlying rules as human soccer, but with a

participated, and over 5000 spectators attended. The creators of the RoboCuphad set a goal to have fully autonomous robots capable of beating the tophuman players of the FIFA World Cup by the year 2050. Since its creation,the competition has expanded and now holds multiple versions of robot soccer,where different types of robots compete. Most recently, the 22nd edition of thecompetition took place in June of 2018, and was held in Montreal. Over 5000robots competed through various divisions.

Robot soccer has the same underlying rules as human soccer, but with a fewexceptions. Some characteristics which distinguish it from FIFA is that gameslast 20 minutes (2 halves of 10 minutes), the games are played on artificial turf,and the field’s dimensions are 9 m by 6 m. 2.6 m separate the goal posts andgames are usually played with 1 to 4 players. The robots vary in size, beingkid-sized, and adult-sized, depending on which league they are participating in.The image above shows a picture of a humanoid kid-size league, where robotsmeasure between 40 and 90 cm tall.

4

Page 5: The Application of the Kalman Filter on Robot Soccergauss.vaniercollege.qc.ca/~iti/proj/Dylan_Zachary.pdf · Robot soccer has the same underlying rules as human soccer, but with a

The robots are prohibited to exhibit “forceful contact that significantlydestabilizes a player, such that walking and/or kicking is impeded” (RoboCupHumanoid League Rulebook 2018). This includes falling into a player or walkingcarelessly into another player at a significant speed. Therefore, the robots areexpected to be able to walk and run dynamically, stand upright, and recoverfrom a fall and kick the ball while maintaining balance. Additionally, they mustbe able to localize themselves, the ball, other players, and the field through theirsensors. It is prohibited for a robot to measure Earth’s magnetic field to orientthemselves. As such, the robots rely on their sensors and cameras, and use thelines of on the field in order to orient themselves. These sensors are also usedto identify objects in front of them, as well as measure distances, such as thedistance between the robot and the ball.

As stated, the goal of the RoboCup is to create robots capable of competingagainst human soccer players. To reflect this idea, the robot’s form is humanoid,and their actions are restricted to the kinematic equivalence of human motion.For example, their neck joint can only move 270o horizontally and 180o verti-cally. They also are allowed sensors which measure volume, frequency, touch,force, and temperature. Furthermore, they can also measure the local state ofthe system, such as voltages, currents, forces, movements, accelerations, androtational speed. As there are many sensors incorporated into the robots, thelikelihood of accurately predicting a state becomes more difficult, especially con-sidering the unpredictability of the world. Even sensors and motors are subjectto noise. Certain things like angle of orientation, roughness of ground, positionof opposing player, and many more, all contain noise because they exist in thereal world. As a result, the robot must be implemented with an appropriateprobabilistic model which will be able to account for the randomness of therobot’s environment.

Regardless of how accurate a robot’s sensors are, there will always be noisein the environment, which emphasizes the importance of implementing a model

5

Page 6: The Application of the Kalman Filter on Robot Soccergauss.vaniercollege.qc.ca/~iti/proj/Dylan_Zachary.pdf · Robot soccer has the same underlying rules as human soccer, but with a

which takes into account uncertainty while computing accurate predictions offuture states. As a result, modern day robotics often prefers probabilistic mod-elling as opposed to deterministic modelling. Deterministic modelling predictsone course of action in a given environment or situation. It does not take intoaccount alternative courses of action or noise. The world does not favor deter-ministic modelling since there are almost infinitely many sources of noise. Thus,having a more flexible model which accounts for such randomness is preferred,which is why robots use probabilistic modelling. Probabilistic modelling takesinto account all plausible dynamics in a distribution, as well as accounting fornoise. Rather than predicting one exact value for the outcome of an event, itderives a possible set of solutions based on the initial information of the sys-tem, and plots them under a probability distribution curve. Another benefit toprobabilistic modelling is that it allows for approximate but controlled calcula-tions. As a result, the robot can compute calculations much more quickly andefficiently.

The preferred algorithm for probabilistic modelling in modern robotics isthe Kalman Filter, which is a derivation of the Bayesian filter, and was origi-nally conceptualized in the late 1950’s by Rudolph Kalman. Despite being metwith skepticism in the 1950’s, it is now one of the most popular applications ofprobabilistic modelling. It is used in many different fields, but is widely used incontrol systems, navigation, signal processing, and guidance; it was even usedin the navigation of the spacecraft during the Apollo missions in the 1960’s. Itfilters noise, estimates non-observable states and makes predictions that are notlimited to one outcome. The Kalman filter uses a recursive state estimationalgorithm to predict a set of variables and then estimates a joint probabilitydistribution between the variables of the state at different time steps. The al-gorithm takes into account the noise at each time step and limits the number ofcomputations by only taking into account the relationship between the previousstate and the proceeding state. In other words, it determines how much theuncertainty of the previous state will influence the following state. Because itdoes not retain a memory of all previous states, the Kalman filter becomes verylight on computations, making it very efficient for real life applications. Essen-tially, it uses a Bayesian approach where one state or belief is only determinedby the state that immediately precedes it, which only works under the conditionthat the initial belief of the state is accurate. Furthermore, for the algorithmto work, it must assume that all of its components follow a Gaussian distribu-tion, so that the dynamics of the system can take on a linear form. By doingso, continuous states can be modelled through the mean and the covariance ofthe distribution; the distribution is centered around the predicted state denotedby the mean µ, with uncertainty denoted by the covariance Σ. The algorithmessentially functions in two part: the prediction step, and the measurement up-date step, which will be discussed in depth in this paper.

6

Page 7: The Application of the Kalman Filter on Robot Soccergauss.vaniercollege.qc.ca/~iti/proj/Dylan_Zachary.pdf · Robot soccer has the same underlying rules as human soccer, but with a

The robots in the RoboCup actually apply the Kalman filter as one of theways in which they self-localize themselves. They also use the Kalman filterto track the position of the ball on the field. Because the measurement of theball’s location will be taken in such short time fragment, its movement canbe considered linear. Acceleration is set to zero because the acquisition andupdate of the data are very quick, which allows for the impact of acceleration tobe overlooked. Theoretically, assuming there is no noise, the position of the ballwill follow simple kinematic laws. However in the real world, the randomness ofthe environment makes it unrealistic to model the position and velocity of theball using only the kinematic laws. By using a Kalman filter algorithm, it willbe possible to predict the location of the ball based on the previous position,and the knowledge of the initial position. It will also allow the robot to makeits predictions at a fast speed since it operates based on strictly the previousstate, and does not store the unnecessary information of all previous states. Itprovides the robot with fast and easy computations in order to keep up withthe position and velocity of the ball.

In this paper, basic probabilistic concepts such as state and measurementdata will be explained, followed by how the Bayesian and Kalman algorithmsmodel state, and how the robots in robot soccer apply the Kalman filter to playthe game.

2 Basic Concepts of the Bayesian Filter

2.1 State, Environment, and Control Data

2.1.1 State

The state xt is a continuous random variable which accounts for variousfactors relative to the robot’s environment that can influence its future. Itprocesses information relative to the surrounding environment of the robot, aswell as information about the robot itself. Furthermore, states can be dynamicor static. Dynamic states are states which are in continuous motion and changegiven time. Contrarily, static states remain constant and do not change relativeto time. Complete states attempt to model every possible aspect of a robot’senvironment, which is very computationally complex and generally unrealisticgiven the randomness of the world. As a result, the more computationallyefficient incomplete state is favored as it does not take into account unnecessaryinformation. This unnecessary information is then categorized as noise. Stateswhich are by definition incomplete can still be considered complete given theMarkov assumption, described in detail in section 3.3. The assumption allowsthe posterior state at time t to be found as a result of Markov computations.This increases computational efficiency, as only the previous state is needed inorder to determine the posterior state xt. Essentially, the robot does not need tokeep track of every prior state, rather it only requires preceding state xt-1. Thisassumption is only valid given that the initial state x0 is accurately initialized.

7

Page 8: The Application of the Kalman Filter on Robot Soccergauss.vaniercollege.qc.ca/~iti/proj/Dylan_Zachary.pdf · Robot soccer has the same underlying rules as human soccer, but with a

2.1.2 Measurement Data

Measurement data is information obtained by the robot about its environ-ment through its sensors. The sensors provide information about a given stateand allow the robot to physically alter the state through actions. Measurementdata at time t is denoted by the variable zt. This information improves therobot’s knowledge of a given state and allows for the robot to make better de-cisions. Simple static observation improves a robot’s knowledge of any givenstate, as it is simply gathering information. Alternatively, a robot in motionwill have a decreased knowledge of state because of the dynamic nature of theenvironment. The continuously changing state found when a robot is in motionincreases the influence of noise, which makes planning out the best course ofaction more difficult. This is counterbalanced by incorporating measurementsinto the state estimation at every time step.

2.1.3 Control Data

Control data is responsible for modelling the change in state and environmentof the robot, and is denoted by the variable ut. Control data monitors how theposterior state has changed given a certain action in order to provide informationon the current state. For example, control data will measure how much a robot’smotors have turned in order to provide the robot information on its current pose.It can also serve as a correction update to improve the accuracy of modelling.

2.1.4 Belief Distribution

The belief distribution is a probabilistic model representing the robot’s inter-nal knowledge about the state of the environment. Belief state is computation-ally essential for the robot since the true state of the environment is unknown.As a result, the robot must rely on its internal knowledge to determine what itbelieves the current state is. The belief state at time t is modelled by the prob-ability distribution bel(xt). Furthermore, the belief state can be represented bya probability density function, which models the current state, given all priorknowledge on the environment and control data:

bel(xt) = p(xt|z1:t, u1:t)

Furthermore, the robot also makes predictions of what the upcoming statewill be based on all past results up until the previous result. This prediction be-lief is denoted by the distribution bel(xt), and is also the result of a probabilisticequation:

bel(xt) = p(xt|z1:t−1, u1:t)

This takes into account all prior knowledge about the environment, as wellas the control data up until time t, but not the most recent observation. Thisallows for the calculation of the probability of the state at time t. The predictionbelief is essentially a prediction of the current state given the entire history of

8

Page 9: The Application of the Kalman Filter on Robot Soccergauss.vaniercollege.qc.ca/~iti/proj/Dylan_Zachary.pdf · Robot soccer has the same underlying rules as human soccer, but with a

the observations, and is used to calculate the belief distribution. The step ofincorporating the current observation zt into the predicted belief distribution isknown as the Measurement Update.

3 The Bayesian Filter

3.1 An Overview of the Bayes Filter

The Bayes Filter is a recursive algorithm allows the robot to calculate itsbelief of the current state, bel(xt), given the previous state bel(xt-1). This cal-culation is done in two essential steps:

1. The prediction belief bel(xt) is obtained by taking the integral of thebelief at the previous state, bel(xt-1), multiplied by the probability distributionof the state xt given control data ut and the previous state xt-1:

bel(xt) =

∫p(xt|ut, xt−1)bel(xt−1) dx

2. Once the prediction belief has been calculated, the Bayes filter then mul-tiplies bel(xt) with the probability that the observation zt is realized. Thismultiplication does not return a probability, thus it is normalized by the nor-malization constant η.

bel(xt) = η p(zt|xt)bel(xt)

This is the crucial Bayesian step which integrates the observations in the robot’sbeliefs about the predicted state. Thus, the Bayes filter algorithm is:

bel(xt) =

∫p(xt|ut, xt−1)bel(xt−1) dx (1)

bel(xt) = η p(zt|xt)bel(xt) (2)

This provides the belief of the state at time t. One time step later, bel(xt-1)becomes bel(xt), and gets fed back into equation 1 of the filter. As a result, thefilter is recursive.

3.2 Derivation of the Bayes Filter

In order to derive the Bayes filter, it will be shown that it correctly calculatesstate probability distribution p(xt|z1:t, u1:t) from the previous state distributionone step earlier: p(xt-1|z1:t-1, u1:t-1). Furthermore, in order for the filter to becorrect, the initial belief state, bel(x0) must be correct. The Bayes filter, atits core, follows Bayes’ rule. As such, the first step in deriving the Bayes filter

9

Page 10: The Application of the Kalman Filter on Robot Soccergauss.vaniercollege.qc.ca/~iti/proj/Dylan_Zachary.pdf · Robot soccer has the same underlying rules as human soccer, but with a

above is to apply Bayes’ rule:

p(xt|z1:t, u1:t) =p(zt|xt, z1:t−1, u1:t−1)p(xt|z1:t−1, u1:t−1)

p(zt|z1:t, u1:t)

The equation then get simplified by rewriting the denominator p(zt|z1:t, u1:t)as the normalization factor η. Thus, the equation becomes:

p(xt|z1:t, u1:t) = η p(zt|xt, z1:t−1, u1:t−1)p(xt|z1:t−1, u1:t−1)

This only works if the density p can be considered a complete model of thestate of the environment. The idea that the state is complete can be exploitedto further simplify the equation; This Markov assumption means that we canuse the following simplification:

p(zt|xt, z1:t−1, u1:t) = p(zt|xt)

This equation essentially states that the historical control data is not neededto determine the measurement data if the state is complete. The complete statewill have already taken into account everything necessary, so the control databecomes obsolete. When substituted into the equation above, the Bayes filteris further simplified to:

p(xt|z1:t, u1:t) = η p(zt|xt)p(xt|z1:t−1, u1:t−1)

Furthermore, the predicted belief state:

bel(xt) = p(xt|z1:t−1, u1:t)

can also be substituted into the equation, resulting in equation 2 of the BayesianFilter Algorithm:

bel(xt) = η p(zt|xt)bel(xt)

10

Page 11: The Application of the Kalman Filter on Robot Soccergauss.vaniercollege.qc.ca/~iti/proj/Dylan_Zachary.pdf · Robot soccer has the same underlying rules as human soccer, but with a

The derivation of the first equation in the algorithm first begins with theexpansion of the formula:

bel(xt) = p(xt|xt−1, z1:t−1, u1:t)

This can be expanded into:

bel(xt) =

∫p(xt−1, z1:t−1, u1:t)p(xt|xt−1, z1:t−1, u1:t) dxt−1

Once again, the assumption that the state is complete can allow for the im-plementation of the following formula to simplify the above equation:

p(xt|xt−1, z1:t−1, u1:t) = p(xt|xt−1, ut)

zt-1 is not necessary since the state is assumed to be complete; the state hasalready taken the information into account. Control data ut cannot be omitted,since it provides information on the change of state. This results in the followingformula:

bel(xt) =

∫p(xt−1, z1:t−1, u1:t)p(xt|xt−1, ut) dxt−1

Recalling from the section on belief distribution, substituting the equation:

bel(xt) = p(xt|z1:t, u1:t)

will result in equation 1 of the Bayesian filter. Thus:

bel(xt) =

∫p(xt|ut, xt−1)bel(xt−1) dx

11

Page 12: The Application of the Kalman Filter on Robot Soccergauss.vaniercollege.qc.ca/~iti/proj/Dylan_Zachary.pdf · Robot soccer has the same underlying rules as human soccer, but with a

3.3 The Markov Assumption

The Bayes Filter assumes that the world is Markovian. In other words, itassumes that the state is complete. It suggests that all past and future statesare independent if one knows the current state. It allows the current state to becomputed as a result of a Markov chain, omitting the need for any states otherthan the previous one. The Markov assumption only works properly under theadditional assumption that the initial state x0 is correctly initialized. Correctlyinitializing the initial state serves as a starting point for the Markov chain, andif it is correct, so will all future states. However, in practice there may bevariables which violate the Markov assumption. One such example is certainaspects of the environment which remain unmodeled in the state xt. Omittingbackground processes in the environment violates the assumption that the stateis complete. Furthermore, there may be Gaussian approximation errors whenapproximating the predicted belief bel(xt).

3.4 Necessity to Restrict to Gaussian Distributions

In order to make the model computationally efficient, it is necessary to re-strict the Bayes filter to Gaussian distributions. The general Bayesian filtermodels its variables based on conditional probabilities, which in general cannotbe modelled by a linear regression. As such, restricting to Gaussian improvescomputational efficiency, “and provides an optimal linear estimator” (Kohan-bash 2014). It also expresses all necessary components of the Bayesian filterusing only two variables: mean µ and covariance Σ. Gaussian modelling modelsa probability distribution curve with best state estimate µ, and with uncertaintyσ. This still allows for modelling of every possible state outcome and takes intoaccount the randomness of the environment. As such, Kalman Filters are oftenadvantageous in the field of robotics, due to the simplicity and computationalefficiency of their algorithm in contrast to a nonlinear Bayesian filter.

To implement the Kalman filter, the posteriors of the Bayesian filter mustfollow the Markov assumption, and the posteriors are Gaussian under the con-dition that the following three properties hold.

1. The next state must be a linear function of the previous state and thecontrol with noise.

xt = Atxt−1 +Btut + εt

Here xt and xt−1 are state vectors, and ut is the control vector. Both are column

12

Page 13: The Application of the Kalman Filter on Robot Soccergauss.vaniercollege.qc.ca/~iti/proj/Dylan_Zachary.pdf · Robot soccer has the same underlying rules as human soccer, but with a

vectors and take on the following form:

xt =

x1,t

x2,t

...xn,t

, ut =

u1,t

u2,t

...un,t

Also, At is a square matrix of size n x n, where n is the dimension of state

vector, xt. When multiplying At with the posterior state vector xt−1 a linearequation is obtained. Similarly, Bt is also a matrix, but of size n x m, wherem is the dimension of the control vector. The multiplication of Bt and ut alsoprovides a linear dependence. Therefore, adding these multiplications allow thestate transition functions to have linear dynamics.

The last variable, εt is a Gaussian random vector that models the randomnessin each change of state with the same dimension as the state vectors. It has amean of 0 and its covariance matrix will be represented as Rt. To determine thestate transition probability, the multivariate normal distribution is used. Firstthe general form of the multivariate Gaussian is seen in the following equationwith column vector V, similar to the state vector xt .

p(V ) = (det 2πΣ)−12 exp {−1

2(V − µ)T Σ−1(V − µ)}

To apply it in a Kalman filter, V will be replaced by the state at time t,the mean, µ in this equation will be the mean of the posterior, which takes theform of Atxt−1 + Btut , and the covariance will be replaced by Rt. This givesthe equation:

p(xt|ut, xt−1)

= (det 2πRt)− 1

2 exp {− 12 (xt − (Atxt−1 +Btut))

TR−1t (xt − (Atxt−1 +Btut))}

2. The measurement probability, p(zt|xt) must also be a linear functionwith additive Gaussian noise. To satisfy this condition, the measurement datawill be determined according to the following equation:

zt = Ctxt + δt

Here Ct is a matrix of size k x n where k is the dimension of the measurementvector zt and where δt is the vector that describes the observational noise. Ithas a multivariate gaussian distribution with mean of 0 and covariance denotedas Qt . The same process performed to arrive at the multivariate equation forstate vectors (seen in the first condition) can be applied to have the measurementprobability be determined by a multivariate Gaussian distribution.

p(zt|xt) = (det 2πQt)− 1

2 exp {−1

2(zt − Ctxt)

TQ−1t (xt − Ctxt)}

13

Page 14: The Application of the Kalman Filter on Robot Soccergauss.vaniercollege.qc.ca/~iti/proj/Dylan_Zachary.pdf · Robot soccer has the same underlying rules as human soccer, but with a

3. The last condition is that the initial belief, bel(xo) must also be a normaldistribution. For this the mean of the initial belief will be denoted by µo and thecovariance matrix of the initial state will be denoted by Σo. This gives bel(xo)determined by the following multivariate distribution:

bel(xo) = p(xo) = (det 2πΣo)−12 exp {−1

2(xo − µo)T Σ−1

o (xo − µo)}

4 The Kalman Filter

4.1 Explanation of the Kalman Filter Algorithm

The Kalman filter is a filter which allows one to compute beliefs about con-tinuous states. It is inapplicable to states which are discrete. The Kalman filterstates that the belief is represented by a multivariate Gaussian distribution withmean µt and covariance Σt. The mean is essentially the best estimator for thestate at time t. The covariance is expressed as a matrix where each of its en-tries is the degree of covariance between the ith state variable and the jth statevariable, making it a square matrix. These matrices will take on the followingforms, given a random state vector xt:

xt =

x1

x2

...xn

, µt =

µ1

µ2

...µn

,

Σt =

V ar(x1) Cov(x1, x2) . . . Cov(x1, xn)

Cov(x2, x1) V ar(x2) . . . Cov(x2, xn)...

.... . .

...Cov(xn, x1) Cov(xn, x2) . . . V ar(xn)

If a robot’s state is being tracked based on its position and velocity, the

mean and covariance can take on the following matrix forms:

µt =

[positionvelocity

], Σt =

[Σpp Σpv

Σvp Σvv

](3)

These matrices provide the necessary information on the current state of therobot. The robot must be able to predict what the next state will be given thecurrent state. The step in which the prediction is made is implemented by thetransformation matrix At. This takes all the possible values of the initial stateand transforms them using the dynamics to a new predicted state. As previouslymentioned, this only works if the starting state was correctly initialized.

In the case where state is defined as the robot’s x and y positions, as well asits x and y velocities, the kinematic equations are used in order to predict thenext state.

14

Page 15: The Application of the Kalman Filter on Robot Soccergauss.vaniercollege.qc.ca/~iti/proj/Dylan_Zachary.pdf · Robot soccer has the same underlying rules as human soccer, but with a

pt = pt−1 + ∆tvt−1 +1

2a∆t2

vt = vt−1 + a∆t

These equations are then rewritten in matrix form, which gives the followingequation:

µt =

[1 ∆t0 1

]µt−1

µt = Atµt−1 (4)

This is a prediction matrix which provides the next state from the previ-ous state. In order to update the covariance matrix, the following property ofcovariance matrices is then applied:

Cov(x) = Σ

Cov(Ax) = AΣAT

Applying this to the covariance of the previous state results in the followingequation, which allows the robot to update the state’s covariance matrix.

Σt = AtΣt−1ATt (5)

Additionally, there are outside factors in the world which can alter the sys-tem. This is denoted by the control vector ut. Assuming that in a scenario, weknow acceleration, our ut will be denoted by a. By converting the kinematicequations into matrix form, the following is obtained:

µt = Atµt−1 +

[∆t2

2∆t

]a

= Atµt−1 +Btut (6)

The control variable serves as a correction factor, which allows for morecomplex models. In the scenario of Robot Soccer however, simpler models arefavored and the control vector ut will simply be 0.

When modelling the real world, everything behaves much more randomlythan it would in a theoretical model. As a result, a variable for noise must beincluded in the equations in order to model uncertainty in any given state. Eachstate exists within a region of uncertainty, with covariance Rt. In other words,the covariance matrix of the noise will be denoted by the variable Rt.

µt = Atµt−1 +Btut + zt (7)

Σt = AtΣt−1ATt +Rt

15

Page 16: The Application of the Kalman Filter on Robot Soccergauss.vaniercollege.qc.ca/~iti/proj/Dylan_Zachary.pdf · Robot soccer has the same underlying rules as human soccer, but with a

One way to improve state estimate is by gathering information about agiven environment through measurements. Measurements are taken by a robot’ssensors, for example. Thus, sensors are modelled with the matrix Ct. Since thereis also noise in the measurements, it will be taken into account in the equationthat determines the measurement and will be denoted by δ.

zexpected = Ctµt + δt (8)

Σexpected = CtΣtCTt (9)

Furthermore, sensors have noise. The covariance of the uncertainty (the sensornoise) will be modelled with the variable Qt and the value of the observedinformation will be denoted by zt.

Based on these observations, the state predictions must be reinterpreted withthe added knowledge of the measurement data. This provides two probabilisticsources of information, one being observed, and one being based on the robot’sprediction of the state. The best possible prediction is one where both the ob-servation and believed state are in agreement, but that will rarely be the casein practice. In Kalman filter modelling, the probabilistic region where the twooverlap is the best estimate of where the true state is. In order to model this bestestimate, the two probabilities are fused together in the Kalman filter algorithm.

Specifically, the two sources of information which are being fused togetherare represented by Gaussian distributions. To illustrate the idea, consider asimple system with a one dimensional state. A single Gaussian distribution hasthe form:

N(x, µ, σ) =1

σ√

2πe

(x−µ)2

2σ2

When multiplying two Gaussian curves together, the resulting curve lies in theregion where the two overlap:

16

Page 17: The Application of the Kalman Filter on Robot Soccergauss.vaniercollege.qc.ca/~iti/proj/Dylan_Zachary.pdf · Robot soccer has the same underlying rules as human soccer, but with a

N(xo, µo, σo) ∗N(x1, µ1, σ1) = N(x′, µ′, σ′) (10)

After several tedious algebraic expansions and manipulations, the equations forthe fused Gaussian distributions take on the following form:

µ′ = µo +σo

2(µ1 − µo)

σo 2 + σ12

(11)

σ′ 2 = σo2 − σo

4

σo 2 + σ12

(12)

They can both be further simplified by factoring out a variable denoted by K,which is also known as the Kalman gain:

K =σo

2

σo 2 + σ12

(13)

Thus, the sources of information about the state (the dynamics and the ob-servations), are fused optimally by a weighed sum; the optimal weights beingprovided by the Kalman gain. The simplified equations take on the form:

µ′ = µo +K(µ1 − µo) (14)

σ′ 2 = σ2 −Kσ2 (15)

In the case where the state is a vector, the Kalman Gain again “specifiesthe degree to which the update measurement is incorporated into the new stateestimate” (Thrun 2005). In other words, it states the importance of the observedmeasurement, and will use it to alter the prediction from the dynamics accordingto their relative importance. For example, a large Kalman gain will increase theimportance of the observed value, as shown below. The fusion of these equationsin matrix form are as follows:

K = Σ(Σ +Qt)−1 (16)

µt = µt +K(zt − zexpected) (17)

Σt = Σt −KΣexpected (18)

Now that all the necessary components to the Kalman filter have been derived,they can all be put together into one cohesive algorithm. By using the equationsfor the predicted measurement (zexpected = Ctµt, Σexpected = CtΣtC

Tt ), and

applying them to the equations above, the following equation is derived whichmodels the covariance and mean at time t:

Ctµt = Ctµt +K(zt − Ctµt) (19)

17

Page 18: The Application of the Kalman Filter on Robot Soccergauss.vaniercollege.qc.ca/~iti/proj/Dylan_Zachary.pdf · Robot soccer has the same underlying rules as human soccer, but with a

CtΣtCTt = CtΣtC

Tt −KCtΣtC

Tt (20)

Furthermore, substituting them into equation 16 provides a formula for theKalman gain:

K = CtΣtCTt (CtΣtC

Tt +Qt)

−1 (21)

From the equations 19 and 20 which were just derived, a Ct and a CTt can be

removed to simplify the equations. This results in the final equations necessaryfor the Kalman Filter Algorithm:

µt = µt +K(zt − Ctµt) (22)

Σt = Σt −KCtΣt ⇒ Σt = Σt(I −KCt) (23)

Kt = ΣtCTt (CtΣtC

Tt +Qt)

−1 (24)

Thus, the Kalman Filter Algorithm is:

1. µt = Atµt−1 +Btut

2. Σt = AtΣt−1ATt +Rt

3. Kt = ΣtCTt (CtΣtC

Tt +Qt)

−1

4. µt = µt +K(zt − Ctµt)

5. Σt = Σt(I −KCt)

This is a very computationally efficient version of the general Bayesian al-gorithm based on the Gaussian assumptions of the distributions of state andobservations.

4.2 Application of the Kalman Filter on Robot Soccer

The robots in RoboCup utilize the Kalman filter exactly as it was describedabove. However, the variables and matrices described above have specific valueswhich are needed in order for the robot to model the state of the ball. In practice,a robot has to model the state of the ball, as well as all other robots and its ownstate. For simplicity, only the state of the ball will be modelled in this paper. Ifthere were no noise, the ball’s motion would follow Newtonian laws, where thepredictions made by the following kinematic equations are respected.

x(t) = xo + vxt , vx(t) = vx0

18

Page 19: The Application of the Kalman Filter on Robot Soccergauss.vaniercollege.qc.ca/~iti/proj/Dylan_Zachary.pdf · Robot soccer has the same underlying rules as human soccer, but with a

y(t) = yo + vyt , vy(t) = vy0

Instead, the true dynamics are computed with the equations above includingnoise sampled from the multivariate Gaussian. The simulations use a Kalmanfilter to compare its predicted distributions to the true state of the position andvelocity of the ball. To do so, the initial state is assumed to be correct witha starting x,y position of (100, 80) and a starting x,y velocity of (-2,-1). Thisgives the following initial state vector:

10080−2−1

4.2.1 The Variables of the Kalman Filter

The variable matrices of the Kalman filter algorithm will now be defined inrelation to robot soccer. The robot models the prediction state µt with a 4×1matrix, which takes into account the x and y coordinates of the ball on the field,as well as the x and y directional velocities of the ball at time t:

µt =

xtytvytvxt

(25)

The robot also models the prediction step matrix At in order to model thestate of the ball at the next time step:

At =

1 0 dt 00 1 0 dt0 0 1 00 0 0 1

(26)

The predicted mean is then updated in discrete time steps, dt, using the pre-diction matrix

xt+1

yt+1

vyt+1

vxt+1

=

1 0 dt 00 1 0 dt0 0 1 00 0 0 1

xtytvytvxt

+ εt (27)

Similarly, a covariance matrix of the state is necessary. The initial covariancematrix is:

Σ0 =

1 0 0 00 1 0 00 0 1 00 0 0 1

(28)

19

Page 20: The Application of the Kalman Filter on Robot Soccergauss.vaniercollege.qc.ca/~iti/proj/Dylan_Zachary.pdf · Robot soccer has the same underlying rules as human soccer, but with a

The covariance matrix is essentially the 4x4 identity matrix I. It is also con-stantly being updated in time steps, dt, with At:

Σt+1 =

1 0 dt 00 1 0 dt0 0 1 00 0 0 1

1 0 0 00 1 0 00 0 1 00 0 0 1

1 0 0 00 1 0 0dt 0 1 00 dt 0 1

+Rt (29)

If the robots were also modelling acceleration, control data would need tobe taken into account. The transformation matrix which updates the controldata is denoted by Bt, a 4 x 4 matrix; however due to the level of modellingfound in this paper the control matrix Bt is not needed. This is because, asmentioned before, computations need to be very quick in order to keep trackof the position and velocity of the ball. The robots do not need to take intoaccount acceleration because of the low ball speeds they are working with, andthe necessity to keep the algorithm as simple as possible.

In order to model the observed results, zt, another matrix is required. Thisobservation matrix Ct is as follows:

Ct =

[1 0 0 00 1 0 0

](30)

This implies that the x- and y-coordinates are observed. In order to getthe measurement data zt, the prediction state matrix µt is multiplied by theobservation matrix Ct, with added noise δ:

[zxtzyt

]=

[1 0 0 00 1 0 0

]xtytvxtvyt

+

[δ1δ2

](31)

The covariance matrix of the measurement noise was created using arbitrarynumbers that are believed to be realistic.

Qt =

[0.1 0.001

0.001 0.1

]Lastly, the model also required a covariance matrix of the state noise, whichwas generated using intuitively correct values, just as it was done for Qt.

Rt =

0.0003 0.0001 0.00002 00.0001 0.0002 0 0.000020.00002 0 0.0003 0.0001

0 0.00002 0.0001 0.0002

In this experiment, there were 200 timesteps, each being recorded 0.1 sec-

onds apart (dt = 0.1).

20

Page 21: The Application of the Kalman Filter on Robot Soccergauss.vaniercollege.qc.ca/~iti/proj/Dylan_Zachary.pdf · Robot soccer has the same underlying rules as human soccer, but with a

4.2.2 The Modelling of Robot Soccer Using Python Code

By running the simulation in Python, the actual trajectory was determinedby sampling the noise according to the model. The simulation generated thefollowing four graphs which model the actual trajectory of the ball with noise.

The top left graph models x-coordinate, the top right graph models y-coordinate, the bottom left models x-velocity, and bottom right models y-velocity of the ball given time. On the coordinate graphs, the red dots arethe actual observations of the robots. The velocity graphs are zoomed in to avery large scale, and show a very significant change in velocity, however thereis little variation in velocity in the actual model. The velocity can actually beconsidered constant. As shown by the graphs, the velocity starts at -2.00 m/sin the x direction, and 20 seconds later has not changed significantly, beingonly -2.10 m/s. Similarly to the y-velocity, which starts at -1.00 m/s and is atapproximately -0.95 m/s 20 seconds later.

Next, the actual x- and y-coordinates were plotted as a function of time, aswell as the predictions computed by the Kalman Filter of these two variables,on the same graph.

21

Page 22: The Application of the Kalman Filter on Robot Soccergauss.vaniercollege.qc.ca/~iti/proj/Dylan_Zachary.pdf · Robot soccer has the same underlying rules as human soccer, but with a

The belief distance is shown in red and is compared to the true distance of theball in blue. The graph on the left models the x-coordinate of the ball given time,and the graph on the right models the y-coordinate of the ball given time. Thebelief distance has very little deviation from the true distance in both graphs,thus demonstrating the strength and accuracy of the Kalman filter algorithm.

The following two graphs model the belief velocity of the ball using theKalman filter algorithm that is being applied by the robot. The graphs showthe belief velocity (red) versus the true velocity of the ball (blue).

The graph on the right models the y-velocity given time, whereas the leftmodels x-velocity given time, and both show the accuracy of the filter. The be-lief velocity is essentially the true velocity, shifted to the right by approximately1.5 seconds. This is because the velocities are not observed directly, but ratherestimated from the dynamics and the observed positions. The observed estima-tion delay mimics the reaction time observed in humans, which is 0.1 seconds.

Next, the true trajectory of the ball was plotted in the x-y plane, as well asthe Kalman Filter model’s belief trajectory of the ball.

22

Page 23: The Application of the Kalman Filter on Robot Soccergauss.vaniercollege.qc.ca/~iti/proj/Dylan_Zachary.pdf · Robot soccer has the same underlying rules as human soccer, but with a

This graph compares the belief trajectory (in terms of x and y position)determined by the Kalman filter (in red) to the true trajectory of the ball (inblue). As mentioned earlier, the graphs are practically identical as it is difficultto distinguish a difference between the two. The initial belief of the state alongwith the arbitrarily chosen covariance matrices for the noise appear to be mod-elled with realistic values as the graphs model the distance and the velocity ofthe ball very accurately.

Finally, the true x- and y-coordinates were ploted as functions of time versusthe straight lines predicted by the Newtonian model.

These two graphs model the theoretical distance based on the kinematicequations (in green) vs the true distance (in blue). By assuming the accelerationis 0, the theoretical distance represented in the graphs by the green lines will beperfectly straight. This model does not take into account the randomness of theenvironment. In reality though, the ball’s motion cannot continuously respectthe kinematic laws of motion because there is noise in the environment. Fromthe graph it becomes noticeable that the line representing the actual trajectoryof the ball (blue) deviates from the straight line that represents the theoreticaltrajectory. This is due to the fact that the blue line also takes into accountthe imperfections of the ground, which consequently causes the ball to travel

23

Page 24: The Application of the Kalman Filter on Robot Soccergauss.vaniercollege.qc.ca/~iti/proj/Dylan_Zachary.pdf · Robot soccer has the same underlying rules as human soccer, but with a

less distance. Theoretically in a perfect world where the ground is perfectly flatand without friction, the ball would travel without any deviation in its pass,thus allowing it to maintain a constant speed. In reality, the noise from theenvironment leads to significant deviations from the straight line behaviour.

5 Conclusion

The Kalman filter is a mathematical alrogithm which has become increas-ingly useful in the modern day and age. It has endless applications and is anessential component of modern robotics. It allows robots to model real worldevents with incredible accuracy. While the Kalman filter was only described inthe linear case in this paper, it can also be extended to the non-linear case, whichis the Extended Kalman Filter. Human understanding of artificial intelligencenot only leads to the creation of more efficient and practical appliances, but italso pushes forward the human understanding of the brain. It is widely believedthat the human brain follows a Bayesian algorithm, as people make decisionsbased on what they believe is the current situation, on what they observe, andbased on past events similar to the current one. Further research in artificialintelligence can not only allow for practical creations, such as self-driving cars,but also pushes forward the field of cognitive science and the understanding ofthe human brain.

24

Page 25: The Application of the Kalman Filter on Robot Soccergauss.vaniercollege.qc.ca/~iti/proj/Dylan_Zachary.pdf · Robot soccer has the same underlying rules as human soccer, but with a

Works Cited

FIRA. “RoboCup Soccer Humanoid League Laws of the Game 2017/2018.”RoboCup, 9 Apr. 2018, robocup.org.

Grewal, Mohinder. ”Applications of Kalman Filtering in Aerospace 1960 tothe Present.”https://www.researchgate.net/publication/224138621ApplicationsofKalmanF iltering

inAerospace1960totheP resentH istoricalP erspectives.

Hui, Jonathan. “Self-Driving Car Object Tracking: Intuition and the Mathbehind Kalman Filter.” Medium.com, Medium, 8 Apr. 2018, medium.com/@jonathanhui/self−driving−object− tracking− intuition−and− the−math−behind−kalman−filter − 657d11dd0a90.

Kohanbash, David. Robotsforroboticists.com, Robotsforroboticists.com, 30Jan. 2014, robotsforroboticists.com/kalman-filtering/.

Schulz, Hannes. Line Structure-Based Localization for Soccer Robots. 7Dec. 2009, pdfs.semanticscholar.org/1c5b/55bc412e91b725ff06c6b6134c9908dffeb0.pdf.

Stephanie. “Probabilistic: Definition, Models and Theory Explained.” Statis-tics How To, 1 Jan. 2017, www.statisticshowto.datasciencecentral.com/probabilistic/.

Sushkov, Oleg. “Robot Localisation Using a Kalman Filter.” Robot Local-isation Using a Kalman Filter – Oleg Sushkov – Research Engineer, 27 Nov.2016, osushkov.github.io/kalman-filter/.

Taylor. “Gaussian Assumption in Kalman Filter.” Cross Validated, 17Feb. 2018, stats.stackexchange.com/questions/260996/gaussian-assumption-in-kalman-filter.

Thrun, Sebastian. “Probabilistic Robotics.” ProbabilisticRobotics.pdf, Aug.2005, docs.ufpr.br/ danielsantos/ProbabilisticRobotics.pdf.

Username: Fat32. “Why Does the Kalman Filter Remove Only GaussianNoise?” Signal Processing Stack Exchange, 14 Sept. 2017, 9:35, dsp.stackexchange.com/questions/44908/why-does-the-kalman-filter-remove-only-gaussian-noise.

Username tbabb. “How a Kalman Filter Works, in Pictures.” Bzarg, Bzarg.com,11 Aug. 2011, www.bzarg.com/p/how-a-kalman-filter-works-in-pictures/.

Wikipedia. “1997 Robocup 2D Soccer Simulation League.” Wikipedia, Wiki-media Foundation, 1 Sept. 2018, en.wikipedia.org/wiki/1997Robocup2DSoccerSimulationLeague.

25

Page 26: The Application of the Kalman Filter on Robot Soccergauss.vaniercollege.qc.ca/~iti/proj/Dylan_Zachary.pdf · Robot soccer has the same underlying rules as human soccer, but with a

Wikipedia. “Rudolf E. Kalman.” Wikipedia, Wikimedia Foundation, 15Nov. 2018, en.wikipedia.org/wiki/RudolfE .K

26