Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
96129 views
1
# -*- coding: utf-8 -*-
2
3
"""Copyright 2015 Roger R Labbe Jr.
4
5
FilterPy library.
6
http://github.com/rlabbe/filterpy
7
8
Documentation at:
9
https://filterpy.readthedocs.org
10
11
Supporting book at:
12
https://github.com/rlabbe/Kalman-and-Bayesian-Filters-in-Python
13
14
This is licensed under an MIT license. See the readme.MD file
15
for more information.
16
"""
17
18
from numpy.random import randn
19
from math import radians, atan2
20
21
22
class RadarSim(object):
23
""" Simulates the radar signal returns from an object flying
24
at a constant altityude and velocity in 1D. Assumes random
25
process noise - altitude and velocity varies a bit for each call.
26
"""
27
28
29
def __init__(self, dt, pos=0., vel=100., alt=1000.):
30
self.dt = dt
31
self.pos = pos
32
self.vel = vel
33
self.alt = alt
34
35
36
def get_range(self, process_err_pct=0.05):
37
""" Returns slant range to the object. Call once for each
38
new measurement at dt time from last call.
39
"""
40
41
vel = self.vel + 5*randn()
42
alt = self.alt + 10*randn()
43
44
self.pos += vel*self.dt
45
46
err = (self.pos * process_err_pct) * randn()
47
slant_range = (self.pos**2 + alt**2)**.5 + err
48
49
return slant_range
50
51
52
def get_range_bearing(self, angle_sigma_deg=1.):
53
r = self.get_range()
54
a = atan2(self.alt, self.x)
55
a += randn() * radians(angle_sigma_deg)
56
57
return r, a
58
59
60