update patch generation 3d
This commit is contained in:
+38
-2
@@ -23,6 +23,37 @@ except:
|
||||
print("PyQtGraph is not installed. Please install it using 'pip install pyqt5 pyqtgraph'.")
|
||||
exit()
|
||||
|
||||
def lp_filter(series, alpha=0.5):
|
||||
series = np.asarray(series)
|
||||
if series.ndim == 0:
|
||||
return float(series)
|
||||
if series.shape[0] < 2:
|
||||
return float(series[-1])
|
||||
return float(series[-1] * alpha + series[-2] * (1 - alpha))
|
||||
|
||||
def median_filter(series, window_size=5):
|
||||
series = np.asarray(series)
|
||||
if series.ndim == 0:
|
||||
return float(series)
|
||||
if series.shape[0] == 0:
|
||||
return 0.0
|
||||
try:
|
||||
window_n = max(1, int(window_size))
|
||||
except (TypeError, ValueError):
|
||||
window_n = 1
|
||||
return float(np.median(series[-window_n:]))
|
||||
def moving_average(series, window_size=5):
|
||||
series = np.asarray(series)
|
||||
if series.ndim == 0:
|
||||
return float(series)
|
||||
if series.shape[0] == 0:
|
||||
return 0.0
|
||||
try:
|
||||
window_n = max(1, int(window_size))
|
||||
except (TypeError, ValueError):
|
||||
window_n = 1
|
||||
return float(np.mean(series[-window_n:]))
|
||||
|
||||
def create_plot():
|
||||
p1 = win.addPlot(title="法向力")
|
||||
p1.setLabel('bottom', '时间', units='s')
|
||||
@@ -100,7 +131,7 @@ p1, p2, p3, plot_af, plot_tfx, plot_tfy = create_plot()
|
||||
data = np.zeros([npoints,2,3])
|
||||
start_time = None # Will be set when sensor starts
|
||||
for i in range(3):
|
||||
data[:,0,i] = np.linspace(-npoints,0,npoints)
|
||||
data[:,0,i] = np.linspace(-npoints,0,npoints)/30
|
||||
|
||||
|
||||
|
||||
@@ -164,6 +195,7 @@ def main():
|
||||
|
||||
# 更新实时曲线
|
||||
current_time = time.time() - start_time
|
||||
data_filtered = data.copy()
|
||||
for i in range(3):
|
||||
data[:-1, 0, i] = data[1:, 0, i] # 时间轴左移
|
||||
data[:-1, 1, i] = data[1:, 1, i] # 力数据左移
|
||||
@@ -171,7 +203,11 @@ def main():
|
||||
data[-1, 1, 0] = fn
|
||||
data[-1, 1, 1] = fx
|
||||
data[-1, 1, 2] = fy
|
||||
update(plot_af, plot_tfx, plot_tfy, data, p1, p2, p3) # 更新曲线
|
||||
# 对最新采样点做一阶低通,滤波对象是历史曲线而不是单个标量。
|
||||
data_filtered[-1, 1, 0] = moving_average(data[:, 1, 0])
|
||||
data_filtered[-1, 1, 1] = moving_average(data[:, 1, 1])
|
||||
data_filtered[-1, 1, 2] = moving_average(data[:, 1, 2])
|
||||
update(plot_af, plot_tfx, plot_tfy, data_filtered, p1, p2, p3) # 更新曲线
|
||||
|
||||
key = cv2.waitKey(1)
|
||||
if key & 0xFF == ord("q"):
|
||||
|
||||
Reference in New Issue
Block a user