Skip to main content

Crate symplex_build

Crate symplex_build 

Source
Expand description

Build-time code generation for symplex.

This crate is designed to be used as a [build-dependency] in firmware projects. It runs the symplex CAS at build time to derive symbolic equations (Jacobians, dynamics, etc.) and generates optimized numerical Rust code for no_std embedded targets.

§Quick Start

# Cargo.toml
[build-dependencies]
symplex-build = "0.2"
// build.rs
use symplex_build::CodeGen;
use symplex::prelude::*;
use symplex::matrix::jacobian;
use symplex::robotics::*;

fn main() {
    let ctx = Context::new();
    symplex::syms!(ctx; theta1, theta2);
    let zero = ctx.int(0);
    let l1 = ctx.rational(3, 10);  // 0.3m
    let l2 = ctx.rational(1, 4);   // 0.25m

    let (x, y, _z) = fk_position(&[
        DhLink { theta: &theta1, d: &zero, a: &l1, alpha: &zero },
        DhLink { theta: &theta2, d: &zero, a: &l2, alpha: &zero },
    ]);

    let j = jacobian(&[&x, &y], &[&theta1, &theta2]);

    CodeGen::new()
        .add_matrix_fn("jacobian", &j, &["theta1", "theta2"])
        .write_to_out_dir("robot_math.rs")
        .unwrap();
}

Structs§

CodeGen
Builder for generating Rust source code from symbolic expressions.
RobotArmBuilder
Builder for generating code for a serial robot arm.

Functions§

from_toml
Load a robot configuration from a TOML file and generate code.
robot_arm
Quick builder for a serial robot arm from DH parameters.