Skip to main content

machine_delta_d3/
lib.rs

1//! Delta picker D3 (Clavel): three motor-driven arms at 120 degrees on a base, each carrying a parallelogram of two
2//! forearms down to a platform that stays level. The tool is the platform's centre, x, y, z.
3//!
4//! The machine is the spatial delta of machine files (`sim_netlist::spatial`, its module comment derives the
5//! kinematics and dynamics), read from this crate's tables: `[geometry]`, `[mass]`, `[upper_arm]`, `[workspace]`, one
6//! `[joint]`/`[motor]`/`[gearbox]` for all three arms. The file machines/delta-d3.toml is the same machine written as a
7//! netlist, so a fix to the arms reaches both.
8
9use sim_core::{Config, ConfigError, Machine, MachineEntry};
10pub use sim_netlist::linkage::Arms;
11pub use sim_netlist::spatial::*;
12
13pub static ENTRY: MachineEntry = MachineEntry {
14    id: "delta-d3",
15    key: "machine-delta-d3",
16    default_config: include_str!("../default.toml"),
17    i18n: &[("en", include_str!("../i18n/en.ftl")), ("de", include_str!("../i18n/de.ftl"))],
18    build,
19    suite_configs,
20};
21
22/// Effects that take energy out or put it in; the standard suite runs with them off. The stops stay, without their
23/// damping: the suite's pulses would otherwise send the arms round beyond where the legs can be assembled.
24pub const LOSSY_EFFECTS: [&str; 7] = [
25    "joint_friction",
26    "motor_friction",
27    "gearbox_drag",
28    "gearbox_lost_motion",
29    "gearbox_efficiency",
30    "torque_ripple",
31    "holding_brake",
32];
33
34fn build(cfg: &Config) -> Result<Box<dyn Machine>, ConfigError> {
35    sim_components::base::mount(cfg, Box::new(Delta::new(cfg)?))
36}
37
38/// The start pose and the cycle's targets moved by `dz` in z, with the working range (see `suite_configs`).
39fn lowered(cfg: &mut Config, dz: f64) {
40    let start = cfg.f64s("start.pose").unwrap();
41    cfg.set_text(&format!("start.pose = [{:?}, {:?}, {:?}]", start[0], start[1], start[2] + dz)).unwrap();
42    let segments: Vec<String> = cfg
43        .array("cycle.segment")
44        .unwrap()
45        .iter()
46        .map(|s| {
47            let t: Vec<f64> = s["target"].as_array().unwrap().iter().map(|v| v.as_float().unwrap()).collect();
48            format!(
49                "{{ target = [{:?}, {:?}, {:?}], dwell_s = {:?}, payload = {} }}",
50                t[0],
51                t[1],
52                t[2] + dz,
53                s["dwell_s"].as_float().unwrap(),
54                s["payload"].as_bool().unwrap()
55            )
56        })
57        .collect();
58    cfg.set_text(&format!("cycle.segment = [{}]", segments.join(", "))).unwrap();
59}
60
61/// The default config with every loss switched off.
62pub fn lossless_config() -> Config {
63    let mut cfg = ENTRY.config();
64    for effect in LOSSY_EFFECTS {
65        cfg.set_text(&format!("effects.{effect} = false")).unwrap();
66    }
67    cfg.set_text("gearbox.damping_nm_s_rad = 0.0").unwrap();
68    cfg.set_text("joint.stop_damping_nm_s_rad = 0.0").unwrap();
69    cfg.set_text("upper_arm.bending_damping_nm_s_rad = 0.0").unwrap();
70    cfg.set_text("upper_arm.lateral_damping_n_s_m = 0.0").unwrap();
71    cfg
72}
73
74/// Loss-free rigid and elastic models, with and without the payload, and the elastic one with part heating and the
75/// temperature feedback (no loss, so the gearboxes stay at ambient).
76///
77/// Their working range, start pose and cycle lie 175 mm lower than the default's (top 850 mm below the shoulders), so
78/// that the suite's middle pose is 1043 mm down: held by constant motor torques, as the suite holds it for 10 s after a pulse, the delta
79/// is unstable in its vertical mode in the upper part of its range, where the platform's weight pulls harder through
80/// the Jacobian the further it sinks (negative stiffness; `the_vertical_mode_under_constant_torques_is_unstable_high_up`),
81/// and stable below about 950 mm. A real property, not a numerical one: the drives' position loops hold it.
82fn suite_configs() -> Vec<Config> {
83    let mut out = Vec::new();
84    for (elastic, payload) in [(false, true), (false, false), (true, true), (true, false)] {
85        let mut cfg = lossless_config();
86        cfg.set_text("workspace.top_z_m = -0.85").unwrap();
87        lowered(&mut cfg, -0.175);
88        cfg.set_text(&format!("effects.joint_elasticity = {elastic}")).unwrap();
89        cfg.set_text(&format!("effects.payload = {payload}")).unwrap();
90        cfg.set_text(&format!("effects.part_heating = {}", elastic && payload)).unwrap();
91        cfg.set_text(&format!("effects.thermal_feedback = {}", elastic && payload)).unwrap();
92        out.push(cfg);
93    }
94    out
95}
96
97#[cfg(test)]
98mod tests;