Skip to content

Commit

Permalink
Merge pull request #571 from AnonymousAcid7787/fix-Setting-the-motor-…
Browse files Browse the repository at this point in the history
…position-of-a-Spherical-multibody-joint-is-broken

Fix #416 Update spherical joint motor position
  • Loading branch information
sebcrozet authored Jan 24, 2024
2 parents 7ba53df + 9fed726 commit 6cee6b0
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
5 changes: 5 additions & 0 deletions examples3d/all_examples3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ mod debug_chain_high_mass_ratio3;
mod debug_cube_high_mass_ratio3;
mod debug_internal_edges3;
mod debug_long_chain3;
mod debug_multibody_ang_motor_pos3;
mod joint_motor_position3;
mod keva3;
mod locked_rotations3;
Expand Down Expand Up @@ -149,6 +150,10 @@ pub fn main() {
debug_shape_modification3::init_world,
),
("(Debug) deserialize", debug_deserialize3::init_world),
(
"(Debug) multibody ang. motor pos.",
debug_multibody_ang_motor_pos3::init_world,
),
];

// Lexicographic sort, with stress tests moved at the end of the list.
Expand Down
31 changes: 31 additions & 0 deletions examples3d/debug_multibody_ang_motor_pos3.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use rapier3d::prelude::*;
use rapier_testbed3d::Testbed;

pub fn init_world(testbed: &mut Testbed) {
let mut bodies = RigidBodySet::new();
let mut colliders = ColliderSet::new();
let impulse_joints = ImpulseJointSet::new();
let mut multibody_joints = MultibodyJointSet::new();

let ground = RigidBodyBuilder::fixed().translation(vector![0.0, 0.0, 0.0]);
let body = bodies.insert(ground);
let collider = ColliderBuilder::cuboid(1.0, 1.0, 1.0);
colliders.insert_with_parent(collider, body, &mut bodies);

let rigid_body = RigidBodyBuilder::dynamic().position(Isometry::translation(0.0, 1.0, 0.0));
let body_part = bodies.insert(rigid_body);
let collider = ColliderBuilder::cuboid(1.0, 1.0, 1.0).density(1.0);
colliders.insert_with_parent(collider, body_part, &mut bodies);

let joint = SphericalJointBuilder::new()
.local_anchor1(point![0.0, 4.0, 0.0])
.local_anchor2(point![0.0, 0.0, 0.0])
.motor_position(JointAxis::AngX, 1.0, 1000.0, 200.0)
.motor_position(JointAxis::AngY, 0.0, 1000.0, 200.0)
.motor_position(JointAxis::AngZ, 0.0, 1000.0, 200.0);

multibody_joints.insert(body, body_part, joint, true);

testbed.set_world(bodies, colliders, impulse_joints, multibody_joints);
testbed.look_at(point![20.0, 0.0, 0.0], point![0.0, 0.0, 0.0]);
}
3 changes: 3 additions & 0 deletions src/dynamics/joint/multibody_joint/multibody_joint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ impl MultibodyJoint {
let angvel = Vector3::from_row_slice(&vels[curr_free_dof..curr_free_dof + 3]);
let disp = UnitQuaternion::new_eps(angvel * dt, 0.0);
self.joint_rot = disp * self.joint_rot;
self.coords[3] += angvel[0] * dt;
self.coords[4] += angvel[1] * dt;
self.coords[5] += angvel[2] * dt;
}
_ => unreachable!(),
}
Expand Down

0 comments on commit 6cee6b0

Please sign in to comment.