symplex-build
Build-time code generation for symplex — run the CAS in build.rs, derive Jacobians, forward kinematics and other symbolic results, and emit optimized no_std Rust into $OUT_DIR.
⚠️ Experimental: This crate's API may change before 1.0. It is functional but has limited test coverage.
Usage
Add to your firmware crate's Cargo.toml:
[]
= "0.2"
= "0.2"
Then in build.rs:
use jacobian;
use *;
use fk_position;
use CodeGen;
Or use the convenience builder — DH parameters given as f64 are converted to the exact rational a human meant (0.3 → 3/10) via Context::from_f64_approx:
Then in your library or binary crate:
include!;
The generated file has no dependencies on std (with the std feature off it calls libm), so add to the firmware crate:
[]
= ["std"]
= []
[]
= "0.2" # used when `std` is disabled
TOML configuration
symplex_build::from_toml("robot.toml") returns a pre-populated CodeGen:
[]
= "two_link"
[[]]
= "theta1"
= 0.3
[[]]
= "theta2"
= 0.25
[]
= ["fk", "jacobian", "fk_matrix"]
= "robot_math.rs"
What is generated
- Scalar functions:
pub fn name(p1: f64, …) -> f64with common subexpression elimination,mul_add, andpowi. - Matrix functions:
pub fn name(p1: f64, …) -> [f64; rows*cols](row-major) with CSE shared across all entries. no_stdmath module: with.no_std(true)(orCodegenOptions::no_std()), math calls go through a cfg-gatedmod mathemitted once at the top of the file. It covers every function the symplex 0.2 backend can emit —sin,cos,tan,exp,ln,abs,sqrt,cbrt,asin/acos/atan,sinh/cosh/tanh,asinh/acosh/atanh,floor,ceil,signum,atan2,powf,powi,min,max,expm1,log1p,log2,exp2,fma,sin_cos— with astdvariant (inherentf64/f32methods) and alibmvariant.- Companion tests:
.with_tests(true).add_test_point(&[…])appends a#[cfg(test)] mod generated_teststhat evaluates every function at each point and asserts finite results. - Options:
.options(CodegenOptions { … })forf32precision (.precision_f32()),#[inline](.inline(true)),use_mul_add,checked_domain,uomtype annotations, etc.
Special functions and the embedded runtime
Expressions that use gamma, lgamma, digamma, erf/erfc, Lambert W, Beta, Bessel functions, orthogonal polynomials or integer sequences compile to calls into a self-contained mod symplex_rt { … } that symplex embeds in the generated code. By default (CodegenOptions::emit_runtime = true) every function embeds its own copy, which is fine for one function but defines the module twice in a file with two such functions.
For multi-function files, emit the runtime once:
use ;
use *;
use CodeGen;
runtime_module() respects the math backend, so the CfgGated runtime is itself no_std-ready. (For C targets the same pattern applies with Ex::to_c_fn_with_options and CodegenOptions::c_runtime().)
Features
no_stdsupport: generated code uses a cfg-gated math module that delegates tolibmwhenstdis unavailable.- Exact parameters: numeric DH parameters become reduced rationals, so generated constants are exact.
- Scalar and matrix functions: individual scalar functions or flat-array matrix functions (
fk_matrixgives the 4×4 transform). - Test generation: optional
#[cfg(test)]companion tests at configured evaluation points. - TOML config: load robot definitions from a TOML file with
from_toml().
License
Licensed under either of Apache License, Version 2.0 or MIT License at your option.