I am creating a simulation of a roller conveyor system in Rapier js (vanilla js, with Three.js).
in order to simulate the rollers, I have created many cylinder-shaped objects rotated on their side:
roller = {
visible:roller_sequence.visible,
enable:"enable",
speed:"speed",
acceleration:"accel",
speed_feedback:0,
current_speed:"p "+position_number+" current speed",
position_number:position_number,
length:roller_sequence.length,
radius:0.025,
local_position: new THREE.Vector3(position.x, position.y, position.z),
local_rotation: new THREE.Quaternion(rotation.x, rotation.y, rotation.z, rotation.w),
position: new THREE.Vector3(absolute.position.x, absolute.position.y, absolute.position.z),
rotation: new THREE.Quaternion(absolute.rotation.x, absolute.rotation.y, absolute.rotation.z, absolute.rotation.w),
parent:roller_sequence.parent
}
let rigidBodyDesc = RAPIER.RigidBodyDesc.kinematicPositionBased()
.setTranslation(roller.position.x, roller.position.y, roller.position.z)
.setRotation(new emulation.physics.Rapier.Quaternion(roller.rotation.x, roller.rotation.y, roller.rotation.z, roller.rotation.w))
let rigid_body = world.createRigidBody(rigidBodyDesc);
let colliderDesc = RAPIER.ColliderDesc.cylinder((roller.length*0.42)/2, roller.radius)
.setFriction(2)
.setRestitution(0)
let collider = world.createCollider(colliderDesc, rigid_body);
roller.rigid_body = rigid_body
roller.collider = collider;
roller.kinematic = true;
rollers.push(roller)
I am also creating some boxes that are rounded cuboid shapes:
const quat = new THREE.Quaternion();
quat.setFromAxisAngle(new THREE.Vector3(0,1,0),(load.angle+90)*(Math.PI/180));
let rigidBodyDesc = RAPIER.RigidBodyDesc.dynamic()
.setTranslation(load_position.x, load_position.y, load_position.z)
.setRotation(new RAPIER.Quaternion(quat.x, quat.y, quat.z, quat.w))
//.setAngularDamping(1)
//.setLinearDamping(1)
let rigidBody = world.createRigidBody(rigidBodyDesc);
let colliderDesc = RAPIER.ColliderDesc.roundCuboid((load_size.x/2)-0.02, (load_size.y/2)-0.02, (load_size.z/2)-0.02, 0.02)
.setMass(1)
//.setRestitution(0)
//.setFriction(1)
let tote_collider = world.createCollider(colliderDesc, rigidBody);
load.userData.collider = tote_collider;
load.userData.dynamic = true;
load.quaternion.copy(tote_collider.rotation())
during the simulation, I am rotating the rollers along their axis like this:
roller.rigid_body.setNextKinematicRotation(new RAPIER.Quaternion(roller.rotation.x, roller.rotation.y, roller.rotation.z, roller.rotation.w))
So, my problem is this:
- if I don't call any code in my update function except for stepping the simulation, the rollers will throw the box violently off of themselves.
- if I call the 'setNextKinematicRotation' on every roller with a new value, the box will begin to move forward, then stop or move backwards or jitter. This isn't consistent though, sometimes it will move along its merry way.
- if I call 'setNextKinematicRotation' on every roller with the same value over and over again, the box will remain perfectly motionless, like it is supposed to.
- if I don't try to scale the speed with the framerate, the jittering seems to go away, but throwing off of the boxes while stopped continues to happen.
I do not understand where the force to throw the box could be coming from if all the rollers are still. and I don't understand why the box seems to fight itself when all the rollers are moving at the same speed.