线性算法验证失败,蠕变导致时飘一直上升
This commit is contained in:
@@ -5,8 +5,9 @@ use crate::serial_core::frame::{FrameHandler, TactileAFrame, TestFrame};
|
||||
use crate::serial_core::model::{HudChartState, HudPacket};
|
||||
use crate::serial_core::record::Recording;
|
||||
use crate::serial_core::record::{FrameTiming, RecordedFrame};
|
||||
use crate::serial_core::sensor_runtime::SensorRuntimeFilter;
|
||||
use anyhow::Result;
|
||||
use log::{debug, info};
|
||||
use log::info;
|
||||
use std::fs::File;
|
||||
use std::future::pending;
|
||||
use std::sync::{Arc, Mutex};
|
||||
@@ -206,7 +207,9 @@ where
|
||||
H: FrameHandler<F, T> + Send + 'static,
|
||||
T: Into<i32>,
|
||||
{
|
||||
info!("run_serial_with_poll");
|
||||
let mut sensor_runtime =
|
||||
SensorRuntimeFilter::new().map_err(|error| anyhow::anyhow!(error))?;
|
||||
|
||||
let mut requester = match poll_mode {
|
||||
PollMode::Disable => None,
|
||||
PollMode::Enabled(r) => Some(r),
|
||||
@@ -238,7 +241,7 @@ where
|
||||
if r.should_request() {
|
||||
if let Some(req) = r.next_request()? {
|
||||
let bytes = codec.encode(&req)?;
|
||||
debug!("send {:02X?}", bytes);
|
||||
// debug!("send {:02X?}", bytes);
|
||||
port.write_all(&bytes).await?;
|
||||
}
|
||||
}
|
||||
@@ -276,10 +279,14 @@ where
|
||||
});
|
||||
|
||||
let display_values = if let Some(vals) = decode_res.as_ref() {
|
||||
let summary = vals.iter().copied().sum::<i32>();
|
||||
chart_state.record_summary(summary as f32);
|
||||
let raw_summary = vals.iter().copied().sum::<i32>();
|
||||
let raw_force_g = raw_to_g1(raw_summary as u32);
|
||||
let stable_force_g =
|
||||
sensor_runtime.process_sample_with_dts(raw_summary as f64, frame.dts_ms());
|
||||
info!("raw force(g) = {raw_force_g:.3}, stable force(g) = {stable_force_g:.3}");
|
||||
chart_state.record_summary(stable_force_g as f32);
|
||||
chart_state.record_pressure_matrix(vals.as_slice());
|
||||
Some(vec![summary])
|
||||
Some(vec![stable_force_g.round() as i32])
|
||||
} else {
|
||||
None
|
||||
};
|
||||
@@ -294,7 +301,38 @@ where
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// 鍦?src-tauri/src/serial_core/serial.rs 涓坊鍔?
|
||||
fn raw_to_g1(raw: u32) -> f64 {
|
||||
const X: [u32; 11] = [
|
||||
0, 74602, 105503, 131459, 153512, 172041, 193794, 218947, 240580, 295118, 332346,
|
||||
];
|
||||
|
||||
const Y: [f64; 11] = [
|
||||
0.0, 160.0, 260.0, 360.0, 460.0, 560.0, 660.0, 860.0, 1060.0, 1560.0, 2060.0,
|
||||
];
|
||||
|
||||
let n = X.len();
|
||||
if raw <= X[0] {
|
||||
return Y[0] / 100.0;
|
||||
}
|
||||
if raw >= X[n - 1] {
|
||||
return Y[n - 1] / 100.0;
|
||||
}
|
||||
|
||||
let mut left = 0;
|
||||
let mut right = n - 1;
|
||||
|
||||
while left + 1 < right {
|
||||
let mid = (left + right) / 2;
|
||||
if raw < X[mid] {
|
||||
right = mid;
|
||||
} else {
|
||||
left = mid;
|
||||
}
|
||||
}
|
||||
|
||||
let ratio = (raw - X[left]) as f64 / (X[right] - X[left]) as f64;
|
||||
Y[left] + ratio * (Y[right] - Y[left])
|
||||
}
|
||||
pub async fn run_serial_with_calibration(
|
||||
app: AppHandle,
|
||||
mut port: SerialStream,
|
||||
|
||||
Reference in New Issue
Block a user