aboutsummaryrefslogtreecommitdiff
path: root/src/dynamics/joint/revolute_joint.rs
diff options
context:
space:
mode:
authorSébastien Crozet <developer@crozet.re>2022-02-20 12:55:00 +0100
committerSébastien Crozet <sebastien@crozet.re>2022-03-20 21:49:16 +0100
commitfb20d72ee29de9311a81aec6eb9f02fd2aa35fc4 (patch)
tree45827ac4c754c3670d1ddb2f91fc498515d6b3b8 /src/dynamics/joint/revolute_joint.rs
parente740493b980dc9856864ead3206a4fa02aff965f (diff)
downloadrapier-fb20d72ee29de9311a81aec6eb9f02fd2aa35fc4.tar.gz
rapier-fb20d72ee29de9311a81aec6eb9f02fd2aa35fc4.tar.bz2
rapier-fb20d72ee29de9311a81aec6eb9f02fd2aa35fc4.zip
Joint API and joint motors improvements
Diffstat (limited to 'src/dynamics/joint/revolute_joint.rs')
-rw-r--r--src/dynamics/joint/revolute_joint.rs171
1 files changed, 134 insertions, 37 deletions
diff --git a/src/dynamics/joint/revolute_joint.rs b/src/dynamics/joint/revolute_joint.rs
index 9084c4d..a9d74f5 100644
--- a/src/dynamics/joint/revolute_joint.rs
+++ b/src/dynamics/joint/revolute_joint.rs
@@ -1,5 +1,5 @@
-use crate::dynamics::joint::{JointAxesMask, JointData};
-use crate::dynamics::{JointAxis, MotorModel};
+use crate::dynamics::joint::{GenericJoint, GenericJointBuilder, JointAxesMask};
+use crate::dynamics::{JointAxis, JointLimits, JointMotor, MotorModel};
use crate::math::{Point, Real};
#[cfg(feature = "dim3")]
@@ -7,100 +7,197 @@ use crate::math::UnitVector;
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
#[derive(Copy, Clone, Debug, PartialEq)]
+#[repr(transparent)]
pub struct RevoluteJoint {
- data: JointData,
+ data: GenericJoint,
}
impl RevoluteJoint {
#[cfg(feature = "dim2")]
pub fn new() -> Self {
- let mask = JointAxesMask::X | JointAxesMask::Y;
-
- let data = JointData::default().lock_axes(mask);
- Self { data }
+ let data = GenericJointBuilder::new(JointAxesMask::LOCKED_REVOLUTE_AXES);
+ Self { data: data.build() }
}
#[cfg(feature = "dim3")]
pub fn new(axis: UnitVector<Real>) -> Self {
- let mask = JointAxesMask::X
- | JointAxesMask::Y
- | JointAxesMask::Z
- | JointAxesMask::ANG_Y
- | JointAxesMask::ANG_Z;
-
- let data = JointData::default()
- .lock_axes(mask)
+ let data = GenericJointBuilder::new(JointAxesMask::LOCKED_REVOLUTE_AXES)
.local_axis1(axis)
- .local_axis2(axis);
+ .local_axis2(axis)
+ .build();
Self { data }
}
- pub fn data(&self) -> &JointData {
+ pub fn data(&self) -> &GenericJoint {
&self.data
}
#[must_use]
+ pub fn local_anchor1(&self) -> Point<Real> {
+ self.data.local_anchor1()
+ }
+
+ pub fn set_local_anchor1(&mut self, anchor1: Point<Real>) -> &mut Self {
+ self.data.set_local_anchor1(anchor1);
+ self
+ }
+
+ #[must_use]
+ pub fn local_anchor2(&self) -> Point<Real> {
+ self.data.local_anchor2()
+ }
+
+ pub fn set_local_anchor2(&mut self, anchor2: Point<Real>) -> &mut Self {
+ self.data.set_local_anchor2(anchor2);
+ self
+ }
+
+ #[must_use]
+ pub fn motor(&self) -> Option<&JointMotor> {
+ self.data.motor(JointAxis::AngX)
+ }
+
+ /// Set the spring-like model used by the motor to reach the desired target velocity and position.
+ pub fn set_motor_model(&mut self, model: MotorModel) -> &mut Self {
+ self.data.set_motor_model(JointAxis::AngX, model);
+ self
+ }
+
+ /// Sets the target velocity this motor needs to reach.
+ pub fn set_motor_velocity(&mut self, target_vel: Real, factor: Real) -> &mut Self {
+ self.data
+ .set_motor_velocity(JointAxis::AngX, target_vel, factor);
+ self
+ }
+
+ /// Sets the target angle this motor needs to reach.
+ pub fn set_motor_position(
+ &mut self,
+ target_pos: Real,
+ stiffness: Real,
+ damping: Real,
+ ) -> &mut Self {
+ self.data
+ .set_motor_position(JointAxis::AngX, target_pos, stiffness, damping);
+ self
+ }
+
+ /// Configure both the target angle and target velocity of the motor.
+ pub fn set_motor(
+ &mut self,
+ target_pos: Real,
+ target_vel: Real,
+ stiffness: Real,
+ damping: Real,
+ ) -> &mut Self {
+ self.data
+ .set_motor(JointAxis::AngX, target_pos, target_vel, stiffness, damping);
+ self
+ }
+
+ pub fn set_motor_max_force(&mut self, max_force: Real) -> &mut Self {
+ self.data.set_motor_max_force(JointAxis::AngX, max_force);
+ self
+ }
+
+ #[must_use]
+ pub fn limits(&self) -> Option<&JointLimits<Real>> {
+ self.data.limits(JointAxis::AngX)
+ }
+
+ pub fn set_limits(&mut self, limits: [Real; 2]) -> &mut Self {
+ self.data.set_limits(JointAxis::AngX, limits);
+ self
+ }
+}
+
+impl Into<GenericJoint> for RevoluteJoint {
+ fn into(self) -> GenericJoint {
+ self.data
+ }
+}
+
+#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
+#[derive(Copy, Clone, Debug, PartialEq)]
+pub struct RevoluteJointBuilder(RevoluteJoint);
+
+impl RevoluteJointBuilder {
+ #[cfg(feature = "dim2")]
+ pub fn new() -> Self {
+ Self(RevoluteJoint::new())
+ }
+
+ #[cfg(feature = "dim3")]
+ pub fn new(axis: UnitVector<Real>) -> Self {
+ Self(RevoluteJoint::new(axis))
+ }
+
+ #[must_use]
pub fn local_anchor1(mut self, anchor1: Point<Real>) -> Self {
- self.data = self.data.local_anchor1(anchor1);
+ self.0.set_local_anchor1(anchor1);
self
}
#[must_use]
pub fn local_anchor2(mut self, anchor2: Point<Real>) -> Self {
- self.data = self.data.local_anchor2(anchor2);
+ self.0.set_local_anchor2(anchor2);
self
}
/// Set the spring-like model used by the motor to reach the desired target velocity and position.
+ #[must_use]
pub fn motor_model(mut self, model: MotorModel) -> Self {
- self.data = self.data.motor_model(JointAxis::AngX, model);
+ self.0.set_motor_model(model);
self
}
/// Sets the target velocity this motor needs to reach.
+ #[must_use]
pub fn motor_velocity(mut self, target_vel: Real, factor: Real) -> Self {
- self.data = self
- .data
- .motor_velocity(JointAxis::AngX, target_vel, factor);
+ self.0.set_motor_velocity(target_vel, factor);
self
}
/// Sets the target angle this motor needs to reach.
+ #[must_use]
pub fn motor_position(mut self, target_pos: Real, stiffness: Real, damping: Real) -> Self {
- self.data = self
- .data
- .motor_position(JointAxis::AngX, target_pos, stiffness, damping);
+ self.0.set_motor_position(target_pos, stiffness, damping);
self
}
/// Configure both the target angle and target velocity of the motor.
- pub fn motor_axis(
+ #[must_use]
+ pub fn motor(
mut self,
target_pos: Real,
target_vel: Real,
stiffness: Real,
damping: Real,
) -> Self {
- self.data =
- self.data
- .motor_axis(JointAxis::AngX, target_pos, target_vel, stiffness, damping);
+ self.0.set_motor(target_pos, target_vel, stiffness, damping);
self
}
- pub fn motor_max_impulse(mut self, max_impulse: Real) -> Self {
- self.data = self.data.motor_max_impulse(JointAxis::AngX, max_impulse);
+ #[must_use]
+ pub fn motor_max_force(mut self, max_force: Real) -> Self {
+ self.0.set_motor_max_force(max_force);
self
}
#[must_use]
- pub fn limit_axis(mut self, limits: [Real; 2]) -> Self {
- self.data = self.data.limit_axis(JointAxis::AngX, limits);
+ pub fn limits(mut self, limits: [Real; 2]) -> Self {
+ self.0.set_limits(limits);
self
}
+
+ #[must_use]
+ pub fn build(self) -> RevoluteJoint {
+ self.0
+ }
}
-impl Into<JointData> for RevoluteJoint {
- fn into(self) -> JointData {
- self.data
+impl Into<GenericJoint> for RevoluteJointBuilder {
+ fn into(self) -> GenericJoint {
+ self.0.into()
}
}