Fix joint limits not being flipped in one body constrains. (#549)
This commit is contained in:
committed by
Sébastien Crozet
parent
a2fdeab7e1
commit
4332818e02
@@ -496,6 +496,26 @@ impl GenericJoint {
|
|||||||
self.motors[i].damping = damping;
|
self.motors[i].damping = damping;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Flips the orientation of the joint, including limits and motors.
|
||||||
|
pub fn flip(&mut self) -> &mut Self {
|
||||||
|
std::mem::swap(&mut self.local_frame1, &mut self.local_frame2);
|
||||||
|
|
||||||
|
let coupled_bits = self.coupled_axes.bits();
|
||||||
|
|
||||||
|
for dim in 0..SPATIAL_DIM {
|
||||||
|
if coupled_bits & (1 << dim) == 0 {
|
||||||
|
let limit = self.limits[dim];
|
||||||
|
self.limits[dim].min = -limit.max;
|
||||||
|
self.limits[dim].max = -limit.min;
|
||||||
|
}
|
||||||
|
|
||||||
|
self.motors[dim].target_vel = -self.motors[dim].target_vel;
|
||||||
|
self.motors[dim].target_pos = -self.motors[dim].target_pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
self
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! joint_conversion_methods(
|
macro_rules! joint_conversion_methods(
|
||||||
|
|||||||
@@ -198,7 +198,7 @@ impl JointOneBodyConstraintBuilder {
|
|||||||
|
|
||||||
if flipped {
|
if flipped {
|
||||||
std::mem::swap(&mut handle1, &mut handle2);
|
std::mem::swap(&mut handle1, &mut handle2);
|
||||||
std::mem::swap(&mut joint_data.local_frame1, &mut joint_data.local_frame2);
|
joint_data.flip();
|
||||||
};
|
};
|
||||||
|
|
||||||
let rb1 = &bodies[handle1];
|
let rb1 = &bodies[handle1];
|
||||||
|
|||||||
@@ -319,7 +319,6 @@ pub struct JointGenericVelocityOneBodyExternalConstraintBuilder {
|
|||||||
joint_id: JointIndex,
|
joint_id: JointIndex,
|
||||||
joint: GenericJoint,
|
joint: GenericJoint,
|
||||||
j_id: usize,
|
j_id: usize,
|
||||||
flipped: bool,
|
|
||||||
constraint_id: usize,
|
constraint_id: usize,
|
||||||
// These are solver body for both joints, except that
|
// These are solver body for both joints, except that
|
||||||
// the world_com is actually in local-space.
|
// the world_com is actually in local-space.
|
||||||
@@ -337,21 +336,20 @@ impl JointGenericVelocityOneBodyExternalConstraintBuilder {
|
|||||||
jacobians: &mut DVector<Real>,
|
jacobians: &mut DVector<Real>,
|
||||||
out_constraint_id: &mut usize,
|
out_constraint_id: &mut usize,
|
||||||
) {
|
) {
|
||||||
|
let mut joint_data = joint.data;
|
||||||
let mut handle1 = joint.body1;
|
let mut handle1 = joint.body1;
|
||||||
let mut handle2 = joint.body2;
|
let mut handle2 = joint.body2;
|
||||||
let flipped = !bodies[handle2].is_dynamic();
|
let flipped = !bodies[handle2].is_dynamic();
|
||||||
|
|
||||||
let local_frame1 = if flipped {
|
if flipped {
|
||||||
std::mem::swap(&mut handle1, &mut handle2);
|
std::mem::swap(&mut handle1, &mut handle2);
|
||||||
joint.data.local_frame2
|
joint_data.flip();
|
||||||
} else {
|
}
|
||||||
joint.data.local_frame1
|
|
||||||
};
|
|
||||||
|
|
||||||
let rb1 = &bodies[handle1];
|
let rb1 = &bodies[handle1];
|
||||||
let rb2 = &bodies[handle2];
|
let rb2 = &bodies[handle2];
|
||||||
|
|
||||||
let frame1 = rb1.pos.position * local_frame1;
|
let frame1 = rb1.pos.position * joint_data.local_frame1;
|
||||||
|
|
||||||
let starting_j_id = *j_id;
|
let starting_j_id = *j_id;
|
||||||
|
|
||||||
@@ -394,11 +392,10 @@ impl JointGenericVelocityOneBodyExternalConstraintBuilder {
|
|||||||
body1,
|
body1,
|
||||||
link2,
|
link2,
|
||||||
joint_id,
|
joint_id,
|
||||||
joint: joint.data,
|
joint: joint_data,
|
||||||
j_id: starting_j_id,
|
j_id: starting_j_id,
|
||||||
frame1,
|
frame1,
|
||||||
local_body2,
|
local_body2,
|
||||||
flipped,
|
|
||||||
constraint_id: *out_constraint_id,
|
constraint_id: *out_constraint_id,
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -417,12 +414,7 @@ impl JointGenericVelocityOneBodyExternalConstraintBuilder {
|
|||||||
// constraints. Could we make this more incremental?
|
// constraints. Could we make this more incremental?
|
||||||
let mb2 = &multibodies[self.link2.multibody];
|
let mb2 = &multibodies[self.link2.multibody];
|
||||||
let pos2 = &mb2.link(self.link2.id).unwrap().local_to_world;
|
let pos2 = &mb2.link(self.link2.id).unwrap().local_to_world;
|
||||||
let frame2 = pos2
|
let frame2 = pos2 * self.joint.local_frame2;
|
||||||
* if self.flipped {
|
|
||||||
self.joint.local_frame1
|
|
||||||
} else {
|
|
||||||
self.joint.local_frame2
|
|
||||||
};
|
|
||||||
|
|
||||||
let joint_body2 = JointSolverBody {
|
let joint_body2 = JointSolverBody {
|
||||||
world_com: pos2 * self.local_body2.world_com, // the world_com was stored in local-space.
|
world_com: pos2 * self.local_body2.world_com, // the world_com was stored in local-space.
|
||||||
|
|||||||
Reference in New Issue
Block a user