aboutsummaryrefslogtreecommitdiff
path: root/src/dynamics/joint
diff options
context:
space:
mode:
authorCrozet Sébastien <developer@crozet.re>2021-02-10 11:56:51 +0100
committerCrozet Sébastien <developer@crozet.re>2021-02-11 15:58:46 +0100
commit5b80c4efbf93ad1294c9d3d390d8c8f090681b0e (patch)
treed82cef06b68a078dc23230e4e596021f7071b9b7 /src/dynamics/joint
parent3be866920657f7a13a49486795e06f14d92f4969 (diff)
downloadrapier-5b80c4efbf93ad1294c9d3d390d8c8f090681b0e.tar.gz
rapier-5b80c4efbf93ad1294c9d3d390d8c8f090681b0e.tar.bz2
rapier-5b80c4efbf93ad1294c9d3d390d8c8f090681b0e.zip
Start experimenting with a generic joint implementation for joint drives.
Diffstat (limited to 'src/dynamics/joint')
-rw-r--r--src/dynamics/joint/generic_joint.rs46
-rw-r--r--src/dynamics/joint/joint.rs23
-rw-r--r--src/dynamics/joint/mod.rs2
3 files changed, 69 insertions, 2 deletions
diff --git a/src/dynamics/joint/generic_joint.rs b/src/dynamics/joint/generic_joint.rs
new file mode 100644
index 0000000..cfea537
--- /dev/null
+++ b/src/dynamics/joint/generic_joint.rs
@@ -0,0 +1,46 @@
+use crate::math::{Isometry, Real, SpacialVector, SPATIAL_DIM};
+
+#[derive(Copy, Clone, Debug)]
+#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
+/// A joint that prevents all relative movement between two bodies.
+///
+/// Given two frames of references, this joint aims to ensure these frame always coincide in world-space.
+pub struct GenericJoint {
+ /// The frame of reference for the first body affected by this joint, expressed in the local frame
+ /// of the first body.
+ pub local_anchor1: Isometry<Real>,
+ /// The frame of reference for the second body affected by this joint, expressed in the local frame
+ /// of the first body.
+ pub local_anchor2: Isometry<Real>,
+ /// The impulse applied to the first body affected by this joint.
+ ///
+ /// The impulse applied to the second body affected by this joint is given by `-impulse`.
+ /// This combines both linear and angular impulses:
+ /// - In 2D, `impulse.xy()` gives the linear impulse, and `impulse.z` the angular impulse.
+ /// - In 3D, `impulse.xyz()` gives the linear impulse, and `(impulse[3], impulse[4], impulse[5])` the angular impulse.
+ pub impulse: SpacialVector<Real>,
+
+ pub min_position: SpacialVector<Real>,
+ pub max_position: SpacialVector<Real>,
+ pub target_velocity: SpacialVector<Real>,
+ /// The maximum negative impulse the joint can apply on each DoF. Must be <= 0.0
+ pub max_negative_impulse: SpacialVector<Real>,
+ /// The maximum positive impulse the joint can apply on each DoF. Must be >= 0.0
+ pub max_positive_impulse: SpacialVector<Real>,
+}
+
+impl GenericJoint {
+ /// Creates a new fixed joint from the frames of reference of both bodies.
+ pub fn new(local_anchor1: Isometry<Real>, local_anchor2: Isometry<Real>) -> Self {
+ Self {
+ local_anchor1,
+ local_anchor2,
+ impulse: SpacialVector::zeros(),
+ min_position: SpacialVector::zeros(),
+ max_position: SpacialVector::zeros(),
+ target_velocity: SpacialVector::zeros(),
+ max_negative_impulse: SpacialVector::repeat(-Real::MAX),
+ max_positive_impulse: SpacialVector::repeat(Real::MAX),
+ }
+ }
+}
diff --git a/src/dynamics/joint/joint.rs b/src/dynamics/joint/joint.rs
index 9fe6488..31c5e0a 100644
--- a/src/dynamics/joint/joint.rs
+++ b/src/dynamics/joint/joint.rs
@@ -1,6 +1,8 @@
#[cfg(feature = "dim3")]
use crate::dynamics::RevoluteJoint;
-use crate::dynamics::{BallJoint, FixedJoint, JointHandle, PrismaticJoint, RigidBodyHandle};
+use crate::dynamics::{
+ BallJoint, FixedJoint, GenericJoint, JointHandle, PrismaticJoint, RigidBodyHandle,
+};
#[derive(Copy, Clone)]
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
@@ -17,6 +19,7 @@ pub enum JointParams {
/// A revolute joint that removes all degrees of degrees of freedom between the affected
/// bodies except for the translation along one axis.
RevoluteJoint(RevoluteJoint),
+ GenericJoint(GenericJoint),
}
impl JointParams {
@@ -26,8 +29,9 @@ impl JointParams {
JointParams::BallJoint(_) => 0,
JointParams::FixedJoint(_) => 1,
JointParams::PrismaticJoint(_) => 2,
+ JointParams::GenericJoint(_) => 3,
#[cfg(feature = "dim3")]
- JointParams::RevoluteJoint(_) => 3,
+ JointParams::RevoluteJoint(_) => 4,
}
}
@@ -49,6 +53,15 @@ impl JointParams {
}
}
+ /// Gets a reference to the underlying generic joint, if `self` is one.
+ pub fn as_generic_joint(&self) -> Option<&GenericJoint> {
+ if let JointParams::GenericJoint(j) = self {
+ Some(j)
+ } else {
+ None
+ }
+ }
+
/// Gets a reference to the underlying prismatic joint, if `self` is one.
pub fn as_prismatic_joint(&self) -> Option<&PrismaticJoint> {
if let JointParams::PrismaticJoint(j) = self {
@@ -81,6 +94,12 @@ impl From<FixedJoint> for JointParams {
}
}
+impl From<GenericJoint> for JointParams {
+ fn from(j: GenericJoint) -> Self {
+ JointParams::GenericJoint(j)
+ }
+}
+
#[cfg(feature = "dim3")]
impl From<RevoluteJoint> for JointParams {
fn from(j: RevoluteJoint) -> Self {
diff --git a/src/dynamics/joint/mod.rs b/src/dynamics/joint/mod.rs
index b4dd60e..92dd715 100644
--- a/src/dynamics/joint/mod.rs
+++ b/src/dynamics/joint/mod.rs
@@ -1,5 +1,6 @@
pub use self::ball_joint::BallJoint;
pub use self::fixed_joint::FixedJoint;
+pub use self::generic_joint::GenericJoint;
pub use self::joint::{Joint, JointParams};
pub(crate) use self::joint_set::{JointGraphEdge, JointIndex};
pub use self::joint_set::{JointHandle, JointSet};
@@ -9,6 +10,7 @@ pub use self::revolute_joint::RevoluteJoint;
mod ball_joint;
mod fixed_joint;
+mod generic_joint;
mod joint;
mod joint_set;
mod prismatic_joint;