machine_delta_d2/lib.rs
1//! Delta picker D2, the planar delta: two motor-driven arms in the vertical x-z plane, one at each side of the base,
2//! each carrying a pair of forearms down to a plate that keeps its orientation (a five-bar whose lower links are
3//! parallelograms, as in Codian's D2 or ABB's two-axis FlexPicker). The tool is the plate's centre, x and z.
4//!
5//! The D3's equations with two legs at the azimuths 0 and 180 degrees and the plate in the plane y = 0. Leg i points
6//! along s_i x (s_1 = +1, s_2 = -1); e = base radius - platform radius (the plate's offset folded into the base, as it
7//! never turns), the arm angle theta_i (0 horizontal, positive down), upper arm L_a, forearm L_b:
8//!
9//! ```text
10//! elbow c_i = (s_i (e + L_a cos theta), -L_a sin theta)
11//! constraint |p - c_i|^2 = L_b^2
12//! inverse A cos theta + B sin theta + C = 0, A = -2 L_a (x' - e), B = 2 L_a z, C = (x' - e)^2 + z^2 + L_a^2 - L_b^2
13//! theta = 2 atan((-B - sqrt(A^2 + B^2 - C^2)) / (C - A)) (elbow out; x' = s_i x)
14//! forward p = the lower of the two points at L_b from both elbows (two circles)
15//! Jacobian J_x p' = J_q theta', J_x rows u_i = p - c_i, J_q = diag(u_i . dc_i/dtheta_i); p' = J theta', J = J_x^-1 J_q
16//! J_x p'' = J_q theta'' + w, w_i = theta_i'^2 (u_i . c_i'') - |p' - c_i' theta_i'|^2
17//! ```
18//!
19//! Dynamics as on the D3 (Codourey 1998, Olsson 2009): each forearm pair's mass split, a share r at the elbow and
20//! 1 - r at the plate; two arms about their joints plus a point mass at the plate, m_nt = plate + payload +
21//! 2 (1 - r) m_fb, and
22//!
23//! ```text
24//! M(theta) theta'' = tau_gear + Q_g - m_nt J^T J_x^-1 w + tau_joint, M = I_b 1 + m_nt J^T J
25//! I_b = I_arm + L_a^2 (m_elbow + r m_fb), Q_g,i = g m_LG cos theta_i - m_nt g J_zi, m_LG = m_arm l_cg + L_a (m_elbow + r m_fb)
26//! ```
27//!
28//! Each joint is a `RotaryJoint`, elastic or rigid (effects.joint_elasticity), as on the D3.
29//!
30//! The machine is the planar linkage of machine files (`sim_netlist::linkage::LinkageMachine`), read from this crate's
31//! tables (`[geometry]`, `[mass]`, `[workspace]`, one `[joint]` for both arms): one implementation, so that a fix
32//! reaches both, and machines/planar-delta.toml gives this crate's numbers.
33
34use sim_core::{Config, ConfigError, Machine, MachineEntry};
35pub use sim_netlist::linkage::{Legs, SIDE, condition_number};
36
37/// The planar delta: the linkage machine of `sim_netlist`, built by `Delta2::new` from this crate's config.
38pub type Delta2 = sim_netlist::linkage::LinkageMachine;
39
40pub static ENTRY: MachineEntry = MachineEntry {
41 id: "delta-d2",
42 key: "machine-delta-d2",
43 default_config: include_str!("../default.toml"),
44 i18n: &[("en", include_str!("../i18n/en.ftl")), ("de", include_str!("../i18n/de.ftl"))],
45 build,
46 suite_configs,
47};
48
49/// Effects that take energy out or put it in; the standard suite runs with them off. The stops stay, without their
50/// damping.
51pub const LOSSY_EFFECTS: [&str; 7] = [
52 "joint_friction",
53 "motor_friction",
54 "gearbox_drag",
55 "gearbox_lost_motion",
56 "gearbox_efficiency",
57 "torque_ripple",
58 "holding_brake",
59];
60
61fn build(cfg: &Config) -> Result<Box<dyn Machine>, ConfigError> {
62 sim_components::base::mount(cfg, Box::new(Delta2::new(cfg)?))
63}
64
65/// The default config with every loss switched off.
66pub fn lossless_config() -> Config {
67 let mut cfg = ENTRY.config();
68 for effect in LOSSY_EFFECTS {
69 cfg.set_text(&format!("effects.{effect} = false")).unwrap();
70 }
71 cfg.set_text("gearbox.damping_nm_s_rad = 0.0").unwrap();
72 cfg.set_text("joint.stop_damping_nm_s_rad = 0.0").unwrap();
73 cfg
74}
75
76/// The start pose and the cycle's targets moved by `dz` in z (see `suite_configs`).
77fn lowered(cfg: &mut Config, dz: f64) {
78 let start = cfg.f64s("start.pose").unwrap();
79 cfg.set_text(&format!("start.pose = [{:?}, {:?}]", start[0], start[1] + dz)).unwrap();
80 let segments: Vec<String> = cfg
81 .array("cycle.segment")
82 .unwrap()
83 .iter()
84 .map(|s| {
85 let t: Vec<f64> = s["target"].as_array().unwrap().iter().map(|v| v.as_float().unwrap()).collect();
86 format!(
87 "{{ target = [{:?}, {:?}], dwell_s = {:?}, payload = {} }}",
88 t[0],
89 t[1] + dz,
90 s["dwell_s"].as_float().unwrap(),
91 s["payload"].as_bool().unwrap()
92 )
93 })
94 .collect();
95 cfg.set_text(&format!("cycle.segment = [{}]", segments.join(", "))).unwrap();
96}
97
98/// Loss-free rigid and elastic models, with and without the payload, and the elastic one with part heating and the
99/// temperature feedback (no loss, so the gearboxes stay at ambient).
100///
101/// As on the D3, their working range, start pose and cycle lie 150 mm lower than the default's (top 550 mm below the
102/// shoulders): held by constant motor torques, as the suite holds it after a pulse, the plate's vertical mode is
103/// unstable at the default's middle pose, 638.5 mm down, and stable at 788.5 mm
104/// (`the_vertical_mode_under_constant_torques_is_unstable_high_up`). The drives' position loops hold it.
105fn suite_configs() -> Vec<Config> {
106 let mut out = Vec::new();
107 for (elastic, payload) in [(false, true), (false, false), (true, true), (true, false)] {
108 let mut cfg = lossless_config();
109 cfg.set_text("workspace.top_z_m = -0.55").unwrap();
110 lowered(&mut cfg, -0.15);
111 cfg.set_text(&format!("effects.joint_elasticity = {elastic}")).unwrap();
112 cfg.set_text(&format!("effects.payload = {payload}")).unwrap();
113 cfg.set_text(&format!("effects.part_heating = {}", elastic && payload)).unwrap();
114 cfg.set_text(&format!("effects.thermal_feedback = {}", elastic && payload)).unwrap();
115 out.push(cfg);
116 }
117 out
118}
119
120#[cfg(test)]
121mod tests;