-
Notifications
You must be signed in to change notification settings - Fork 0
/
speed_trap_velocity.py
47 lines (36 loc) · 1.98 KB
/
speed_trap_velocity.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# speed_trap_velocity.py
# ----------------------------------------------------------------------------------------------------------
# Uses the recorded signals from the speed trap to calculate the velocity of the striker bar during
# split-Hopkinson pressure bar experiments.
# INPUTS:
# - raw_file: Path to csv file containing oscilloscope data columns Time, Ch1, Ch2, Ch3, Ch4 (string).
# OUTPUTS:
# - velocity: speed of the striker bar.
# Authors: Arthur van Lerberghe ([email protected]) & Kin Shing Oswald Li ([email protected])
# ----------------------------------------------------------------------------------------------------------
# Imported modules:
from pathlib import Path
import pandas as pd
import numpy as np
def speed_trap_velocity(raw_file):
# Inputs:
trap_distance = 50 # Distance between speed traps, mm
trigger_voltage = 24 # Voltage level triggering pulse, V
# Read the csv file and extract necessary columns:
raw_data = pd.read_csv(raw_file, sep=';', skiprows=9, header=None) # Read csv file
time = raw_data.iloc[:, 0] # Time, s
gauge_signal = raw_data.iloc[:, 1:3]
# Find the index where gauge signal exceeds the trigger voltage:
front_trigger_idx = np.argmax(gauge_signal.iloc[:, 0] > trigger_voltage)
back_trigger_idx = np.argmax(gauge_signal.iloc[:, 1] > trigger_voltage)
# Calculate the time at which each signal triggers:
front_trigger_time = time[front_trigger_idx]
back_trigger_time = time[back_trigger_idx]
# Calculate the velocity of the striker bar:
difference = abs(back_trigger_time - front_trigger_time) # Difference between trigger times, s
velocity = (trap_distance / difference) / 10 ** 3 # Velocity of striker bar, m/s
# Print results:
file = Path(raw_file)
print('-' * 80 + '\n' + f"PROCESSING STRIKER VELOCITY OF: {file.parts[-1].split('.')[0]} " '\n' + '-' * 80)
print(f'Original file path:{file}')
return f'Velocity of striker bar: {round(velocity, 3)} m/s'