Copy edit of chapter 8.
Note fully done, still have to figure out what to do with the ball tracking code, and add a control example to the chapter.
This commit is contained in:
@@ -83,8 +83,13 @@ def plot_measurements(xs, ys=None, color='r', lw=2, label='Measurements', **kwar
|
||||
|
||||
|
||||
|
||||
def plot_residual_limits(Ps):
|
||||
std = np.sqrt(Ps)
|
||||
def plot_residual_limits(Ps, stds=1.):
|
||||
""" plots standand deviation given in Ps as a yellow shaded region. One std
|
||||
by default, use stds for a different choice (e.g. stds=3 for 3 standard
|
||||
deviations.
|
||||
"""
|
||||
|
||||
std = np.sqrt(Ps) * stds
|
||||
|
||||
plt.plot(-std, color='k', ls=':', lw=2)
|
||||
plt.plot(std, color='k', ls=':', lw=2)
|
||||
|
||||
35
code/kf_design_internal.py
Normal file
35
code/kf_design_internal.py
Normal file
@@ -0,0 +1,35 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Created on Mon Jul 13 13:20:27 2015
|
||||
|
||||
@author: Roger
|
||||
"""
|
||||
|
||||
from filterpy.kalman import UnscentedKalmanFilter as UKF
|
||||
from filterpy.kalman import JulierSigmaPoints
|
||||
from math import atan2
|
||||
import numpy as np
|
||||
|
||||
def hx(x):
|
||||
""" compute measurements corresponding to state x"""
|
||||
dx = x[0] - hx.radar_pos[0]
|
||||
dy = x[1] - hx.radar_pos[1]
|
||||
return np.array([atan2(dy,dx), (dx**2 + dy**2)**.5])
|
||||
|
||||
def fx(x,dt):
|
||||
""" predict state x at 'dt' time in the future"""
|
||||
return x
|
||||
|
||||
def set_radar_pos(pos):
|
||||
global hx
|
||||
hx.radar_pos = pos
|
||||
|
||||
def sensor_fusion_kf():
|
||||
global hx, fx
|
||||
# create unscented Kalman filter with large initial uncertainty
|
||||
points = JulierSigmaPoints(2, kappa=2)
|
||||
kf = UKF(2, 2, dt=0.1, hx=hx, fx=fx, points=points)
|
||||
kf.x = np.array([100, 100.])
|
||||
kf.P *= 40
|
||||
return kf
|
||||
|
||||
@@ -359,8 +359,6 @@ def plot_track(ps, zs, cov, std_scale=1,
|
||||
plot_P=True, y_lim=None,
|
||||
title='Kalman Filter'):
|
||||
|
||||
print(std_scale)
|
||||
|
||||
count = len(zs)
|
||||
actual = np.linspace(0, count - 1, count)
|
||||
cov = np.asarray(cov)
|
||||
|
||||
Reference in New Issue
Block a user