# EKF over-correcting?

I've been implementing an extended kalman filter, following Thrun's Probabilistic Robotics implementation. I believe my correct step may be wrong, as the state appears to be corrected far too much.

Here's a screen capture showing the issue https://youtu.be/gkSpFK27yvg

Note, the bottom status reading is the 'corrected' pose coordinates.

This is my correct step:

    def correct(self, reobservedLandmarks):
for landmark in reobservedLandmarks:
storedLandmark = self.getLandmark(landmark.id)

h, q = self.sensorModel(storedLandmark)

JH = np.zeros([2, 3 + (self.landmarkCount*2)])
JH = -1.0/q

JH = -((self.X - storedLandmark.x) / math.sqrt(q))
JH = -((self.X - storedLandmark.y) / math.sqrt(q))
JH = (storedLandmark.y - self.X) / q
JH = -((storedLandmark.x - self.X) / q)

JH[3+(landmark.id*2)] = -JH
JH[4+(landmark.id*2)] = -JH
JH[3+(landmark.id*2)] = -JH
JH[4+(landmark.id*2)] = -JH

R = np.array([[landmark.dist*self.sensorDistError, 0],[0, self.sensorAngleError]])

Z = matmult(JH, self.P, JH.T) + R
K = matmult(self.P, JH.T, np.linalg.inv(Z))

self.X = self.X + matmult(K, inv)
self.P = matmult((np.identity(self.X.shape) - matmult(K, JH)), self.P)


h = The range and bearing of state landmark.

q = (landmark.x - self.X)^2 + (landmark.y - self.X)^2

My sensor covariance errors are 1cm per meter, and pi/180 for the bearing. My assumption was that the correction should be relative to the size of the robot's pose error. Which is very small in this example, as it only moved forward less than 30cm.

Is the kalman gain applied correctly here, and if yes, what other factors would result in this 'over-correcting'?

Thanks.