11use crate :: prelude:: * ;
22use bevy:: prelude:: * ;
33
4- /// The motor model determines how the motor force/torque is computed.
4+ /// Determines how the joint motor force/torque is computed.
5+ ///
6+ /// Different models offer trade-offs between ease of tuning, physical accuracy,
7+ /// and timestep-independence. The default is a [`SpringDamper`](MotorModel::SpringDamper)
8+ /// model that provides stable, predictable behavior regardless of the timestep.
59#[ derive( Clone , Copy , Debug , PartialEq , Reflect ) ]
610#[ cfg_attr( feature = "serialize" , derive( serde:: Serialize , serde:: Deserialize ) ) ]
711#[ cfg_attr( feature = "serialize" , reflect( Serialize , Deserialize ) ) ]
812#[ reflect( Debug , PartialEq ) ]
913pub enum MotorModel {
1014 /// A spring-damper model using implicit Euler integration for timestep-independent behavior.
1115 ///
12- /// While not truly timestep-independant, this model provides stabler, more predictable
13- /// spring-damper dynamics regardless of the physics substep count.
16+ /// While not truly timestep-independent, this model provides stable and predictable
17+ /// spring-damper behavior regardless of the physics substep count or mass configuration.
18+ /// This makes it easier to achieve the desired behavior without extensive tuning.
19+ ///
20+ /// This is the recommended model for most use cases.
1421 ///
15- /// Ignores the mass of the bodies.
22+ /// # Parameters
1623 ///
1724 /// - `frequency`: The natural frequency of the spring in Hz. Higher values create stiffer springs.
1825 /// - `damping_ratio`: The damping ratio.
@@ -26,30 +33,56 @@ pub enum MotorModel {
2633 /// The damping ratio.
2734 damping_ratio : Scalar ,
2835 } ,
36+
2937 /// The motor force/torque is computed directly from the stiffness and damping parameters.
3038 ///
31- /// This model takes the mass of the bodies into account, resulting in more physically
32- /// accurate behavior, but it may be harder to tune.
39+ /// The model can be described by the following formula:
40+ ///
41+ /// ```text
42+ /// force = (stiffness * position_error) + (damping * velocity_error)
43+ /// ```
44+ ///
45+ /// This produces physically accurate forces/torques, but requires careful tuning of the
46+ /// stiffness and damping parameters based on the masses of the connected bodies.
47+ /// As a result, it can be more difficult to achieve the desired behavior compared to
48+ /// the [`AccelerationBased`](MotorModel::AccelerationBased) model or the
49+ /// [`SpringDamper`](MotorModel::SpringDamper) model.
50+ ///
51+ /// # Parameters
3352 ///
3453 /// - `stiffness`: The stiffness coefficient for position control. Set to zero for pure velocity control.
35- /// - `damping`: The damping coefficient.
54+ /// - `damping`: The damping coefficient for velocity control .
3655 ForceBased {
3756 /// The stiffness coefficient for position control.
3857 stiffness : Scalar ,
39- /// The damping coefficient.
58+ /// The damping coefficient for velocity control .
4059 damping : Scalar ,
4160 } ,
61+
4262 /// The motor force/torque is computed based on the acceleration required to reach the target.
4363 ///
44- /// This model is more stable than the `ForceBased` model and easier to tune, but it ignores the mass of the bodies.
45- /// Prefer the `SpringDamper` model if it's an option.
64+ /// The model can be described by the following formula:
65+ ///
66+ /// ```text
67+ /// acceleration = (stiffness * position_error) + (damping * velocity_error)
68+ /// ```
69+ ///
70+ /// This automatically scales the motor force/torque based on the masses of the bodies,
71+ /// resulting in consistent behavior across different mass configurations.
72+ /// It is therefore easier to tune compared to the [`ForceBased`](MotorModel::ForceBased) model,
73+ /// which requires manual adjustment of stiffness and damping based on mass.
74+ ///
75+ /// For more timestep-independent spring-damper behavior, consider using
76+ /// the [`SpringDamper`](MotorModel::SpringDamper) model instead.
77+ ///
78+ /// # Parameters
4679 ///
4780 /// - `stiffness`: The stiffness coefficient for position control. Set to zero for pure velocity control.
48- /// - `damping`: The damping coefficient.
81+ /// - `damping`: The damping coefficient for velocity control .
4982 AccelerationBased {
5083 /// The stiffness coefficient for position control.
5184 stiffness : Scalar ,
52- /// The damping coefficient.
85+ /// The damping coefficient for velocity control .
5386 damping : Scalar ,
5487 } ,
5588}
0 commit comments