Add motors to prismatic joints.
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
use crate::dynamics::SpringModel;
|
||||
use crate::math::{Isometry, Point, Real, Vector, DIM};
|
||||
use crate::utils::WBasis;
|
||||
use na::Unit;
|
||||
@@ -36,10 +37,23 @@ pub struct PrismaticJoint {
|
||||
///
|
||||
/// The impulse applied to the second body is given by `-impulse`.
|
||||
pub limits_impulse: Real,
|
||||
// pub motor_enabled: bool,
|
||||
// pub target_motor_vel: Real,
|
||||
// pub max_motor_impulse: Real,
|
||||
// pub motor_impulse: Real,
|
||||
|
||||
/// The target relative angular velocity the motor will attempt to reach.
|
||||
pub motor_target_vel: Real,
|
||||
/// The target relative angle along the joint axis the motor will attempt to reach.
|
||||
pub motor_target_pos: Real,
|
||||
/// The motor's stiffness.
|
||||
/// See the documentation of `SpringModel` for more information on this parameter.
|
||||
pub motor_stiffness: Real,
|
||||
/// The motor's damping.
|
||||
/// See the documentation of `SpringModel` for more information on this parameter.
|
||||
pub motor_damping: Real,
|
||||
/// The maximal impulse the motor is able to deliver.
|
||||
pub motor_max_impulse: Real,
|
||||
/// The angular impulse applied by the motor.
|
||||
pub motor_impulse: Real,
|
||||
/// The spring-like model used by the motor to reach the target velocity and .
|
||||
pub motor_model: SpringModel,
|
||||
}
|
||||
|
||||
impl PrismaticJoint {
|
||||
@@ -63,10 +77,13 @@ impl PrismaticJoint {
|
||||
limits_enabled: false,
|
||||
limits: [-Real::MAX, Real::MAX],
|
||||
limits_impulse: 0.0,
|
||||
// motor_enabled: false,
|
||||
// target_motor_vel: 0.0,
|
||||
// max_motor_impulse: Real::MAX,
|
||||
// motor_impulse: 0.0,
|
||||
motor_target_vel: 0.0,
|
||||
motor_target_pos: 0.0,
|
||||
motor_stiffness: 0.0,
|
||||
motor_damping: 0.0,
|
||||
motor_max_impulse: Real::MAX,
|
||||
motor_impulse: 0.0,
|
||||
motor_model: SpringModel::VelocityBased,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -118,10 +135,13 @@ impl PrismaticJoint {
|
||||
limits_enabled: false,
|
||||
limits: [-Real::MAX, Real::MAX],
|
||||
limits_impulse: 0.0,
|
||||
// motor_enabled: false,
|
||||
// target_motor_vel: 0.0,
|
||||
// max_motor_impulse: Real::MAX,
|
||||
// motor_impulse: 0.0,
|
||||
motor_target_vel: 0.0,
|
||||
motor_target_pos: 0.0,
|
||||
motor_stiffness: 0.0,
|
||||
motor_damping: 0.0,
|
||||
motor_max_impulse: Real::MAX,
|
||||
motor_impulse: 0.0,
|
||||
motor_model: SpringModel::VelocityBased,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -137,7 +157,8 @@ impl PrismaticJoint {
|
||||
|
||||
/// Can a SIMD constraint be used for resolving this joint?
|
||||
pub fn supports_simd_constraints(&self) -> bool {
|
||||
true
|
||||
// SIMD revolute constraints don't support motors right now.
|
||||
self.motor_max_impulse == 0.0 || (self.motor_stiffness == 0.0 && self.motor_damping == 0.0)
|
||||
}
|
||||
|
||||
// FIXME: precompute this?
|
||||
@@ -195,4 +216,29 @@ impl PrismaticJoint {
|
||||
let translation = self.local_anchor2.coords.into();
|
||||
Isometry::from_parts(translation, rotation)
|
||||
}
|
||||
|
||||
pub fn configure_motor_model(&mut self, model: SpringModel) {
|
||||
self.motor_model = model;
|
||||
}
|
||||
|
||||
pub fn configure_motor_velocity(&mut self, target_vel: Real, factor: Real) {
|
||||
self.configure_motor(self.motor_target_pos, target_vel, 0.0, factor)
|
||||
}
|
||||
|
||||
pub fn configure_motor_position(&mut self, target_pos: Real, stiffness: Real, damping: Real) {
|
||||
self.configure_motor(target_pos, 0.0, stiffness, damping)
|
||||
}
|
||||
|
||||
pub fn configure_motor(
|
||||
&mut self,
|
||||
target_pos: Real,
|
||||
target_vel: Real,
|
||||
stiffness: Real,
|
||||
damping: Real,
|
||||
) {
|
||||
self.motor_target_vel = target_vel;
|
||||
self.motor_target_pos = target_pos;
|
||||
self.motor_stiffness = stiffness;
|
||||
self.motor_damping = damping;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user