Modified jerk planner to use no_std and custom sqrt and cbrt routines. These routines do not seem to work yet

This commit is contained in:
TQ Hirsch
2022-04-24 23:59:13 +02:00
parent ce6a6be1e9
commit 7685ed1ab7
6 changed files with 96 additions and 6 deletions

View File

@@ -0,0 +1,36 @@
fn ulp(f: f32) -> f32 {
f32::from_bits((f.to_bits() & 0x7f80_0000) - 0x0b80_0000)
}
fn fn_err(actual: f32, calc: f32) -> f32 {
(calc - actual).abs() / actual
}
fn test_all(fname: &str, actual: fn(f32) -> f32, calc: fn(f32) -> f32) {
let mut max_err = 0f32;
let mut max_err_value = 0f32;
for i in (0x00c0_0000..0x0f7f_ffffu32).map(f32::from_bits) {
// range of normalized floats...
let err = fn_err(actual(i), calc(i));
if err > max_err {
max_err = err;
max_err_value = i;
}
}
let max_err_pct = max_err * 100f32;
println!("{}: {}% @ {}", fname, max_err_pct, max_err_value);
println!(
"Value: 0x{:08x}\n
Calculated: 0x{:08x}\n
Actual: 0x{:08x}",
max_err_value.to_bits(),
calc(max_err_value).to_bits(), actual(max_err_value).to_bits())
}
fn main() {
// test_all("sqrt", f32::sqrt, jerk_control::math_ext::Roots::sqrt);
test_all("cbrt", f32::cbrt, jerk_control::math_ext::Roots::cbrt);
}

View File

@@ -1,2 +1,6 @@
// #![no_std]
pub mod planner;
pub mod executor;
pub mod executor;
pub mod math_ext;

View File

@@ -4,6 +4,7 @@
//! All of their derivations can be found in the motion-control.ipynb file.
use core::num::Wrapping;
use core::option::Option;
pub struct Config {
/// Max jerk, in mm/s^3
@@ -162,7 +163,7 @@ impl Planner {
.clamp(0.0, (1u32 << 31) as f32);
let step_size = config.step_size * 6. * tick_rate * tick_rate * tick_rate / config.j_max;
if step_size > (u32::MAX / 2) as f32 {
eprintln!("Failed to configure planner: stepsize = {}", step_size);
//eprintln!("Failed to configure planner: stepsize = {}", step_size);
return false;
}
self.a_max = a_max as u32;
@@ -212,7 +213,7 @@ impl Planner {
let tv = (dx - ramp_dx) * 2 / s4v as u64;
let tv = ((tv + 1) / 2) as u32;
eprintln!("ta={ta}, tj={tj}, tv={tv}");
//eprintln!("ta={ta}, tj={tj}, tv={tv}");
let j_real = dir * 6;
let mut segments = [Segment::default(); 8];
let seg_params = [