Skip to main content

dynamics_joint/
limits.rs

1//! Defines **joint limits** and related operations.
2
3use dynamics_spatial::configuration::Configuration;
4
5/// A joint limit, defining the physical constraints and dynamical properties of a joint.
6#[derive(Clone, Debug, PartialEq)]
7pub struct JointLimits {
8    /// Maximum torque/force that can be applied by the joint.
9    pub effort: Configuration,
10    /// Maximum velocity of the joint.
11    pub velocity: Configuration,
12    /// Minimum configuration of the joint.
13    pub min_configuration: Configuration,
14    /// Maximum configuration of the joint.
15    pub max_configuration: Configuration,
16    /// Joint friction coefficient.
17    pub friction: Configuration,
18    /// Joint damping coefficient.
19    pub damping: Configuration,
20    /// Dry friction loss.
21    pub friction_loss: f64,
22}
23
24impl JointLimits {
25    /// Creates a new [`JointLimits`] with the given parameters.
26    ///
27    /// # Arguments
28    ///
29    /// * `effort` - Maximum torque/force that can be applied by the joint.
30    /// * `velocity` - Maximum velocity of the joint.
31    /// * `min_configuration` - Minimum configuration of the joint.
32    /// * `max_configuration` - Maximum configuration of the joint.
33    /// * `friction` - Joint friction coefficient.
34    /// * `damping` - Joint damping coefficient.
35    /// * `friction_loss` - Dry friction loss.
36    ///
37    /// # Returns
38    /// A new [`JointLimits`] object.
39    #[must_use]
40    pub fn new(
41        effort: Configuration,
42        velocity: Configuration,
43        min_configuration: Configuration,
44        max_configuration: Configuration,
45        friction: Configuration,
46        damping: Configuration,
47        friction_loss: f64,
48    ) -> Self {
49        Self {
50            effort,
51            velocity,
52            min_configuration,
53            max_configuration,
54            friction,
55            damping,
56            friction_loss,
57        }
58    }
59
60    /// Creates a new unbounded [`JointLimits`], with infinite limits and zero friction/damping.
61    ///
62    /// # Returns
63    /// A new unbounded [`JointLimits`] object.
64    pub fn new_unbounded(nq: usize) -> Self {
65        Self {
66            effort: Configuration::from_element(nq, f64::INFINITY),
67            velocity: Configuration::from_element(nq, f64::INFINITY),
68            min_configuration: Configuration::from_element(nq, f64::NEG_INFINITY),
69            max_configuration: Configuration::from_element(nq, f64::INFINITY),
70            friction: Configuration::zeros(nq),
71            damping: Configuration::zeros(nq),
72            friction_loss: 0.0,
73        }
74    }
75}