aboutsummaryrefslogtreecommitdiff
path: root/examples3d
diff options
context:
space:
mode:
authorSébastien Crozet <developer@crozet.re>2021-04-13 14:06:04 +0200
committerGitHub <noreply@github.com>2021-04-13 14:06:04 +0200
commitaaf80bfa872c6f29b248cab8eb5658ab0d73cb4a (patch)
treecb4ea7f7867c33afc5a04603a18a34452026b2df /examples3d
parent7ae8184167ad6852341757608dadfc47b1f4179c (diff)
parenta4fe46b5c48050e9fdd2b9af362d36af6bd9b7d4 (diff)
downloadrapier-aaf80bfa872c6f29b248cab8eb5658ab0d73cb4a.tar.gz
rapier-aaf80bfa872c6f29b248cab8eb5658ab0d73cb4a.tar.bz2
rapier-aaf80bfa872c6f29b248cab8eb5658ab0d73cb4a.zip
Merge pull request #174 from dimforge/prismatic_motor
Fix torque generation for the prismatic joint motor
Diffstat (limited to 'examples3d')
-rw-r--r--examples3d/all_examples3.rs2
-rw-r--r--examples3d/debug_prismatic3.rs110
-rw-r--r--examples3d/joints3.rs4
3 files changed, 114 insertions, 2 deletions
diff --git a/examples3d/all_examples3.rs b/examples3d/all_examples3.rs
index 8122583..2611a2f 100644
--- a/examples3d/all_examples3.rs
+++ b/examples3d/all_examples3.rs
@@ -23,6 +23,7 @@ mod debug_cylinder3;
mod debug_dynamic_collider_add3;
mod debug_friction3;
mod debug_infinite_fall3;
+mod debug_prismatic3;
mod debug_rollback3;
mod debug_triangle3;
mod debug_trimesh3;
@@ -109,6 +110,7 @@ pub fn main() {
("(Debug) trimesh", debug_trimesh3::init_world),
("(Debug) cylinder", debug_cylinder3::init_world),
("(Debug) infinite fall", debug_infinite_fall3::init_world),
+ ("(Debug) prismatic", debug_prismatic3::init_world),
("(Debug) rollback", debug_rollback3::init_world),
];
diff --git a/examples3d/debug_prismatic3.rs b/examples3d/debug_prismatic3.rs
new file mode 100644
index 0000000..5ccf2eb
--- /dev/null
+++ b/examples3d/debug_prismatic3.rs
@@ -0,0 +1,110 @@
+use na::{Point3, Vector3};
+use rapier3d::dynamics::{JointSet, RigidBodyBuilder, RigidBodySet};
+use rapier3d::geometry::{ColliderBuilder, ColliderSet};
+use rapier_testbed3d::Testbed;
+
+fn prismatic_repro(
+ bodies: &mut RigidBodySet,
+ colliders: &mut ColliderSet,
+ joints: &mut JointSet,
+ box_center: Point3<f32>,
+) {
+ let box_rb = bodies.insert(
+ RigidBodyBuilder::new_dynamic()
+ .translation(box_center.x, box_center.y, box_center.z)
+ .build(),
+ );
+ colliders.insert(
+ ColliderBuilder::cuboid(1.0, 0.25, 1.0).build(),
+ box_rb,
+ bodies,
+ );
+
+ let wheel_y = -1.0;
+ let wheel_positions = vec![
+ Vector3::new(1.0, wheel_y, -1.0),
+ Vector3::new(-1.0, wheel_y, -1.0),
+ Vector3::new(1.0, wheel_y, 1.0),
+ Vector3::new(-1.0, wheel_y, 1.0),
+ ];
+
+ for pos in wheel_positions {
+ let wheel_pos_in_world = box_center + pos;
+ let wheel_rb = bodies.insert(
+ RigidBodyBuilder::new_dynamic()
+ .translation(
+ wheel_pos_in_world.x,
+ wheel_pos_in_world.y,
+ wheel_pos_in_world.z,
+ )
+ .build(),
+ );
+ colliders.insert(ColliderBuilder::ball(0.5).build(), wheel_rb, bodies);
+
+ let mut prismatic = rapier3d::dynamics::PrismaticJoint::new(
+ Point3::new(pos.x, pos.y, pos.z),
+ Vector3::y_axis(),
+ Vector3::default(),
+ Point3::new(0.0, 0.0, 0.0),
+ Vector3::y_axis(),
+ Vector3::default(),
+ );
+ prismatic.configure_motor_model(rapier3d::dynamics::SpringModel::VelocityBased);
+ let (stiffness, damping) = (0.05, 0.2);
+ prismatic.configure_motor_position(0.0, stiffness, damping);
+
+ joints.insert(bodies, box_rb, wheel_rb, prismatic);
+ }
+
+ // put a small box under one of the wheels
+ let gravel = bodies.insert(
+ RigidBodyBuilder::new_dynamic()
+ .translation(box_center.x + 1.0, box_center.y - 2.4, -1.0)
+ .build(),
+ );
+ colliders.insert(
+ ColliderBuilder::cuboid(0.5, 0.1, 0.5).build(),
+ gravel,
+ bodies,
+ );
+}
+
+pub fn init_world(testbed: &mut Testbed) {
+ /*
+ * World
+ */
+ let mut bodies = RigidBodySet::new();
+ let mut colliders = ColliderSet::new();
+ let mut joints = JointSet::new();
+
+ /*
+ * Ground
+ */
+ let ground_size = 50.0;
+ let ground_height = 0.1;
+
+ let rigid_body = RigidBodyBuilder::new_static()
+ .translation(0.0, -ground_height, 0.0)
+ .build();
+ let handle = bodies.insert(rigid_body);
+ let collider = ColliderBuilder::cuboid(ground_size, ground_height, ground_size).build();
+ colliders.insert(collider, handle, &mut bodies);
+
+ prismatic_repro(
+ &mut bodies,
+ &mut colliders,
+ &mut joints,
+ Point3::new(0.0, 5.0, 0.0),
+ );
+
+ /*
+ * Set up the testbed.
+ */
+ testbed.set_world(bodies, colliders, joints);
+ testbed.look_at(Point3::new(10.0, 10.0, 10.0), Point3::origin());
+}
+
+fn main() {
+ let testbed = Testbed::from_builders(0, vec![("Boxes", init_world)]);
+ testbed.run()
+}
diff --git a/examples3d/joints3.rs b/examples3d/joints3.rs
index 1246bc4..6ba9461 100644
--- a/examples3d/joints3.rs
+++ b/examples3d/joints3.rs
@@ -107,12 +107,12 @@ fn create_actuated_prismatic_joints(
// the limits with large forces.
prism.motor_max_impulse = 1.0;
} else if i > 1 {
- prism.configure_motor_position(2.0, 0.2, 1.0);
+ prism.configure_motor_position(2.0, 0.01, 1.0);
} else {
prism.configure_motor_velocity(1.0, 1.0);
// We set a max impulse so that the motor doesn't fight
// the limits with large forces.
- prism.motor_max_impulse = 1.0;
+ prism.motor_max_impulse = 0.7;
prism.limits_enabled = true;
prism.limits[0] = -2.0;
prism.limits[1] = 5.0;