Skip to content

Commit 5736f0b

Browse files
committed
Improve docs
1 parent 1358746 commit 5736f0b

File tree

4 files changed

+54
-14
lines changed

4 files changed

+54
-14
lines changed

src/dynamics/joints/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ Therefore, they have 3 translational DOF and 3 rotational DOF, a total of 6 DOF.
208208
//! ## Other Configuration
209209
//!
210210
//! Different joints may have different configuration options. They may allow you to change the axis of allowed
211-
//! translation or rotation, and can have distance or angle limits for those axes.
211+
//! translation or rotation, and apply limits or motors for those axes.
212212
//!
213213
//! Take a look at the documentation and methods of each joint to see all the different configuration options.
214214

src/dynamics/joints/motor.rs

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,25 @@
11
use crate::prelude::*;
22
use 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)]
913
pub 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
}

src/dynamics/joints/prismatic.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,13 @@ use bevy::{
1616
/// This can be useful for things like elevators, pistons, sliding doors and moving platforms.
1717
///
1818
/// Each prismatic joint is defined by a [`JointFrame`] on each body, a [`slider_axis`](Self::slider_axis)
19-
/// along which the bodies can translate, and an optional [`DistanceLimit`] that defines the extents of the allowed translation.
19+
/// along which the bodies can translate, and an optional [`DistanceLimit`] that defines the extents
20+
/// of the allowed translation.
2021
///
2122
#[doc = include_str!("./images/prismatic_joint.svg")]
23+
///
24+
/// The joint can also include a [`LinearMotor`] for driving the translation along the [`slider_axis`](Self::slider_axis).
25+
/// Use this to create pistons, elevators, or other linear motion mechanisms.
2226
#[derive(Component, Clone, Debug, PartialEq, Reflect)]
2327
#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))]
2428
#[cfg_attr(feature = "serialize", reflect(Serialize, Deserialize))]

src/dynamics/joints/revolute.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ use bevy::{
3737
)]
3838
///
3939
#[doc = include_str!("./images/revolute_joint.svg")]
40+
///
41+
/// The joint can also include an [`AngularMotor`] for driving the rotation about the pivot point.
42+
/// Use this to create wheels, fans, servos, or other rotating mechanisms.
4043
#[derive(Component, Clone, Debug, PartialEq, Reflect)]
4144
#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))]
4245
#[cfg_attr(feature = "serialize", reflect(Serialize, Deserialize))]

0 commit comments

Comments
 (0)