nphysics2d/joint/
joint_motor.rs

1use crate::solver::ImpulseLimits;
2use na::RealField;
3use num::Zero;
4
5/// Description of a motor applied to a joint.
6#[derive(Copy, Clone, Debug)]
7pub struct JointMotor<V, N: RealField + Copy> {
8    /// The velocity the motor will attempt to reach.
9    pub desired_velocity: V,
10    /// The maximum velocity the motor will attempt to reach.
11    pub max_velocity: N,
12    /// The maximum force deliverable by the motor.
13    pub max_force: N,
14    /// Whether or not the motor is active.
15    pub enabled: bool,
16}
17
18impl<V: Zero, N: RealField + Copy> JointMotor<V, N> {
19    /// Create a disable motor with zero desired velocity.
20    ///
21    /// The max force is initialized to a virtually infinite value, i.e., `N::max_value()`.
22    pub fn new() -> Self {
23        JointMotor {
24            desired_velocity: V::zero(),
25            max_velocity: N::max_value(),
26            max_force: N::max_value(),
27            enabled: false,
28        }
29    }
30
31    /// The limits of the impulse applicable by the motor on the body parts.
32    pub fn impulse_limits(&self) -> ImpulseLimits<N> {
33        ImpulseLimits::Independent {
34            min: -self.max_force,
35            max: self.max_force,
36        }
37    }
38}
39
40impl<V: Zero, N: RealField + Copy> Default for JointMotor<V, N> {
41    fn default() -> Self {
42        Self::new()
43    }
44}