Skip to main content

sim_components/
joint.rs

1//! A motor-driven rotary joint: motor, gearbox (ratio, torsional stiffness, backlash, efficiency), holding brake, the
2//! motor's own friction and torque ripple, friction in the joint itself and end stops on its angle. What a machine of
3//! arms that turn about their joints needs per joint; it knows no machine.
4//!
5//! The joint's angle (the gearbox output, the arm) and the rotor's angle are apart by the gearbox. Elastic: both are
6//! states, and the gearbox's spring passes the torque between them (`Gearbox::torque`). Rigid: the rotor turns with the
7//! arm times the ratio, and its inertia counts at the arm times the ratio squared (`reflected_inertia`).
8//!
9//! Config, read here:
10//!
11//! - `[motor]`, `[gearbox]`: as for every machine (`ShaftFriction`, `Ripple`, `Gearbox`, `HoldingBrake`).
12//! - `[joint]`: `friction_coulomb_nm`, `friction_viscous_nm_s_rad`, `friction_smoothing_rad_s` (effects.joint_friction),
13//!   `min_angle_deg`, `max_angle_deg` (the stops), `stop_stiffness_nm_rad`, `stop_damping_nm_s_rad`
14//!   (effects.hard_stops).
15
16use crate::mech::{GearTorque, Gearbox, HardStop, HoldingBrake, Ripple, ShaftFriction};
17use sim_core::{Config, ConfigError, FRICTION_SIGNALS, SignalInfo};
18
19#[derive(Debug, Clone)]
20pub struct RotaryJoint {
21    pub gearbox: Gearbox,
22    /// Rotor and gearbox input, kg m^2: what the brake holds and the motor turns.
23    pub rotor_inertia: f64,
24    /// Motor bearing friction, at the rotor.
25    pub shaft: ShaftFriction,
26    pub ripple: Ripple,
27    pub brake: HoldingBrake,
28    /// Friction in the joint (bearings of the arm), at the output, N m.
29    pub friction: ShaftFriction,
30    /// The stops at both ends of the angle range, N m/rad and N m s/rad; zero with effects.hard_stops off.
31    pub stops: HardStop,
32    /// The angles of the stops, rad.
33    pub range: (f64, f64),
34    /// What a screw, rack or worm puts on the configured gearbox's efficiency (1 for none): kept apart so that the
35    /// gearbox's temperature can set its own share (`JointMachine::set_part_temperatures`), and so that the torque at
36    /// the gearbox output can be told from the force at the joint.
37    pub extra_efficiency: f64,
38    /// The configured gearbox has ratio 1: it is the coupling of a direct drive, also with a screw or rack behind it
39    /// (which changes the ratio). Nothing then warms as a gearbox, and its loss is the coupling's.
40    pub coupled: bool,
41}
42
43impl RotaryJoint {
44    pub fn from_config(cfg: &Config) -> Result<Self, ConfigError> {
45        let on = cfg.bool("effects.joint_friction")?;
46        let (min, max) = (cfg.f64("joint.min_angle_deg")?.to_radians(), cfg.f64("joint.max_angle_deg")?.to_radians());
47        if min >= max {
48            return Err(ConfigError::Invalid("joint.max_angle_deg".into()));
49        }
50        let (stiffness, damping) =
51            (cfg.positive("joint.stop_stiffness_nm_rad")?, cfg.non_negative("joint.stop_damping_nm_s_rad")?);
52        let friction = ShaftFriction {
53            coulomb: if on { cfg.non_negative("joint.friction_coulomb_nm")? } else { 0.0 },
54            viscous: if on { cfg.non_negative("joint.friction_viscous_nm_s_rad")? } else { 0.0 },
55            smoothing: cfg.positive("joint.friction_smoothing_rad_s")?,
56            ..ShaftFriction::NONE
57        };
58        Self::with(cfg, friction, Self::stops(cfg, stiffness, damping)?, (min, max))
59    }
60
61    /// A joint that slides (a carriage on its guides), its coordinate the travel in m: `[slide]` `stroke_m` (the stops
62    /// at 0 and the stroke), `friction_coulomb_n`, `friction_viscous_n_s_m`, `friction_smoothing_m_s` (the guides,
63    /// effects.joint_friction), `stop_stiffness_n_m`, `stop_damping_n_s_m` (effects.hard_stops). Motor and gearbox as for
64    /// `from_config`; a transmission (`transmission::Converter`) turns the gearbox into one in N and m.
65    ///
66    /// With effects.slide_presliding (a config without the switch has it off) the guides' friction is a presliding
67    /// state (`ShaftFriction::presliding_force`) of stiffness `presliding_stiffness_n_m`, its level the breakaway force
68    /// `friction_breakaway_n` at rest falling to the Coulomb level over `friction_stribeck_m_s`.
69    pub fn linear_from_config(cfg: &Config) -> Result<Self, ConfigError> {
70        let on = cfg.bool("effects.joint_friction")?;
71        let presliding = on && cfg.get("effects.slide_presliding").is_ok() && cfg.bool("effects.slide_presliding")?;
72        let coulomb = if on { cfg.non_negative("slide.friction_coulomb_n")? } else { 0.0 };
73        let friction = ShaftFriction {
74            coulomb,
75            viscous: if on { cfg.non_negative("slide.friction_viscous_n_s_m")? } else { 0.0 },
76            smoothing: cfg.positive("slide.friction_smoothing_m_s")?,
77            ..ShaftFriction::NONE
78        };
79        let friction = if presliding {
80            ShaftFriction {
81                stiction: cfg.non_negative("slide.friction_breakaway_n")?.max(coulomb),
82                stribeck: cfg.positive("slide.friction_stribeck_m_s")?,
83                presliding: cfg.positive("slide.presliding_stiffness_n_m")?,
84                ..friction
85            }
86        } else {
87            friction
88        };
89        let stops =
90            Self::stops(cfg, cfg.positive("slide.stop_stiffness_n_m")?, cfg.non_negative("slide.stop_damping_n_s_m")?)?;
91        Self::with(cfg, friction, stops, (0.0, cfg.positive("slide.stroke_m")?))
92    }
93
94    fn stops(cfg: &Config, stiffness: f64, damping: f64) -> Result<HardStop, ConfigError> {
95        Ok(if cfg.bool("effects.hard_stops")? {
96            HardStop { stiffness, damping }
97        } else {
98            HardStop { stiffness: 0.0, damping: 0.0 }
99        })
100    }
101
102    /// Motor and gearbox from `[motor]` and `[gearbox]`, with the joint's own friction, stops and range.
103    pub fn with(
104        cfg: &Config,
105        friction: ShaftFriction,
106        stops: HardStop,
107        range: (f64, f64),
108    ) -> Result<Self, ConfigError> {
109        let rotor_inertia =
110            cfg.positive("motor.rotor_inertia_kgm2")? + cfg.non_negative("gearbox.inertia_at_input_kgm2")?;
111        let gearbox = Gearbox::from_config(cfg)?;
112        Ok(Self {
113            coupled: gearbox.is_coupling(),
114            gearbox,
115            rotor_inertia,
116            shaft: ShaftFriction::from_config(cfg)?,
117            ripple: Ripple::from_config(cfg)?,
118            brake: HoldingBrake::from_config(cfg, rotor_inertia)?,
119            friction,
120            stops,
121            range,
122            extra_efficiency: 1.0,
123        })
124    }
125
126    pub fn ratio(&self) -> f64 {
127        self.gearbox.ratio
128    }
129
130    /// Its train for the time-optimal plan (`Machine::trains`): the gearbox's spring (K1, which holds a converter's own
131    /// compliance behind it in series) between the rotor and the rest of `whole`, the motor's rigid inertia at a pose, all
132    /// referred to the motor over the ratio squared.
133    /// Behind a screw whose stiffness follows its nut, the far end's (`train_at` takes the pose's).
134    pub fn train(&self, whole: f64) -> Option<sim_core::Train> {
135        Self::train_of(&self.gearbox, self.ratio(), self.rotor_inertia, whole)
136    }
137
138    /// `train` with the joint at `travel`, where a screw's stiffness follows its nut (`Gearbox::at`).
139    pub fn train_at(&self, travel: f64, whole: f64) -> Option<sim_core::Train> {
140        Self::train_of(&self.gearbox.at(travel), self.ratio(), self.rotor_inertia, whole)
141    }
142
143    fn train_of(g: &Gearbox, ratio: f64, rotor: f64, whole: f64) -> Option<sim_core::Train> {
144        // K1 holds a converter's compliance already (`Converter::apply_back`); `band_compliance` is that same spring.
145        sim_core::Train::of(g.stiffness / (ratio * ratio), rotor, whole)
146    }
147
148    /// The rotor's inertia as the joint feels it in the rigid model.
149    pub fn reflected_inertia(&self) -> f64 {
150        self.gearbox.ratio * self.gearbox.ratio * self.rotor_inertia
151    }
152
153    /// The parts a sub-step is cut into where the joint at `angle` and `speed` meets its stops within a base step `dt`
154    /// (`HardStop::substeps`).
155    pub fn stop_substeps(&self, angle: f64, speed: f64, dt: f64) -> u32 {
156        let (min, max) = self.range;
157        self.stops.substeps(angle - min, speed, max - min, dt)
158    }
159
160    /// What acts on the arm at the joint besides the gearbox, at its angle and speed: the joint's friction and the
161    /// stops (positive turns the angle up).
162    pub fn output_torque(&self, angle: f64, speed: f64) -> f64 {
163        let (min, max) = self.range;
164        self.stops.force(angle - min, speed, max - min) - self.friction.torque_at(angle, speed)
165    }
166
167    /// Elastic model: the gearbox torques between rotor and arm, the rotor's acceleration under the motor's torque
168    /// `command` (before ripple), and the rate of the brake's deflection `brake`.
169    pub fn rotor(
170        &self,
171        command: f64,
172        rotor: f64,
173        rotor_speed: f64,
174        angle: f64,
175        speed: f64,
176        brake: f64,
177        engaged: bool,
178    ) -> (GearTorque, f64, f64) {
179        let gear = self.gearbox.torque(rotor, rotor_speed, angle, speed);
180        let (acc, rate) = self.rotor_under(command, rotor, rotor_speed, gear, brake, engaged);
181        (gear, acc, rate)
182    }
183
184    /// `rotor` with the gearbox's torques `gear` given (a gear with its Maxwell arm, `Gearbox::torque_with`): the
185    /// rotor's acceleration and the brake's deflection rate.
186    pub fn rotor_under(
187        &self,
188        command: f64,
189        rotor: f64,
190        rotor_speed: f64,
191        gear: GearTorque,
192        brake: f64,
193        engaged: bool,
194    ) -> (f64, f64) {
195        let (held, rate) = self.brake.torque(engaged, rotor_speed, brake);
196        let acc = (self.ripple.apply(command, rotor) - gear.rotor - self.shaft.torque(rotor_speed) - held)
197            / self.rotor_inertia;
198        (acc, rate)
199    }
200
201    /// Rigid model: the torque the motor puts on the arm through a loss-free gearbox with a massless rotor at the
202    /// rotor's angle and speed (ripple, motor friction and the brake taken off), and the brake's deflection rate.
203    pub fn rigid_drive(&self, command: f64, rotor: f64, rotor_speed: f64, brake: f64, engaged: bool) -> (f64, f64) {
204        let (held, rate) = self.brake.torque(engaged, rotor_speed, brake);
205        (self.gearbox.ratio * (self.ripple.apply(command, rotor) - self.shaft.torque(rotor_speed) - held), rate)
206    }
207
208    /// The joint's own friction torque at a steady speed at the output, split into [Coulomb, viscous, stiction] (N m;
209    /// they add up to `friction.torque(speed)` of a joint without gearbox drag): the level `level` is Coulomb plus the
210    /// Stribeck rise to the breakaway, both under the same tanh, the viscous part is linear. For the friction view.
211    pub fn friction_split(&self, speed: f64) -> [f64; 3] {
212        let f = &self.friction;
213        let (s, seals) = ((speed / f.smoothing).tanh(), f.oil.powf(f.seal_exponent));
214        [seals * f.coulomb * s, f.viscous * speed, (f.level(speed) - seals * f.coulomb) * s]
215    }
216
217    /// The values of the friction view's signals `<id>.friction_<part>` (`sim_core::FRICTION_SIGNALS`) of this joint at
218    /// an output speed: the speed, the three parts, and a load factor of 1 (a bearing's levels do not follow a load).
219    pub fn friction_signals(&self, speed: f64) -> [f64; 5] {
220        let [coulomb, viscous, stiction] = self.friction_split(speed);
221        [speed, coulomb, viscous, stiction, 1.0]
222    }
223
224    /// The infos of `friction_signals` for a joint `id` of the owner `owner_key`: rad/s and N m.
225    pub fn friction_infos(id: &str, owner_key: &str) -> Vec<SignalInfo> {
226        FRICTION_SIGNALS
227            .iter()
228            .map(|part| {
229                let unit = match *part {
230                    "speed" => "rad/s",
231                    "load_scale" => "",
232                    _ => "N m",
233                };
234                let quantity = format!("quantity-friction-{}", part.replace('_', "-"));
235                SignalInfo::new(format!("{id}.friction_{part}"), owner_key, &quantity, unit)
236            })
237            .collect()
238    }
239
240    /// Energy in the stops' springs at an angle.
241    pub fn stop_energy(&self, angle: f64) -> f64 {
242        let (min, max) = self.range;
243        self.stops.energy(angle - min, max - min)
244    }
245
246    /// Powers lost at an angle and speed, rotor speed and brake: in the joint's friction, the stops, the motor's
247    /// friction with the brake, and the gearbox's drag (W; the gearbox's loss, though it acts on the rotor).
248    pub fn losses(&self, angle: f64, speed: f64, rotor_speed: f64, brake: f64, engaged: bool) -> [f64; 4] {
249        let (min, max) = self.range;
250        let held = self.brake.torque(engaged, rotor_speed, brake).0;
251        let drag = self.shaft.drag_power(rotor_speed);
252        [
253            self.friction.torque_at(angle, speed) * speed,
254            self.stops.loss_power(angle - min, speed, max - min),
255            (self.shaft.torque(rotor_speed) + held) * rotor_speed - drag,
256            drag,
257        ]
258    }
259}
260
261#[cfg(test)]
262mod tests {
263    use super::*;
264
265    fn joint_text() -> String {
266        "format_version = 1\n[effects]\njoint_friction = true\nhard_stops = true\nmotor_friction = true\ntorque_ripple = false\ngearbox_backlash = false\ngearbox_efficiency = true\ngearbox_drag = false\nmotor_stiction = false\ngearbox_lost_motion = false\ngearbox_stiffness_curve = false\nthermal_feedback = false\nholding_brake = true\n\
267            [motor]\nrotor_inertia_kgm2 = 1e-4\nfriction_coulomb_nm = 0.1\nfriction_viscous_nm_s_rad = 0.0\nfriction_smoothing_rad_s = 1e-3\nfriction_breakaway_nm = 0.1\nfriction_stribeck_rad_s = 2.0\nripple_fraction = 0.0\nripple_order = 6.0\ncogging_nm = 0.0\ncogging_order = 6.0\nbrake_torque_nm = 5.0\n\
268            [gearbox]\nratio = 20.0\nefficiency = 0.9\nbacklash_rad = 0.0\nstiffness_nm_rad = 1e4\ndamping_nm_s_rad = 0.0\ninertia_at_input_kgm2 = 1e-4\nefficiency_torque_nm = 100.0\nno_load_torque_nm = 0.0\nno_load_speed_rpm = 3000.0\nlost_motion_band_rad = 0.0\nhysteresis_rad = 0.0\nstiffness_t1_nm = 100.0\nstiffness_t2_nm = 100.0\nstiffness_k2_nm_rad = 1e4\nstiffness_k3_nm_rad = 1e4\n\
269            [joint]\nfriction_coulomb_nm = 2.0\nfriction_viscous_nm_s_rad = 0.5\nfriction_smoothing_rad_s = 1e-3\nmin_angle_deg = -45.0\nmax_angle_deg = 90.0\nstop_stiffness_nm_rad = 1e5\nstop_damping_nm_s_rad = 0.0\n".to_string()
270    }
271
272    fn joint() -> RotaryJoint {
273        RotaryJoint::from_config(&Config::parse(&joint_text()).unwrap()).unwrap()
274    }
275
276    /// By hand: joint friction 2 N m + 0.5 N m s/rad at 4 rad/s is 4 N m against the motion; 0.01 rad beyond the upper
277    /// stop pushes back with 1e5 * 0.01 = 1000 N m; the rotor (1e-4 + 1e-4 kg m^2) is felt at the arm as 2e-4 * 400 =
278    /// 0.08 kg m^2; 1 N m at the motor with 0.1 N m friction gives 18 N m at the arm in the rigid model.
279    #[test]
280    fn a_joint_adds_friction_stops_and_the_rotor_as_calculated() {
281        let j = joint();
282        assert!((j.output_torque(0.0, 4.0) + 4.0).abs() < 1e-9);
283        assert!((j.output_torque(90f64.to_radians() + 0.01, 0.0) + 1000.0).abs() < 1e-6);
284        assert!((j.output_torque(-45f64.to_radians() - 0.01, 0.0) - 1000.0).abs() < 1e-6);
285        assert!((j.reflected_inertia() - 0.08).abs() < 1e-12);
286        assert!((j.rigid_drive(1.0, 0.0, 10.0, 0.0, false).0 - 18.0).abs() < 1e-9);
287        // Elastic: twisted by 1 mrad at the output, the gearbox passes 10 N m to the arm and takes 0.5 N m from the rotor.
288        let (gear, acc, _) = j.rotor(0.0, 20.0 * 1e-3, 0.0, 0.0, 0.0, 0.0, false);
289        assert!((gear.output - 10.0).abs() < 1e-9 && (acc + 0.5 / 2e-4).abs() < 1e-6);
290        // The losses at 4 rad/s at the arm and 80 rad/s at the rotor: 16 W in the joint, 8 W in the motor bearings.
291        let [joint_loss, stop_loss, motor_loss, _] = j.losses(0.0, 4.0, 80.0, 0.0, false);
292        assert!((joint_loss - 16.0).abs() < 1e-9 && stop_loss == 0.0 && (motor_loss - 8.0).abs() < 1e-9);
293    }
294    /// A pinion of 50 mm radius (stiffness 1e7 N/m, backlash 0.1 mm, 95 %, 0.04 kg m^2) behind the gearbox of ratio 20
295    /// (1e4 N m/rad, 90 %, rotor and input 2e-4 kg m^2), by hand: ratio 20 / 0.05 = 400 rad/m; the gearbox seen at the
296    /// rack 1e4 / 0.05^2 = 4e6 N/m, in series with 1e7: 1 / (2.5e-7 + 1e-7) = 2.857143e6 N/m; efficiency 0.9 * 0.95 =
297    /// 0.855; the pinion at the rotor 0.04 / 400 = 1e-4, so 3e-4 kg m^2. Backlash off: none; on, the gearbox's 2 mrad
298    /// seen at the rack (0.1 mm) plus the rack's 0.1 mm, half of it 0.1 mm.
299    #[test]
300    fn a_converter_behind_the_gearbox_gives_the_hand_calculated_joint() {
301        use crate::transmission::Converter;
302        let pinion = Converter {
303            lever: 0.05,
304            stiffness: 1e7,
305            backlash: 1e-4,
306            efficiency: 0.95,
307            inertia: 0.04,
308            damping_ratio: 0.0,
309        };
310        let mut cfg = Config::parse(&joint_text()).unwrap();
311        let mut j = RotaryJoint::from_config(&cfg).unwrap();
312        pinion.apply(&cfg, &mut j).unwrap();
313        let close = |a: f64, b: f64| (a / b - 1.0).abs() < 1e-9;
314        assert!(
315            close(j.ratio(), 400.0) && close(j.gearbox.stiffness, 2.857142857e6) && close(j.gearbox.efficiency, 0.855)
316        );
317        assert!(close(j.rotor_inertia, 3e-4) && j.gearbox.half_backlash == 0.0);
318        cfg.set_text("effects.gearbox_backlash = true").unwrap();
319        cfg.set_text("gearbox.backlash_rad = 0.002").unwrap();
320        let mut j = RotaryJoint::from_config(&cfg).unwrap();
321        pinion.apply(&cfg, &mut j).unwrap();
322        assert!(close(j.gearbox.half_backlash, 1e-4));
323    }
324
325    /// The mesh friction's bristle behind a converter is in N/m: a pinion of 50 mm (1e7 N/m) behind the 1e4 N m/rad
326    /// gearbox gives the series 2.857143e6 N/m, MESH_STIFFNESS times it. A stiff gearbox (1e12 N m/rad) behind a rigid
327    /// 50 mm lever would give 1e12 / 0.05^2 = 4e14 N/m; the cap is the rotor (2e-4 kg m^2) at 20 / 0.05 = 400 rad/m,
328    /// 2e-4 * 400^2 = 32 kg, times (BRISTLE_RATE_MAX / 4)^2 = (2.5e4)^2: 32 * 6.25e8 = 2e10 N/m.
329    #[test]
330    fn a_converters_mesh_bristle_is_in_newtons_per_metre_and_capped() {
331        use crate::transmission::Converter;
332        let text = joint_text()
333            .replace("gearbox_lost_motion = false", "gearbox_lost_motion = false\ngearbox_mesh_friction = true");
334        let mut cfg = Config::parse(&text).unwrap();
335        let mut j = RotaryJoint::from_config(&cfg).unwrap();
336        Converter { lever: 0.05, stiffness: 1e7, backlash: 0.0, efficiency: 0.95, inertia: 0.04, damping_ratio: 0.0 }
337            .apply(&cfg, &mut j)
338            .unwrap();
339        assert!((j.gearbox.mesh_stiffness / 2.857142857e6 - 1.0).abs() < 1e-9);
340        cfg.set_text("gearbox.stiffness_nm_rad = 1e12").unwrap();
341        let mut j = RotaryJoint::from_config(&cfg).unwrap();
342        Converter {
343            lever: 0.05,
344            stiffness: f64::INFINITY,
345            backlash: 0.0,
346            efficiency: 1.0,
347            inertia: 0.0,
348            damping_ratio: 0.0,
349        }
350        .apply(&cfg, &mut j)
351        .unwrap();
352        assert!((j.gearbox.mesh_stiffness / 2e10 - 1.0).abs() < 1e-9);
353    }
354
355    /// The slide's own table: its stroke, its guides' friction in N, its stops in N/m.
356    #[test]
357    fn a_linear_joint_reads_its_slide() {
358        let text = joint_text()
359            + "[slide]
360stroke_m = 0.8
361friction_coulomb_n = 30.0
362friction_viscous_n_s_m = 40.0
363friction_smoothing_m_s = 1e-3
364stop_stiffness_n_m = 2e6
365stop_damping_n_s_m = 0.0
366";
367        let j = RotaryJoint::linear_from_config(&Config::parse(&text).unwrap()).unwrap();
368        assert_eq!(j.range, (0.0, 0.8));
369        // 30 N + 40 N s/m * 0.5 m/s against the motion; 1 mm beyond the far stop, 2000 N back.
370        assert!((j.output_torque(0.4, 0.5) + 50.0).abs() < 1e-9);
371        assert!((j.output_torque(0.801, 0.0) + 2000.0).abs() < 1e-6);
372    }
373
374    /// Hand value: at 2 rad/s (far above the 1e-3 smoothing) the joint of the text has Coulomb 2 N m, viscous
375    /// 0.5 * 2 = 1 N m and no stiction rise; the parts add up to `friction.torque` and the signals carry them.
376    #[test]
377    fn friction_view_parts_add_up() {
378        let j = joint();
379        let [c, v, s] = j.friction_split(2.0);
380        assert!((c - 2.0).abs() < 1e-9 && (v - 1.0).abs() < 1e-12 && s.abs() < 1e-12);
381        assert!((c + v + s - j.friction.torque(2.0)).abs() < 1e-12);
382        assert!((c + v + s + j.friction.torque(-2.0)).abs() < 1e-12, "odd in the speed");
383        assert_eq!(j.friction_signals(2.0), [2.0, c, v, s, 1.0]);
384        assert_eq!(RotaryJoint::friction_infos("joint.1", "arm-1").len(), sim_core::FRICTION_SIGNALS.len());
385        // A breakaway level of 5 N m falling over 1 rad/s: at 1 rad/s the rise is (5 - 2) e^-1 = 1.10364 N m, the
386        // Coulomb part stays 2 N m; together the torque less the viscous part.
387        let mut j = j;
388        (j.friction.stiction, j.friction.stribeck) = (5.0, 1.0);
389        let [c, v, s] = j.friction_split(1.0);
390        assert!((c - 2.0).abs() < 1e-9 && (s - 3.0 * (-1.0f64).exp()).abs() < 1e-9 && (v - 0.5).abs() < 1e-12);
391        assert!((c + v + s - j.friction.torque(1.0)).abs() < 1e-12);
392    }
393}