write python script to calculate road profile and IRI, IRI 20m, and IRI 100 m, based on…
- User
write python script to calculate road profile and IRI, IRI 20m, and IRI 100 m, based on measured sprung and unsprung acceleration of a running car (sampling rate 800Hz)
- Assistant
Certainly! Below is a Python script that calculates the road profile and the International Roughness Index (IRI) over 20m and 100m segments based on measured sprung and unsprung accelerations of a running car sampled at 800 Hz.
We'll follow these main steps:
- Data Acquisition: Read the sprung and unsprung acceleration data.
- Road Profile Estimation: Use the measured accelerations to estimate the road profile.
- IRI Calculation: Compute IRI over specified segments (20m and 100m).
Before we proceed, here's a brief overview of the methodology:
-
Road Profile Estimation: We'll use a simple double integration of the unsprung acceleration to estimate the road displacement. In practice, more sophisticated methods might be used, such as implementing a Kalman filter or using a quarter-car model, but for the purpose of this script, we'll keep it straightforward.
-
IRI Calculation: The IRI is calculated by simulating a standard quarter-car model (as per ASTM E1926) over the estimated road profile.
Let's start with the code:
import numpy as np import pandas as pd import scipy.signal as signal import matplotlib.pyplot as plt # Constants SAMPLE_RATE = 800 # Hz DT = 1 / SAMPLE_RATE # Time interval between samples # Vehicle speed (m/s), assuming constant speed VEHICLE_SPEED_KMH = 80 # km/h VEHICLE_SPEED = VEHICLE_SPEED_KMH * 1000 / 3600 # Convert km/h to m/s # Segment lengths in meters SEGMENT_LENGTHS = [20, 100] # m # Quarter-car model parameters for IRI calculation (As per ASTM E1926) # These are standard parameters for the IRI computation BT = 0 # Road input (will be updated with road profile) C = 6 # Suspension damping (kN.s/m) K = 653 # Suspension stiffness (kN/m) MU = 0.15 # Unsprung mass (kg) MS = 0.5 # Sprung mass (kg) KS = 63.3 # Tire stiffness (kN/m) def read_acceleration_data(sprung_file, unsprung_file): """ Reads the sprung and unsprung acceleration data from files. """ # Assuming the data files are in CSV format with a single column of acceleration data. # Replace with the appropriate data reading mechanism if different. sprung_acc = pd.read_csv(sprung_file, header=None).values.flatten() unsprung_acc = pd.read_csv(unsprung_file, header=None).values.flatten() return sprung_acc, unsprung_acc def estimate_road_profile(unsprung_acc): """ Estimates the road profile by double integrating the unsprung acceleration. """ # Remove mean to eliminate any bias unsprung_acc_demeaned = unsprung_acc - np.mean(unsprung_acc) # Integrate acceleration to get velocity velocity = np.cumsum(unsprung_acc_demeaned) * DT # Remove velocity drift (high-pass filter) sos = signal.butter(2, 0.1, 'highpass', fs=SAMPLE_RATE, output='sos') velocity_filtered = signal.sosfilt(sos, velocity) # Integrate velocity to get displacement (road profile) displacement = np.cumsum(velocity_filtered) * DT # Remove displacement drift (high-pass filter) displacement_filtered = signal.sosfilt(sos, displacement) return displacement_filtered def calculate_iri(road_profile, segment_length): """ Calculates the IRI over the specified segment length. """ # Number of samples per segment samples_per_segment = int(segment_length / VEHICLE_SPEED * SAMPLE_RATE) # Total number of segments num_segments = len(road_profile) // samples_per_segment iries = [] # List to store IRI for each segment for i in range(num_segments): start_idx = i * samples_per_segment end_idx = start_idx + samples_per_segment segment_profile = road_profile[start_idx:end_idx] # Simulate quarter-car model over the segment iri = simulate_quarter_car(segment_profile) iries.append(iri) return iries def simulate_quarter_car(road_profile_segment): """ Simulates the quarter-car model over the given road profile segment and returns the IRI. """ # Initialize state variables zs = 0 # Sprung mass displacement zu = 0 # Unsprung mass displacement dzs = 0 # Sprung mass velocity dzu = 0 # Unsprung mass velocity # Convert parameters to SI units C_Ns_per_m = C * 1000 # Convert kN.s/m to N.s/m K_N_per_m = K * 1000 # Convert kN/m to N/m KS_N_per_m = KS * 1000 # Convert kN/m to N/m # Time vector for the segment t = np.arange(len(road_profile_segment)) * DT # Road input (interpolated to match vehicle speed) # Assuming the vehicle speed is constant distance = VEHICLE_SPEED * t road_input = road_profile_segment # Initialize arrays to store simulation results num_samples = len(road_input) sprung_displacement = np.zeros(num_samples) sprung_velocity = np.zeros(num_samples) # Time integration using Euler method for i in range(1, num_samples): # Road excitation zr = road_input[i] # Equations of motion d2zs = ( -C_Ns_per_m * (dzs - dzu) - K_N_per_m * (zs - zu) ) / MS d2zu = ( C_Ns_per_m * (dzs - dzu) + K_N_per_m * (zs - zu) - KS_N_per_m * (zu - zr) ) / MU # Update velocities dzs += d2zs * DT dzu += d2zu * DT # Update displacements zs += dzs * DT zu += dzu * DT # Store results sprung_displacement[i] = zs sprung_velocity[i] = dzs # Compute IRI as the accumulated absolute suspension velocity per unit distance abs_suspension_velocity = np.abs(sprung_velocity) iri = (1 / VEHICLE_SPEED) * np.sum(abs_suspension_velocity) * DT iri *= 1000 # Convert to mm/m return iri def main(): # File paths to the sprung and unsprung acceleration data sprung_file = 'sprung_acceleration.csv' unsprung_file = 'unsprung_acceleration.csv' # Read acceleration data sprung_acc, unsprung_acc = read_acceleration_data(sprung_file, unsprung_file) # Estimate road profile road_profile = estimate_road_profile(unsprung_acc) # Plot the estimated road profile plt.figure(figsize=(10, 4)) plt.plot(road_profile) plt.title('Estimated Road Profile') plt.xlabel('Sample Index') plt.ylabel('Displacement (m)') plt.show() # Calculate IRI over specified segment lengths for segment_length in SEGMENT_LENGTHS: print(f'\nCalculating IRI over {segment_length}m segments...') iries = calculate_iri(road_profile, segment_length) average_iri = np.mean(iries) print(f'Average IRI over {segment_length}m segments: {average_iri:.2f} mm/m') print(f'IRI values for each segment: {iries}') if __name__ == "__main__": main()Explanation of the Script:
-
Data Reading: The
read_acceleration_datafunction reads the sprung and unsprung acceleration data from CSV files. Ensure your data files (sprung_acceleration.csvandunsprung_acceleration.csv) contain acceleration data in a single column without headers. -
Road Profile Estimation: The
estimate_road_profilefunction estimates the road profile by double integrating the unsprung acceleration. Before integration, we remove the mean to eliminate any biases. We also use high-pass Butterworth filters to remove drift in velocity and displacement resulting from integration of acceleration signals. -
IRI Calculation: The
calculate_irifunction divides the road profile into segments of the specified length and computes the IRI for each segment using thesimulate_quarter_carfunction. -
Quarter-Car Simulation: The
simulate_quarter_carfunction simulates the response of a standard quarter-car model traveling over the road profile segment. It uses time integration (Euler method) to solve the equations of motion and computes the IRI as the accumulated absolute sprung mass velocity per unit distance. -
Main Execution: The
mainfunction ties everything together, reading the data, estimating the road profile, and calculating the IRI over the specified segments. It also plots the estimated road profile.
Notes and Assumptions:
-
Vehicle Speed: The vehicle speed is assumed to be constant at 80 km/h as per standard IRI calculation. Adjust
VEHICLE_SPEED_KMHif necessary. -
Sampling Rate: The sampling rate is given as 800 Hz. Ensure your data matches this rate.
-
Data Files: Replace
'sprung_acceleration.csv'and'unsprung_acceleration.csv'with the actual paths to your acceleration data files. -
Units: All calculations are performed in SI units. Acceleration is assumed to be in m/s².
-
Filters: High-pass filters are used to remove drift from integration. The cutoff frequency (0.1 Hz) may need adjustment based on the characteristics of your data.
Important Considerations:
-
Integration Drift: Double integration of acceleration can lead to significant drift due to noise and biases in the data. Filtering is crucial to get a meaningful road profile.
-
Advanced Methods: For more accurate road profile estimation, consider using more advanced techniques, such as implementing a Kalman filter or using frequency domain methods.
-
IRI Standards: The IRI calculation here is a simplified implementation. For compliance with official standards (e.g., ASTM E1926 or ISO 8608), more precise methods and parameters may be required.
Example Data Files:
Below is an example of how your CSV files might look:
sprung_acceleration.csv:0.1 0.15 0.12 ...unsprung_acceleration.csv:0.05 0.08 0.06 ...Running the Script:
- Ensure you have the necessary data files with correct formatting.
- Install required Python packages if not already installed:
pip install numpy pandas scipy matplotlib - Run the script:
python iri_calculation.py
Visualizing Results:
The script includes plotting the estimated road profile. You can modify or enhance the plots as needed to better visualize your data.
Feel free to ask if you need further assistance or modifications to the script!
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.