aboutsummaryrefslogtreecommitdiff
path: root/examples3d
diff options
context:
space:
mode:
authorSébastien Crozet <sebcrozet@dimforge.com>2023-07-10 09:14:16 +0200
committerSébastien Crozet <sebcrozet@dimforge.com>2023-12-10 12:43:13 +0100
commita05622cfe995cb681f01bc22956addf99c208cc6 (patch)
tree3dcd4ad86677d3c39faccbb4efbc211abc4b0b78 /examples3d
parent9f3b5c86421e957e94f14e23b7e9912ada88d7e2 (diff)
downloadrapier-a05622cfe995cb681f01bc22956addf99c208cc6.tar.gz
rapier-a05622cfe995cb681f01bc22956addf99c208cc6.tar.bz2
rapier-a05622cfe995cb681f01bc22956addf99c208cc6.zip
fix: avoid perpetual movement when the target ang motor position is overshot
Diffstat (limited to 'examples3d')
-rw-r--r--examples3d/all_examples3.rs2
-rw-r--r--examples3d/joint_motor_position3.rs84
2 files changed, 86 insertions, 0 deletions
diff --git a/examples3d/all_examples3.rs b/examples3d/all_examples3.rs
index e51e185..ad4d226 100644
--- a/examples3d/all_examples3.rs
+++ b/examples3d/all_examples3.rs
@@ -35,6 +35,7 @@ mod joints3;
// mod joints3;
mod character_controller3;
mod debug_internal_edges3;
+mod joint_motor_position3;
mod keva3;
mod locked_rotations3;
mod newton_cradle3;
@@ -97,6 +98,7 @@ pub fn main() {
("Domino", domino3::init_world),
("Heightfield", heightfield3::init_world),
("Impulse Joints", joints3::init_world_with_joints),
+ ("Joint Motor Position", joint_motor_position3::init_world),
("Locked rotations", locked_rotations3::init_world),
("One-way platforms", one_way_platforms3::init_world),
("Platform", platform3::init_world),
diff --git a/examples3d/joint_motor_position3.rs b/examples3d/joint_motor_position3.rs
new file mode 100644
index 0000000..d149d82
--- /dev/null
+++ b/examples3d/joint_motor_position3.rs
@@ -0,0 +1,84 @@
+use rapier3d::prelude::*;
+use rapier_testbed3d::Testbed;
+
+pub fn init_world(testbed: &mut Testbed) {
+ /*
+ * World
+ */
+ let mut bodies = RigidBodySet::new();
+ let mut colliders = ColliderSet::new();
+ let mut impulse_joints = ImpulseJointSet::new();
+ let multibody_joints = MultibodyJointSet::new();
+
+ /*
+ * The ground
+ */
+ let ground_size = 5.0;
+ let ground_height = 0.1;
+
+ let rigid_body = RigidBodyBuilder::fixed().translation(vector![0.0, -ground_height, 0.0]);
+ let ground_handle = bodies.insert(rigid_body);
+ let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size);
+ colliders.insert_with_parent(collider, ground_handle, &mut bodies);
+
+ /*
+ * A rectangle on a motor with target position.
+ */
+ for num in 0..9 {
+ let x_pos = -6.0 + 1.5 * num as f32;
+ let rigid_body = RigidBodyBuilder::dynamic()
+ .translation(vector![x_pos, 2.0, 0.0])
+ .can_sleep(false);
+ let handle = bodies.insert(rigid_body);
+ let collider = ColliderBuilder::cuboid(0.1, 0.5, 0.1);
+ colliders.insert_with_parent(collider, handle, &mut bodies);
+
+ let joint = RevoluteJointBuilder::new(Vector::z_axis())
+ .local_anchor1(point![x_pos, 1.5, 0.0])
+ .local_anchor2(point![0.0, -0.5, 0.0])
+ .motor_position(
+ -(std::f32::consts::PI - std::f32::consts::PI / 4.0 * num as f32),
+ 1000.0,
+ 150.0,
+ );
+ impulse_joints.insert(ground_handle, handle, joint, true);
+ }
+
+ /*
+ * A rectangle on a motor with limits.
+ */
+ for num in 0..9 {
+ let x_pos = -6.0 + 1.5 * num as f32;
+ let rigid_body = RigidBodyBuilder::dynamic()
+ .translation(vector![x_pos, 5.0, 0.0])
+ .rotation(vector![0.0, 0.0, std::f32::consts::PI])
+ .can_sleep(false);
+ let handle = bodies.insert(rigid_body);
+ let collider = ColliderBuilder::cuboid(0.1, 0.5, 0.1);
+ colliders.insert_with_parent(collider, handle, &mut bodies);
+
+ let joint = RevoluteJointBuilder::new(Vector::z_axis())
+ .local_anchor1(point![x_pos, 5.0, 0.0])
+ .local_anchor2(point![0.0, -0.5, 0.0])
+ .motor_velocity(1.5, 30.0)
+ .motor_max_force(100.0)
+ .limits([
+ -std::f32::consts::PI,
+ std::f32::consts::PI / 4.0 * num as f32,
+ ]);
+ impulse_joints.insert(ground_handle, handle, joint, true);
+ }
+
+ /*
+ * Set up the testbed.
+ */
+ testbed.set_world_with_params(
+ bodies,
+ colliders,
+ impulse_joints,
+ multibody_joints,
+ vector![0.0, 0.0, 0.0],
+ (),
+ );
+ testbed.look_at(point![15.0, 5.0, 42.0], point![13.0, 1.0, 1.0]);
+}