初步添加力显示,粗标定可以测试
This commit is contained in:
11
data_processing/1.py
Normal file
11
data_processing/1.py
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
import matplotlib.pyplot as plt
|
||||||
|
|
||||||
|
y = [0, 160, 260, 360, 460, 560, 660, 860, 1060, 1560, 2060]
|
||||||
|
x = [0, 74602, 105503, 131459, 153512, 172041, 193794, 218947, 240580, 295118, 332346]
|
||||||
|
|
||||||
|
plt.plot(x, y)
|
||||||
|
plt.title("Simple Line Plot")
|
||||||
|
plt.xlabel("g")
|
||||||
|
plt.ylabel("raw data")
|
||||||
|
|
||||||
|
plt.show()
|
||||||
BIN
data_processing/~$第一次粗标定.xlsx
Normal file
BIN
data_processing/~$第一次粗标定.xlsx
Normal file
Binary file not shown.
@@ -241,7 +241,8 @@ impl FrameHandler<TactileAFrame, i32> for TactileAHandler {
|
|||||||
match frame {
|
match frame {
|
||||||
TactileAFrame::Rep(rep) => {
|
TactileAFrame::Rep(rep) => {
|
||||||
let vals = TactileACodec::parse_data_frame(&rep.payload)?;
|
let vals = TactileACodec::parse_data_frame(&rep.payload)?;
|
||||||
|
let g = raw_to_g1(vals.iter().sum::<i32>() as u32);
|
||||||
|
debug!("force is {g}");
|
||||||
Ok(Some(vals))
|
Ok(Some(vals))
|
||||||
}
|
}
|
||||||
_ => Ok(None),
|
_ => Ok(None),
|
||||||
@@ -249,12 +250,47 @@ impl FrameHandler<TactileAFrame, i32> for TactileAHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn raw_to_g1(raw: u32) -> f64 {
|
||||||
|
const X: [u32; 11] = [
|
||||||
|
0, 74602, 105503, 131459, 153512, 172041, 193794, 218947, 240580, 295118, 332346,
|
||||||
|
];
|
||||||
|
|
||||||
fn trans_data_2_n(val: i32) -> i32 {
|
const Y: [f64; 11] = [
|
||||||
if val <= 74602 {
|
0.0, 160.0, 260.0, 360.0, 460.0, 560.0, 660.0, 860.0, 1060.0, 1560.0, 2060.0,
|
||||||
val / 466
|
];
|
||||||
} else if val > 74602 && val <= 105503 {
|
|
||||||
|
|
||||||
|
let n = X.len();
|
||||||
|
if raw <= X[0] {
|
||||||
|
return Y[0];
|
||||||
|
}
|
||||||
|
if raw >= X[n - 1] {
|
||||||
|
return Y[n - 1];
|
||||||
|
}
|
||||||
|
|
||||||
|
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]) / 100.0
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod test {
|
||||||
|
use crate::serial_core::codecs::tactile_a::raw_to_g1;
|
||||||
|
#[test]
|
||||||
|
fn raw_to_g1_test() {
|
||||||
|
let input = 198000;
|
||||||
|
let g = raw_to_g1(input);
|
||||||
|
println!("input {input} -> g {g}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user