Skip to content

Commit

Permalink
Minor updates to comments and constants
Browse files Browse the repository at this point in the history
  • Loading branch information
botprof committed Nov 13, 2023
1 parent 1a5b00b commit 52de113
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions PF_range.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
x_pf = np.zeros((3, M, N))

# Set the covariance matrices
Q = np.diag([SIGMA_SPEED ** 2, SIGMA_SPEED ** 2])
Q = np.diag([SIGMA_SPEED**2, SIGMA_SPEED**2])

# Initialize the vehicle's true state
x = np.zeros((3, N))
Expand Down Expand Up @@ -119,16 +119,17 @@
# FUNCTION TO MODEL RANGE TO FEATURES


def range_sensor(x, f_map, R, r_max, r_min):
def range_sensor(x, f_map, R, R_MAX, R_MIN):
"""Function to model the range sensor."""

# Determine how many total features are available
m = np.shape(f_map)[1]

# Find the indices of features that are within range (r_min, r_max)
# Find the indices of features that are within range (R_MIN, R_MAX)
a = np.array([])
for i in range(0, m):
r = np.sqrt((f_map[0, i] - x[0]) ** 2 + (f_map[1, i] - x[1]) ** 2)
if np.all([r < r_max, r > r_min]):
if np.all([r < R_MAX, r > R_MIN]):
a = np.append(a, i)

# Simulate for each time
Expand Down Expand Up @@ -164,6 +165,7 @@ def range_sensor(x, f_map, R, r_max, r_min):


def pf_resample(x_pf, x_likelihood):
"""Function to resample particles."""

# Get the number of particles
M = x_pf.shape[1]
Expand All @@ -181,6 +183,7 @@ def pf_resample(x_pf, x_likelihood):


def diffdrive_pf(x_pf, v, y, a, f_map, Q, R, T):
"""Particle filter for differential drive vehicle function."""

# Get the number of particles
M = x_pf.shape[1]
Expand Down Expand Up @@ -255,14 +258,14 @@ def diffdrive_pf(x_pf, v, y, a, f_map, Q, R, T):
P_hat[:, :, 0] = np.diag(np.square([5.0, 5.0, 0.1]))

# Set the covariance matrices
Q = np.diag([SIGMA_SPEED ** 2, SIGMA_SPEED ** 2])
Q = np.diag([SIGMA_SPEED**2, SIGMA_SPEED**2])

# Set sensor range
r_max = 25.0
r_min = 1.0
R_MAX = 25.0
R_MIN = 1.0

# Set the range and bearing covariance
R = np.diag([SIGMA_RANGE ** 2])
R = np.diag([SIGMA_RANGE**2])

# Initialize the first particles on the basis of the initial uncertainty
for i in range(1, M):
Expand All @@ -278,7 +281,7 @@ def diffdrive_pf(x_pf, v, y, a, f_map, Q, R, T):
x[:, i] = rk_four(vehicle.f, x[:, i - 1], v, T)

# Run the range and bearing sensor model
y_m, a = range_sensor(x[:, i], f_map, R, r_max, r_min)
y_m, a = range_sensor(x[:, i], f_map, R, R_MAX, R_MIN)

# Run the particle filter
x_pf[:, :, i] = diffdrive_pf(x_pf[:, :, i - 1], v, y_m, a, f_map, Q, R, T)
Expand Down

0 comments on commit 52de113

Please sign in to comment.