Certainly! Below is a Python script that calculates the road profile and the instantaneous IRI, as well as the IRI over 20m and 100m intervals, based on measured sprung and unsprung accelerations of a running car. The script includes two methods: one using a Kalman filter and another using a quarter-car model.
Please note that you will need to provide the acceleration data and vehicle parameters for the script to work correctly.
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
# Constants
SAMPLING_RATE = 800 # Hz
DELTA_T = 1 / SAMPLING_RATE
# Vehicle parameters (example values, replace with actual values)
m_s = 250 # Sprung mass (kg)
m_u = 35 # Unsprung mass (kg)
k_s = 8000 # Suspension stiffness (N/m)
k_t = 160000 # Tire stiffness (N/m)
c_s = 350 # Suspension damping coefficient (Ns/m)
# Load acceleration data (replace 'acceleration_sprung.csv' and 'acceleration_unsprung.csv' with your data files)
# Data should be in columns: time, acceleration
# For demonstration, let's assume they are numpy arrays
# time = np.arange(0, total_time, DELTA_T)
# acceleration_sprung = np.loadtxt('acceleration_sprung.csv', delimiter=',')
# acceleration_unsprung = np.loadtxt('acceleration_unsprung.csv', delimiter=',')
# For this example, let's simulate some acceleration data
total_time = 60 # seconds
time = np.arange(0, total_time, DELTA_T)
num_samples = len(time)
# Simulated acceleration data (replace this with your actual data)
np.random.seed(0)
acceleration_sprung = 0.1 * np.random.randn(num_samples)
acceleration_unsprung = 0.2 * np.random.randn(num_samples)
# Method 1: Using Kalman Filter
def kalman_filter(acc_sprung, acc_unsprung):
# State vector: x = [z_s, z_u, z_s_dot, z_u_dot]
# Process noise covariance matrix Q and measurement noise covariance R need to be defined
# Initialize state estimates and covariance matrix
x_est = np.zeros((4, num_samples))
P = np.eye(4)
Q = np.eye(4) * 1e-5 # Process noise covariance
R = np.eye(2) * 1e-2 # Measurement noise covariance
# State transition matrix A
A = np.array([
[1, 0, DELTA_T, 0],
[0, 1, 0, DELTA_T],
[- (k_s / m_s) * DELTA_T, (k_s / m_s) * DELTA_T, 1 - (c_s / m_s) * DELTA_T, (c_s / m_s) * DELTA_T],
[(k_s / m_u) * DELTA_T, -((k_s + k_t) / m_u) * DELTA_T, (c_s / m_u) * DELTA_T, 1 - (c_s / m_u) * DELTA_T]
])
# Input matrix B (assuming road profile r is unknown, set to zero)
B = np.zeros((4, 1))
# Measurement matrix H
H = np.array([
[0, 0, 1, 0], # z_s_ddot (approximated by z_s_dot change)
[0, 0, 0, 1] # z_u_ddot
])
# Measurements
z = np.vstack((acc_sprung, acc_unsprung))
for i in range(1, num_samples):
# Predict
x_pred = A @ x_est[:, i-1] # + B * u (u is zero)
P_pred = A @ P @ A.T + Q
# Update
y_measure = z[:, i]
y_pred = H @ x_pred
S = H @ P_pred @ H.T + R
K = P_pred @ H.T @ np.linalg.inv(S)
x_est[:, i] = x_pred + K @ (y_measure - y_pred)
P = (np.eye(4) - K @ H) @ P_pred
# Estimated road profile approximation (since we have no direct measurement of r, we can estimate z_u - (k_t)^-1 * Force)
road_profile_estimated = x_est[1, :] - (m_u / k_t) * acceleration_unsprung
return road_profile_estimated
# Method 2: Using Quarter-Car Model
def quarter_car_model(acc_sprung, acc_unsprung):
# Simplified method to estimate road profile from accelerations by double integration
# Due to noise, we need to use filtering to avoid drift
# Initialize displacement arrays
z_s = np.zeros(num_samples)
z_u = np.zeros(num_samples)
v_s = np.zeros(num_samples)
v_u = np.zeros(num_samples)
r = np.zeros(num_samples) # Road profile estimation
for i in range(1, num_samples):
# Integrate accelerations to get velocities
v_s[i] = v_s[i-1] + acc_sprung[i] * DELTA_T
v_u[i] = v_u[i-1] + acc_unsprung[i] * DELTA_T
# Integrate velocities to get displacements
z_s[i] = z_s[i-1] + v_s[i] * DELTA_T
z_u[i] = z_u[i-1] + v_u[i] * DELTA_T
# Estimate road profile based on quarter-car model equations
# Rearranged from the unsprung mass equation
r[i] = z_u[i] - (m_u / k_t) * (acc_unsprung[i])
return r
# Compute road profiles using both methods
road_profile_kalman = kalman_filter(acceleration_sprung, acceleration_unsprung)
road_profile_qcar = quarter_car_model(acceleration_sprung, acceleration_unsprung)
# IRI Calculation
def compute_iri(road_profile, speed_kmh):
# Convert speed to m/s
speed_ms = speed_kmh / 3.6
# Reference quarter-car model parameters for IRI calculation
m_s_ref = 0.25 * 1500 # kg
c_s_ref = 6 * 1000 # Ns/m
k_s_ref = 63 * 1000 # N/m
k_t_ref = 653 * 1000 # N/m
# Simulate vehicle response to the road profile
num_samples = len(road_profile)
DELTA_T = 1 / SAMPLING_RATE
v_ref = speed_ms
# Initialize state variables
z_s = np.zeros(num_samples)
z_u = np.zeros(num_samples)
v_s = np.zeros(num_samples)
v_u = np.zeros(num_samples)
for i in range(1, num_samples):
# Road input at the current time step
if i * DELTA_T * v_ref < len(road_profile) * DELTA_T * v_ref:
r = road_profile[int(i * DELTA_T * v_ref / DELTA_T)]
else:
r = 0
# Equations of motion
a_s = ( -k_s_ref * (z_s[i-1] - z_u[i-1]) - c_s_ref * (v_s[i-1] - v_u[i-1]) ) / m_s_ref
a_u = ( k_s_ref * (z_s[i-1] - z_u[i-1]) + c_s_ref * (v_s[i-1] - v_u[i-1]) - k_t_ref * (z_u[i-1] - r) ) / m_s_ref
# Update velocities
v_s[i] = v_s[i-1] + a_s * DELTA_T
v_u[i] = v_u[i-1] + a_u * DELTA_T
# Update displacements
z_s[i] = z_s[i-1] + v_s[i] * DELTA_T
z_u[i] = z_u[i-1] + v_u[i] * DELTA_T
# Compute the accumulated suspension travel (absolute difference between sprung and unsprung displacements)
accum_susp_travel = np.abs(z_s - z_u)
# Compute IRI over specified intervals
iri_instant = accum_susp_travel / DELTA_T # Instantaneous IRI
iri_20m = []
iri_100m = []
distance = np.arange(num_samples) * DELTA_T * v_ref
total_distance = distance[-1]
# Compute IRI over 20m intervals
num_segments_20m = int(np.floor(total_distance / 20))
for i in range(num_segments_20m):
start_idx = int(i * 20 / (v_ref * DELTA_T))
end_idx = int((i + 1) * 20 / (v_ref * DELTA_T))
iri_segment = np.sum(accum_susp_travel[start_idx:end_idx]) / 20
iri_20m.append(iri_segment)
# Compute IRI over 100m intervals
num_segments_100m = int(np.floor(total_distance / 100))
for i in range(num_segments_100m):
start_idx = int(i * 100 / (v_ref * DELTA_T))
end_idx = int((i + 1) * 100 / (v_ref * DELTA_T))
iri_segment = np.sum(accum_susp_travel[start_idx:end_idx]) / 100
iri_100m.append(iri_segment)
return iri_instant, iri_20m, iri_100m
# For demonstration, let's assume constant speed of 60 km/h
speed_kmh = 60
# Compute IRI using road profile estimated by Kalman filter
iri_instant_kalman, iri_20m_kalman, iri_100m_kalman = compute_iri(road_profile_kalman, speed_kmh)
# Compute IRI using road profile estimated by quarter-car model
iri_instant_qcar, iri_20m_qcar, iri_100m_qcar = compute_iri(road_profile_qcar, speed_kmh)
# Plot results
plt.figure(figsize=(12, 6))
plt.subplot(2, 1, 1)
plt.plot(time, road_profile_kalman, label='Road Profile (Kalman Filter)')
plt.plot(time, road_profile_qcar, label='Road Profile (Quarter-Car Model)')
plt.xlabel('Time (s)')
plt.ylabel('Displacement (m)')
plt.title('Estimated Road Profiles')
plt.legend()
plt.subplot(2, 1, 2)
plt.plot(time, iri_instant_kalman, label='Instantaneous IRI (Kalman Filter)')
plt.plot(time, iri_instant_qcar, label='Instantaneous IRI (Quarter-Car Model)')
plt.xlabel('Time (s)')
plt.ylabel('IRI (m/km)')
plt.title('Instantaneous IRI')
plt.legend()
plt.tight_layout()
plt.show()
print("IRI over 20m intervals (Kalman Filter):", iri_20m_kalman)
print("IRI over 20m intervals (Quarter-Car Model):", iri_20m_qcar)
print("IRI over 100m intervals (Kalman Filter):", iri_100m_kalman)
print("IRI over 100m intervals (Quarter-Car Model):", iri_100m_qcar)
Notes:
- Vehicle Parameters: Replace the example vehicle parameters (
m_s, m_u, k_s, k_t, c_s) with the actual values for your vehicle.
- Acceleration Data: Replace the simulated acceleration data with your measured sprung and unsprung accelerations. The accelerations should be numpy arrays corresponding to the measurements at each time step.
- Kalman Filter Tuning: The process noise covariance
Q and measurement noise covariance R matrices in the Kalman filter need to be tuned based on the characteristics of your system and measurement noise.
- IRI Calculation: The IRI computation in this script is simplified for demonstration purposes. The standard IRI calculation involves filtering the road profile using a specific filter defined by the World Bank. For precise IRI calculations, you should implement the IRI filter as defined in the ASTM E1926 standard.
- Speed Variation: If the vehicle speed varies between 30-80 km/h, you should adjust the
v_ref variable accordingly for each time step based on your speed measurements.
References:
- Sayers, M. W., Gillespie, T. D., & Paterson, W. D. O. (1986). Guidelines for conducting and calibrating road roughness measurements. World Bank Technical Paper Number 46.
- ASTM E1926-08, Standard Practice for Computing International Roughness Index of Roads from Longitudinal Profile Measurements.
Feel free to modify and expand upon this script to fit your specific needs and to incorporate any additional data or functionality required.